8 years, 2 months ago.

How can I force disconnection from nrf51822 with BLE API?

I want to disconnect peripheral device once the data is sent by it. how can I do that? I did not find API. I want that peripheral disconnects or disconnects forcefully. after the required data is sent.

ok I found out how to do this. But I am not sure if this is the right way to do this???

disconnect on unknown mac-id

void connectionCallBack(const Gap::ConnectionCallbackParams_t* params)
{
  Serial.print("  The peerAddr : ");
    for(uint8_t index=0; index<6; index++)
    {
       Serial.print(params->peerAddr[index], HEX);
       Serial.print(" ");  
    }
 //check the mac id what every you saved or know you want to only connect to.
    if( !(params->peerAddr[0]!=0xf9  || params->peerAddr[0]!=0xf9 || params->peerAddr[0]!=0xf9 params->peerAddr[0]!=0xf9  || params->peerAddr[0]!=0xf9 || params->peerAddr[0]!=0xf9))
      {
        //this is not the allowed Device. disconnect.
        Serial.println("not the device we want");
        Gap::DisconnectionReason_t res=Gap::LOCAL_HOST_TERMINATED_CONNECTION;
        ble.disconnect(params->handle,res );
      }
}
posted by Shirish Jadav 22 Sep 2016

1 Answer

8 years, 2 months ago.

Hello Shirish,

You have answered your own question. It is the correct way to do it.