Why not structure the code a bit different:
- have one async task read/delete from the queue and send to BLE
- have one async task reading the buttons and write events to the queue
- have one async task measuring voltage and write values to the queue
If each button press is in one event, I would add a timestamp ticks_us to be sent with the button identifier. Allows to handle latency on receiver side. Also useful to add a sequence counter which helps to identify missing messages (BLE is still radio transmission and prone to errors.)
There is a messageformat I found recently with small BLE buttons: BTHome BLE, see https://bthome.io/ In a nutshell, they send packet_id 00; battery 01, button 3a in one message. They have no timestamp, but there are no concurrent button presses in this device.
- have one async task read/delete from the queue and send to BLE
- have one async task reading the buttons and write events to the queue
- have one async task measuring voltage and write values to the queue
If each button press is in one event, I would add a timestamp ticks_us to be sent with the button identifier. Allows to handle latency on receiver side. Also useful to add a sequence counter which helps to identify missing messages (BLE is still radio transmission and prone to errors.)
There is a messageformat I found recently with small BLE buttons: BTHome BLE, see https://bthome.io/ In a nutshell, they send packet_id 00; battery 01, button 3a in one message. They have no timestamp, but there are no concurrent button presses in this device.
Statistics: Posted by ghp — Tue Feb 24, 2026 8:38 pm