-
Notifications
You must be signed in to change notification settings - Fork 198
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
What determines when the device sends an update? #68
Comments
@pvvx esp32_ble_tracker: |
These are bugs in the ESP32 BLE driver SDK. RF driver code, the operating system itself is closed for all ESPs - proprietary and does not belong to open-source. |
@pvvx I hope my questions did not come across as complaining. I was just trying to understand. As I mention in "setting context", I connected the dots that whatever the receiver is would not know when a device was offline other than X amount of time with no updates. So I started different tests seeing what should I set X time for. The first lesson learned is HA only updates when a value changes. So even when the device and ESP are communicating, the last_updated value was not changing. So I created a "heartbeat" sensor that the ESP creates and updates on each received from the device. That is when I asked about what are the expectations. From what I have read here and saw in practice, my X time, with default settings, is around 15 minutes. In fact, my ESP could not connect to HA, which a reboot of HA is what fixed it, help me see it in this graph. You can see the stretch in dark blue when it was the same value for a long time. Right now the time is from the ESP and I am not worried about it being right or better said "set right", just that it is changing. |
@pvvx Just found this old issue. I'm trying to request the last 50 readings from ESP32 and I'm getting only 15-20 notifications each time (there are gaps in the sequence numbers) so it looks like some are lost. Could it be because of ESP32 dropping packets? Are you aware of any workarounds? I thought indications should solve the problem but apparently they are not supported by this firmware. |
After the "Read memory measures" command, the thermometer changes the "connection interval" to a faster one. Default "Connection interval" is 20ms. And "Connection latency" is designed for 2.5 seconds. Changes in "Connection intervals/latency" are always consistent in the receiver and transmitter. If any of them do not agree with the change request, then the changes are not accepted.
The BLE in the ESP32 can receive all the packets, but not have time to process them at the top level of the software? PS: When receiving BLE advertisement packets, if there are many BLE devices, then the receiver receives BLE advertisements every 3 ms. UART speeds in 115200 Baud and even USB1.1 are not enough to transfer information in binary form in the HCI format. Requires BT adapter with USB2.0 HS. |
Ok, so I tried to build the firmware with I changed EDIT: Just saw your edit. Perhaps ESP32 does not accept 500 ms? |
"Connection latency" does not affect the transmission interval from the device. "Connection latency" is the amount of time a device may not respond or accept requests. But it can transmit with the "Connection interval" step. The receiver still needs to be prepared to accept every "connection interval". The code sets bls_pm_setManualLatency(0) so that the chip wakes up every ""Connection interval" and everything is unambiguous. To increase the step, you need to change the "connection interval". |
In the "connection intervals" you can change the ESP32 by sending a request after connecting. Additionally https://novelbits.io/ble-connection-intervals |
I can't see any option to change it after connecting: https://docs.micropython.org/en/latest/library/bluetooth.html Maybe MicroPython does not expose this API. |
Based on the links you provided, it seems that even setting a longer connection interval does not guarantee that packets will be transmitted slower, as multiple packets can be transmitted in a single connection interval. |
No more than the set MTU can be transmitted in one interval. You can request an increase in MTU during a connection. But that's not useful for these thermometers... Arduno ESP32 Test... I inserted a piece of code
into the sketch for ESP32 for testing.
50 measurements are transferred to the ESP32 in 12 seconds ESP32 does not have time to work out and the thermometer transmits duplicates ... Battery... |
Funny, yesterday's night I also tried Arduino :) And indeed, results for me were also much better. However, my sketch (which is based on this example) has One more thing I noticed yesterday in Arduino is that it was skipping the first 7 packets, i.e. I was getting 43 instead of 50. I had to add a small delay after subscribing to notifications and before sending a request. It doesn't seem you are doing such thing in your sketch so something else must be going on. I will try different combinations. |
Excellent point. I don't intend to query the sensor during a normal operation, but only when if ESP32 for some reason has gaps in readings from advertisements. Besides, I suppose the library can be easily changed to have fixed service indices. Big thanks for all your help! |
I felt like I was highjacking #23 question. An @MichielioZ pointed out that I was getting confused between the device sending advertising and updates. I just assumed that the device would send data with every advertising packet. I can see a power-saving by not turning on the measuring sensor, but if you are turning on the radio to send advertising would sending whatever the last data use that much more power?
What is the maximum time between updates?
Let me give a little more context for my question.
I have just started with ATC device and ESPHome. Seeing the update was asynchronous and ESPHome would not know if a device quit reporting, I started trying to figure out how to know if a device has not sent an update in X time. That way HA could send an alert that temp sensor XYZ is down. I was going to use the state property "last_updated". Because of some HA and ESPHome internals, I was going to create a Heartbeat based on the "on_value" event in ESPHome. That is when I notice that there are long times between data updates. That is why I am asking for the maximum time between updates, so I know when to send an alert that a sensor may be down.
The text was updated successfully, but these errors were encountered: