h2zero / NimBLE-Arduino

A fork of the NimBLE library structured for compilation with Arduino, for use with ESP32, nRF5x.
https://h2zero.github.io/NimBLE-Arduino/
Apache License 2.0
672 stars 138 forks source link

PIN code on connection #546

Closed marco95thb closed 1 month ago

marco95thb commented 1 year ago

Hi, I added the PIN protection to a single characteristic thanks to the issue https://github.com/h2zero/NimBLE-Arduino/issues/158 but I want to protect with PIN the entire connection. Now I'm connecting with BLE scanner, and when I try to read the app is asking me for the password. What I want to achieve is that the APP asks me for password when I try to connect. How can I implement the PIN code onConnection and not on characteristic reading?

Thanks, Marco

sanastasiou commented 1 year ago

You can't. This is just how BLE works. A non encrypted characteristic will not request pin. Only way to pair/bond is to request to read/write an encrypted characteristic.

I think what you really want is not that, rather whitelisting. But I have found that certain devices are ridiculously buggy with regards to that.

h2zero commented 1 month ago

This can be done by calling NimBLEDevice::startSecurity in the onConnect callback.