Nrf ble disconnect for sometime after event occur


#1

Hello Everyone,

I am trying to disconnect the nrf51822 ble(peripheral) from the App(central) for some seconds say 5-7 seconds after event occurs like this:
advertise -> connect -> receive (say 1 byte) -> disconnect and then back to advertise after 5-7 seconds.

I found the function called ble.disconnect() but not able to use it properly on user level.
Am I using the correct function or I need to use the different function?
please guide me.


#2

This is a little tricky at the moment. The issue is, when you disconnect, you go into the advertising state and then the gateway could immediately reconnect. Also, the disconnect command doesn’t disconnect immediately, it may have a bit of a delay as it is a graceful disconnect.

The solution is to have a helper function. Basically, it should look something like this:

BLE.disconnect();
while (BLE.getState() != BLE_ADVERTISING) { }
BLE.stopAdvertising();

This will disconnect and then wait for advertising to start, and then stop it.

We do have an issue at the moment to make his better in a future release: https://github.com/bluzDK/bluzDK-firmware/issues/33