balda / ruuvitag-discovery

Web interface to Discover RuuviTag Environmental Sensors and save measures to MQTT, InfluxDB, Graphite and Home Assistant
MIT License
31 stars 5 forks source link

period & frequency calculation is incorrect if packets are missed - defect #21

Open DG12 opened 3 years ago

DG12 commented 3 years ago

The period calculation in index.js/calcFrequency does not account for missing packets.

A ruuvi at distance or in a radio isolation area (like a refrigerator ) may miss packets.

Worst case is receiving 1 packet, missing many, then receiving 2 consequential packets causes the calculation to be the average. A better algorithm would be min( last calculation , this calculation ) but that's not really good either. Calculating the frequency requires the time of 2 consequential packets.

DG12 commented 3 years ago

Actually I suppose this means that the frequency/period cannot be calculated in the web page side.

balda commented 3 years ago

In fact, it's the period and frequency of reception, not emission. So, the math is good :) But it's true that I must specify it in the docs.

For the period and frequency of emission, we can maybe make something with the measurement sequence number to fill the holes (if tags are in data format 5). I'll think about it.

DG12 commented 3 years ago

Please review regarding not calculating in web page.