ubluetooth - Question regarding event codes and subscribing to notifying characteristics
Posted: Tue Jun 16, 2020 11:50 pm
I am trying to control a BLE-accessible motor with an ESP32 board. I am quite new to microcontroller programming and first tried to use the Arduino IDE, soon to find out that C programming is still not much fun (for me). As this is part of a home improvement project I decided it should be fun and switched to MicroPython as python is pretty native to me.
I have most of the basic building blocks working at the moment, including uasyncio to allow for cooperative multi-tasking and scheduling, an asynchronous webserver to provide a GUI and ubluetooth actually talking to the motor. There are a few things however that I don't seem to grasp on the bluetooth part.
My setup:
When I started playing around with this a few months ago all event codes where declared with a statement using bit shifting, like
In the official documentation I now find a different way to declare the event codes that doesn't use bit shifting anymore and also declares different integer values for the events:
I also see that some event codes have been added w.r.t. the info I found a few months ago, like _IRQ_SCAN_DONE, _IRQ_GATTC_SERVICE_DONE and _IRQ_GATTC_CHARACTERISTIC_DONE.
Question: my software version (v1.12) still seems to be the latest stable build for ESP32, but the event codes in the documentation do not match the event codes working with this build. Where would I find any documentation regarding this change and when can I expect these new event codes to be usable in a stable build for ESP32?
2. How do I subscribe to notifications from a peripheral device?
I have set up my ESP32 to act as a BLE Central, connecting to two peripheral motors.
Using the code I currently use I can successfully:
On my Android phone I can use nRF connect to see that the motor position characteristic does have properties READ and NOTIFY.
Question: how do I subscribe to notify events for a certain characteristic? I did have a look at some example ble_temperature_central.py but it also doesn't seem to actively subscribe to the notifications.
I hope someone can shed some light on these questions. Anyway, thanks for all effort put into MicroPython and all the useful info on this forum!
Kind regards,
Bart
I have most of the basic building blocks working at the moment, including uasyncio to allow for cooperative multi-tasking and scheduling, an asynchronous webserver to provide a GUI and ubluetooth actually talking to the motor. There are a few things however that I don't seem to grasp on the bluetooth part.
My setup:
- Board: ESP WROOM 32 development board from Geekcreit
- Build: "MicroPython v1.12 on 2019-12-20; ESP32 module with ESP32" with IDF v4, no SPIRAM (esp32-idf4-20191220-v1.12.bin)
When I started playing around with this a few months ago all event codes where declared with a statement using bit shifting, like
Code: Select all
_IRQ_SCAN_RESULT = const(1 << 4) #16
Code: Select all
_IRQ_SCAN_RESULT = const(5) #5
Question: my software version (v1.12) still seems to be the latest stable build for ESP32, but the event codes in the documentation do not match the event codes working with this build. Where would I find any documentation regarding this change and when can I expect these new event codes to be usable in a stable build for ESP32?
2. How do I subscribe to notifications from a peripheral device?
I have set up my ESP32 to act as a BLE Central, connecting to two peripheral motors.
Using the code I currently use I can successfully:
- Scan for available devices [_IRQ_SCAN_RESULT, _IRQ_SCAN_COMPLETE]
- Connect to the motors [_IRQ_PERIPHERAL_CONNECT, _IRQ_PERIPHERAL_DISCONNECT]
- Discover services and characteristics [_IRQ_GATTC_SERVICE_RESULT, _IRQ_GATTC_CHARACTERISTIC_RESULT]
- Read values from characteristics (motor position, battery level, etc) [_IRQ_GATTC_READ_RESULT]
- Write values to characteristics (motor position target, motor move up, motor move down, stop, etc) [_IRQ_GATTC_WRITE_RESULT]
On my Android phone I can use nRF connect to see that the motor position characteristic does have properties READ and NOTIFY.
Question: how do I subscribe to notify events for a certain characteristic? I did have a look at some example ble_temperature_central.py but it also doesn't seem to actively subscribe to the notifications.
I hope someone can shed some light on these questions. Anyway, thanks for all effort put into MicroPython and all the useful info on this forum!
Kind regards,
Bart