-
DescriptionI have a BLE server running on an ESP32 using Micropython. This sends two integers each second with each one being incremented by 1 each time. I have successfully connected to the device using my laptop and when I call read_gatt_char() in a loop I was expecting the function to block until the next two integers were sent. Instead, the function returns immediately with the values last sent from the device. What I DidThe code below runs and reads the data sent by the device correctly. However I was expecting it to print the two numbers once per second, e.g. 1 1 but, instead, it repeats the loop many times a second displaying a list like: 1 1
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
BLE is a stateless protocol. Reading a characteristic always returns the current value. If you want to know when a value changes, have a look at notifications instead - if this characteristics support it. |
Beta Was this translation helpful? Give feedback.
-
Many thanks for the explanation. I was treating it more like UDP sockets where the receive would wait for the next message. I have moved to notifications now and my code works perfectly. |
Beta Was this translation helpful? Give feedback.
BLE is a stateless protocol. Reading a characteristic always returns the current value. If you want to know when a value changes, have a look at notifications instead - if this characteristics support it.