Skip to content

esp32: enable BLE synchronous events and BLE pairing/boindng #7046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2022

Conversation

dpgeorge
Copy link
Member

This is currently WIP, but all multitests pass (including GAP pairing/bonding) on esp32 with IDF v4.2.

@EddieParis
Copy link
Contributor

EddieParis commented Mar 22, 2021

I just gave a try to your branch, I successfully paired the ble_bonding_peripheral.py example with my iPhone.
Thanks a lot, this arrives right on time, I just began to work again on an old project where this was needed.
Note I also used esp-idf 4.2

@EddieParis
Copy link
Contributor

Sorry to add on your plate, I just noticed that if an unhandeled exception occurs in the irq there is a crash and the ESP reboots.
I had no time (yet) to see if it is a regression.

@dpgeorge dpgeorge force-pushed the esp32-ble-sync-events branch 2 times, most recently from 5b69fa2 to b459964 Compare April 1, 2021 06:10
@dpgeorge
Copy link
Member Author

dpgeorge commented Apr 1, 2021

I just noticed that if an unhandeled exception occurs in the irq there is a crash and the ESP reboots.

Should be fixed by the latest code in this PR (I force pushed to rebase on the lastest master).

@smurfix
Copy link
Contributor

smurfix commented Apr 14, 2021

Nice! If this is ready to be merged, could you remove the "WIP:" prefix and rebase to master?

@dpgeorge
Copy link
Member Author

If this is ready to be merged, could you remove the "WIP:" prefix and rebase to master?

It's not ready yet, it needs more testing and will not make it in before the next v1.15 release (which should be in the next few days).

@dpgeorge
Copy link
Member Author

This is still not 100% reliable, it can lock up the ESP32 (tested with IDF v4.2.2).

@smurfix
Copy link
Contributor

smurfix commented Jun 23, 2021

Are those lock-ups random? Specifically I just want to do a scan, to tell my home whether it's me at the front door.

@dpgeorge
Copy link
Member Author

Are those lock-ups random?

Yes. Running the BLE multitests in a loop, it will eventually lock the ESP32 so it does not respond to anything but a hard reset.

Copy link

@chriscmorgan chriscmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am running into this error on the esp32-c3 board when it tries to write to a notify characteristic and its rebooting.

Error:
GATT procedure initiated: notify; att_handle=21
assertion "pxQueue->uxItemSize == 0" failed: file "IDF/components/freertos/queue.c", line 1451, function: xQueueSemaphoreTake`

I do not get this error on the esp32 board but that one is having some trouble later in my code trying to connect to the wifi network.

full error.txt

@sahilrastogi94
Copy link

is this still being actively looked into?

dpgeorge added 2 commits July 22, 2022 17:38
If the Bluetooth stack runs on another OS thread then synchronous BLE irq
callbacks, which block the Bluetooth stack until the callback to Python is
complete, must coordinate with the main thread and configure the
MicroPython thread-local-state.

This commit adds MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS_WITH_INTERLOCK which
can be enabled if the system has these requirements.

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge force-pushed the esp32-ble-sync-events branch from 8602675 to 5dbb822 Compare July 22, 2022 07:42
@dpgeorge dpgeorge changed the title WIP: esp32: enable BLE synchronous events and BLE pairing/boindng esp32: enable BLE synchronous events and BLE pairing/boindng Jul 22, 2022
@dpgeorge
Copy link
Member Author

I've run extensive tests with this PR using ESP IDF v4.4.1and it works well.

@dpgeorge dpgeorge merged commit 5dbb822 into micropython:master Jul 22, 2022
@sahilrastogi94
Copy link

@dpgeorge can you share an example code to test ble pairing/bonding? I tried the example code, but it seems like the bonding information is not getting saved in nvs. I created a _FLAG_READ_ENCRYPTED characteristic and I have to repair using passkey after every reboot of esp32.

tannewt pushed a commit to tannewt/circuitpython that referenced this pull request Oct 22, 2022
@FlantasticDan
Copy link

I suspect this pull request removes the need for the following note in the Pairing and bonding section of the bluetooth docs:

Note: This is currently only supported when using the NimBLE stack on STM32 and Unix (not ESP32).

@dpgeorge if it does I'm happy to open a PR to amend the docs, I'm just awaiting hardware to test for myself and don't want to jump the gun.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants