Non-blocking onConfirmPIN
In the original Bluedroid implementation onConfirmPIN was a blocking function. I bypassed the issue by creating some custom code which would call esp_ble_confirm_reply(bleBondReqAddr, false) when the user pressed a button which confirms the pin was correct. As the device was waiting for user input it could continue running other functions. I also had a timeout to automatically confirm false after 10 seconds (I think the ble stack enforces 30 seconds, but I set my own shorter timeout).
The problem with NimBLE is that onConfirmPIN is included in the NimBLEServerCallbacks so I can't bypass the call anymore.
Is is possible to create a way to asynchronously confirm the pin request? This would be much more useful than the current method. I have my own class that wraps BLE functionality i.e. MyBleClass : public NimBLEServerCallbacks { ... } so ideally the added functions would be located in NimBLEServerCallbacks for ease of use.
Thanks 👍
Sounds like a good suggestion. It could be implemented by adding a function to the server that can inject the response at a later time instead of waiting for the callback to return. I'm too busy at this time to work on it, I'd happily accept a PR for this if you're interested.
30 seconds is from bluetooth specification.
Yes, it is possible to do it. onConfirm callback can be overloaded that will just inform user there is request. Then like @h2zero said, additional function to which you can pass a pin.
Quite busy myself too so but I will see if I can make some time to work on something.. Any hints for me? I see usages of ble_sm_inject_io in NimBLEServer - is that what I should be calling?
ble_sm_inject_io is what you would need to use.
I think the event handler would need to be changed so if the callback returns an invalid pin (such as 0xFFFFFFFF) it will not inject the pin response at that time and instead we could have a function to perform the proper pin response after.