Page 1 of 1

NimBLE how to only allow previously bonded central to connect?

Posted: Thu Aug 25, 2022 4:02 pm
by steaky1212
I'm working on a BLE peripheral using the NimBLE stack, and a key requirement is that it must only allow a single central device which has previously bonded with it to connect (until a button is pressed, clearing the stored bond and allowing a different central to bond). But figuring out how to implement this using the NimBLE library is proving very difficult.

I can either do this by doing directed advertising to the central that has bonded, or by terminating any connections (in the BLE_GAP_EVENT_CONNECT event) if there is no stored bond for the central that has just connected.

It also needs to work with private random addresses (as the phone randomises its own address and I will be using LE Privacy on the peripheral). This is the main problem I’m struggling to solve. How do I read the correctly resolved address from the stored bonds so I can do directed advertising to it, and how do I see if a stored bond exists for an existing connection?

Can this be done with the NimBLE stack and if so, how would I do it?

Thanks

Re: NimBLE how to only allow previously bonded central to connect?

Posted: Fri Aug 26, 2022 12:39 am
by Alberk
Hi,

I am thinking out aloud. If there is there is no bonding on the ESP32 then allow any device to bond. Once there is an established bond then no bonding to the ESP32 is allowed/rejected. In this instance only the first bonded Phone/Device would be able to establish connection.

Re: NimBLE how to only allow previously bonded central to connect?

Posted: Thu Oct 26, 2023 12:40 pm
by bakadave
Did you manage to do tihs?