Weird log data from data sent by ESP32 - Printable Version +- phyphox Forums (https://phyphox.org/forums) +-- Forum: App-Feedback (https://phyphox.org/forums/forumdisplay.php?fid=6) +--- Forum: Bugs and Problems (https://phyphox.org/forums/forumdisplay.php?fid=9) +--- Thread: Weird log data from data sent by ESP32 (/showthread.php?tid=742) |
Weird log data from data sent by ESP32 - Uwe - 03-31-2020 Hi, I played around with the ESP32 example for Phyphox taken from here: https://phyphox.org/wiki/index.php?title=Micro-controller_based_sensors When I raised the frequency of notifications I found a surprising behaviour with time stamps logged in Phyphox and started to dig into that. I modified the sketch so it sends the value of millis() (converted to 16bit int) every 5ms to my Samsung S6 running Phyphox app. Here's the sketch used: Code: /* So each notification's value sent by ESP 32 increments by 5 and notification transmit interval is 5ms. No sensor used at all. This allows to compare timing of GATT server and client (so I thought). What I saw in Phyphox log was astonishing and up to now I have no idea what's going on:
On ESP32 I added logging of millis() to serial monitor but didn't saw any pause or spontaneous increase of the value. Good news is: this is not limited to Phyphox app; I also was able to see that behaviour e.g. with nRF connect app or LightBlue when logging data. So it seems to be a BLE topic in general (may be in combination with Android). I haven't tested other BLE connection parameters e.g. connection interval or others; even didn't set them explicitly at all, as I don't understand in detail (# packets per connection interval), so implicit default settings were used. I've attached Excel sheet with log data from Phyphox' CSV export. My questions:
Uwe RE: Weird log data from data sent by ESP32 - Sebastian Staacks - 03-31-2020 (03-31-2020, 01:54 PM)Uwe Wrote: Not surprising so far, this is similar to the maximum rate we have seen when trying to use higher rates. This of course can depend on signal quality and the actual devices used. (03-31-2020, 01:54 PM)Uwe Wrote: Well, the clock used has indeed a high resolution. Phyphox calls System.nanoTime() (Android) when it receives a value and that is the number you get there (here it is in the code:https://github.com/Staacks/phyphox-android/blob/335ab6bd71ec63a1eb769fcd3a0069310b00f308/app/src/main/java/de/rwth_aachen/phyphox/Bluetooth/BluetoothInput.java#L306) . However, this is not the time the value was measured or the time at which you called "notify". It is the time at which the value has passed the Bluetooth stacks and was handed over to the callback function in phyphox. When multiple values have the same timestamp, I would guess that there is some optimization going on that multiple values are transferred in one "burst", but I have to admit that my understanding of the Bluetooth protocol at that point is very limited. (03-31-2020, 01:54 PM)Uwe Wrote: Good news is: this is not limited to Phyphox app; I also was able to see that behaviour e.g. with nRF connect app or LightBlue when logging data.Relieved to read that This adds to my guess that it is an optimization in Bluetooth. BLE is not designed to guarantee the arrival of a value at a given time, but to be suitable for low energy applications. It makes sense that multiple values are stored to be sent in a single burst for efficiency. (03-31-2020, 01:54 PM)Uwe Wrote:So, yes, 200 Hz in my experience is a bit much. You might be able to increase the data rate by packing multiple values into a single notification. Simply let your characteristic not hold a single 16bit int (2 byte), but a sequence of multiple, which you can unpack in phyphox by using different offsets and appending the result. Not sure how much it helps, but it should reduce the overhead a bit. If this helps a lot in your case, you can also increase the MTU since the last phyphox version, to pack even more into a single package, although I would expect that there is a limit at which it won't help that much. The timestamp created by phyphox will always be subject to network lag, so even at lower rates with a weak and unstable connection, you might see some surprising delays in this value. To solve the timestamp issue, meaning to get reliable and precise timestamps, you need to measure the time on your device and either transfer it or make sure that you transfer equidistant (or is "equitemporal" the word?) measurements and create the timestamp in phyphox based on the assumption that you did not miss anything. You can either pack the timestamp with your transferred value (and simply assign them in phyphox using an offset= and the appropriate conversion function) or have a look at what we do for most sensor boxes. They all just send a stream of values and we have to assume that they are created at a given rate. This reduces the required bandwidth and remains precise even on a laggy connection. The downside is that value is not long-term stable if a package is missed. An example can be found in our configuration for the SensorTag: https://github.com/Staacks/phyphox-experiments/blob/master/bluetooth/TI%20SensorTag%20Accelerometer.phyphox - we simply create the time axis with a "ramp" module. RE: Weird log data from data sent by ESP32 - Uwe - 03-31-2020 Your reply explains very comprehensible what I saw during my tests. To summarize your recommendations:
I wasn't aware of these capabilities in details and all the functionality they provide. Again a lot to learn .... So a wide range of measure to work on and good chance to improve Thanks a lot for your outstanding support and help !! Uwe |