Android Question How to stop BlePeripheral

leongcc

Member
Licensed User
Longtime User
B4X:
Private peripheral As BlePeripheral2
...
peripheral.Start("10% off")
...
peripheral.Start("20% off")
...

In the codes, the advertisement was changed by calling peripheral.Start() again. Using a BLE scanner, both BLE peripherals are detected. Is there a way to 'kill off' the 1st instance of the peripheral ?

I explain in details:
I am writing an app running in Nexus5X (Android 8) and the phone is behaving like a BLE peripheral. An independent BLE central is continuously scanning for peripherals. Each time peripheral.Start() is executed, the scanner detects a new peripheral. In the codes example above, the scanner shows the existence of 2 peripherals. Other scanners also show the same.
peripheral.Start() is implemented in Service, but stopping service doesn't not change anything. When the app closes, the scanner shows 0 peripheral.
 
Last edited:

leongcc

Member
Licensed User
Longtime User
Thanks but the Close method has no effect.
I am re-using BlePeripheral.b4a for my testing and I added a UI button that executes peripheral.Close when the button is pressed. I also added another button that executes peripheral.Start(advertisement).
The scanners (Gatt Client) still see the advertisement after peripheral.Close.
If peripheral.Start(advertisement) is executed twice, the scanners see 2 instances of the peripherals. Scanners detected 2 peripherals with same advertisement.
As always, the advertisement disappears only after I close the app.
 
Last edited:
Upvote 0

leongcc

Member
Licensed User
Longtime User
Yes, your codes work. Thanks.
Currently, each peripheral.Start(advertisement) must be aborted by a peripheral.Close before the next peripheral.Start(advertisement). For example,


B4X:
'---- This is OK:
peripheral.Start("10% off")
...
peripheral.Close
peripheral.Start("20% off")
...
peripheral.Close

'----This is not OK:
peripheral.Start("10% off")
...
peripheral.Start("20% off")
...
peripheral.Close
peripheral.Close
'Scanner shows 1 peripheral (the 2nd one) and it cannot be closed unless the app closes


 
Upvote 0
Top