BLE config le_secure or bond - unknown config param

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
mibra
Posts: 3
Joined: Sun Jan 03, 2021 12:43 pm

BLE config le_secure or bond - unknown config param

Post by mibra » Sun Jan 03, 2021 1:19 pm

Hi,

I am trying to setup a Bluetooth mouse for chin control for my handicapped dad.

Basically everything works great, re-used your examples. Thank you for them!

I only have one problem. Once the mouse is successfully paired and I reboot the ESP32, it does reconnect, but disconnect immediately. Via btmon on the RaspBerry I found following issues during reconnecting:

Code: Select all

> HCI Event: Encryption Change (0x08) plen 4                          #439 [hci0] 513.583695
        Status: PIN or Key Missing (0x06)
        Handle: 64
        Encryption: Disabled (0x00)
< HCI Command: Disconnect (0x01|0x0006) plen 3                        #440 [hci0] 513.583765
        Handle: 64
        Reason: Authentication Failure (0x05)
> HCI Event: Command Status (0x0f) plen 4                             #441 [hci0] 513.584229
      Disconnect (0x01|0x0006) ncmd 1
        Status: Success (0x00)
> HCI Event: Disconnect Complete (0x05) plen 4                        #442 [hci0] 513.632950
        Status: Success (0x00)
        Handle: 64
        Reason: Connection Terminated By Local Host (0x16)
I suppose that I have to implement le_secure to save the keys and load them after reboot. However when I use bond or le_secure I get an error for "unknown config param".

Code: Select all

print('- enabling BLE security')
try:                                                                                                                                                                                        
    ble.config(le_secure=True)
except Exception as e:
    print('*** could not enable security')
    print('*** Error:', str(e))
print('- enabling BLE bonding')
try:
    ble.config(bond=True)
except Exception as e:
    print('*** could not enable bonding')
    print('*** Error:', str(e))
I tried idf 3 and idf 4, version 1.13 and the unstable version. I tried importing bluetooth and ubluetooth. Same results.

I would appreciate any hint you can give me.

Maybe this is unavailable on the ESP32 and I need to switch to the pyboard?

Regards
Michael

mibra
Posts: 3
Joined: Sun Jan 03, 2021 12:43 pm

Re: BLE config le_secure or bond - unknown config param

Post by mibra » Tue Jan 05, 2021 9:22 pm

To add to my previous post.

If I pair the device, then it will not reconnect when rebooting either controller or peripheral.

On Linux 5.4 it never works. When I updated to 5.10 on the Raspberry and I do not pair via GUI, but only trust and connect via bluetoothctl everything works perfectly fine. After any reboot of any device, they reconnect perfectly, which is what I needed.

I just yet don't understand why bond and le_secure are listed in the documentation, but are unavailable when trying to use them in practice.

Appreciate any input.

Michael

User avatar
jimmo
Posts: 2059
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: BLE config le_secure or bond - unknown config param

Post by jimmo » Mon Jan 11, 2021 12:41 am

mibra wrote:
Tue Jan 05, 2021 9:22 pm
I just yet don't understand why bond and le_secure are listed in the documentation, but are unavailable when trying to use them in practice.
Unfortunately the pairing/bonding support is only available on STM32 & Unix. The documentation does say this, but I would also like to make it possible for the documentation to be much more port-aware (and only show functionality that is available on your selected port).

I hope to support ESP32 eventually, but the way things work on ESP32 make it a bit harder to integrate with Espressif's APIs from MicroPython.

I'm glad you got it working on the Raspberry Pi -- I would have thought that pairing and bonding would only be required for a device that uses RPA addressing, but perhaps something is also forcing it to require encrypted/authenticated (which TBH does seem like a sensible idea for a HID device).

mibra
Posts: 3
Joined: Sun Jan 03, 2021 12:43 pm

Re: BLE config le_secure or bond - unknown config param

Post by mibra » Mon Jan 11, 2021 7:44 pm

Thank you. I found the note in the documentation now. I should have looked further down instead of only looking at the available parameters.

5.10 allows for non pairing and only use trust and connect, but that is also only possible on the CLI, not in the GUI or applet. 5.4 seems always to force this, which would makes sense per what you say.

Thanks again for answering my question and thank you for a great product.

With what you made available I was able to create a "mouth mouse" for my dad, which suffers tetraplegia. He is now able to control a card game on the Pi and more with his lips and tongue. Clicking is possible with a water flow sensor, which measures puffing.

Without MP and all of your efforts this it would have been much more difficult for me if not impossible.

BIG thank you to all of you!

User avatar
jimmo
Posts: 2059
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: BLE config le_secure or bond - unknown config param

Post by jimmo » Mon Jan 11, 2021 11:52 pm

mibra wrote:
Mon Jan 11, 2021 7:44 pm
With what you made available I was able to create a "mouth mouse" for my dad, which suffers tetraplegia. He is now able to control a card game on the Pi and more with his lips and tongue. Clicking is possible with a water flow sensor, which measures puffing.

Without MP and all of your efforts this it would have been much more difficult for me if not impossible.

BIG thank you to all of you!
That's absolutely wonderful!! So glad it's working, and thank you for telling us about your project. :)

We will keep improving the BLE support, sorry it's been slow progress. Once we can get ESP32 updated to support synchronous events (and then add pairing/bonding support), we'll be able to simplify the documentation. The other big thing in the pipeline is asyncio support for BLE which will dramatically simplify writing BLE code in MicroPython...

Post Reply