Page 1 of 1

BLE config le_secure or bond - unknown config param

Posted: Sun Jan 03, 2021 1:19 pm
by mibra
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

Re: BLE config le_secure or bond - unknown config param

Posted: Tue Jan 05, 2021 9:22 pm
by mibra
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

Re: BLE config le_secure or bond - unknown config param

Posted: Mon Jan 11, 2021 12:41 am
by jimmo
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).

Re: BLE config le_secure or bond - unknown config param

Posted: Mon Jan 11, 2021 7:44 pm
by mibra
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!

Re: BLE config le_secure or bond - unknown config param

Posted: Mon Jan 11, 2021 11:52 pm
by jimmo
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...

Re: BLE config le_secure or bond - unknown config param

Posted: Wed Feb 03, 2021 1:14 pm
by mibra
That is great news.

Is there any way how I can follow the development? Can I subscribe to notifications?

Re: BLE config le_secure or bond - unknown config param

Posted: Thu Feb 04, 2021 5:54 am
by jimmo
mibra wrote:
Wed Feb 03, 2021 1:14 pm
Is there any way how I can follow the development? Can I subscribe to notifications?
Unfortunately the only way I know of is to subscribe to the github project (github.com/micropython/micropython) and you'll see the PRs and Issues by email.

Otherwise sign up for the MicroPython newsletter and check the release notes. We're planning to do much more frequent releases going forward (i.e. every ~2-3 months).

Re: BLE config le_secure or bond - unknown config param

Posted: Sun Aug 22, 2021 10:29 am
by maxkes
Hi,

I tried BLE with bonding on ESP32 and ran in this problem... my question is:

jimmo wrote
Unfortunately the pairing/bonding support is only available on STM32 & Unix
On which SMT32 I can run micropython with Bluetooth? Or do I need to connect an external Bluetooth-Chip via UART or similar?

Re: BLE config le_secure or bond - unknown config param

Posted: Tue May 23, 2023 6:21 am
by MasterOfGizmo
The changelog from Wed, 26 Apr 2023 for version v1.20.0 includes the line:

Code: Select all

mpconfigport: enable BLE synchronous events and pairing/bonding
Does that mean that bonding is now supposed to work on esp32?