fix: preserve original telemetry timestamp on periodic resend#2120
Conversation
The periodic reporting thread in __periodical_reporting() was overwriting the original telemetry timestamp with the current wall-clock time before re-sending cached values. This made it impossible for downstream consumers to detect stale data — the timestamp always looked fresh even if the source device had stopped updating. Now periodic resends use the original timestamp from when the value was last received from the device (via report_strategy_data_record.get_ts()). The receivedTs in metadata still reflects when the gateway forwarded the data, covering the "last forwarded" use case. Fixes thingsboard#2119
|
Correct me if i am wrong but doesn't this defeat the purpose of The |
|
If that's the case, then I propose a new reporting strategy that either sends data on change, or every reporting period (but preserves the timestamp so the user knows if it's stale). In my customer dashboard, I want to show data updates periodically (eg, every 30s), but also instant updates when values have changed. When a device has gone stale, the current reporting strategy would keep sending the stale data as if it were fresh, misleading the customer. Currently, there is no (to my understanding, correct me if I'm wrong) report strategy that has this behavior. |

Summary
__periodical_reporting()report_strategy_data_record.get_ts()) so downstream consumers can detect stale datareceivedTsin metadata still reflects when the gateway forwarded the dataProblem
When using
ON_REPORT_PERIODorON_CHANGE_OR_REPORT_PERIODstrategies, the periodic reporting thread replaced the original telemetry timestamp withint(time() * 1000)before re-sending. This made stale data appear fresh in ThingsBoard. If a device stopped updating, thetskept advancing every report period, breaking any staleness detection in dashboards, rule chains, or frontends.Change
In
report_strategy_service.py,__periodical_reporting():The commented-out line that already existed for this purpose has been activated and the timestamp-overwriting code removed.
Test plan
ON_CHANGE_OR_REPORT_PERIODstrategy (e.g. 60s report period)tsstays at the original value (does not advance every 60s)receivedTsin metadata still updates on each resendtsupdates correctly viafilter_datapoint_and_cacheON_REPORT_PERIODstrategy as wellFixes #2119