Fixed last_seen calculation with zigbee devices.

The specific circumstances of this bug typically involve a restart, after which a zigbee
device pings the bridge before the Rtc.utc_time is set by NTP. This results in a large "last seen"
time calculation. This is cosmetic only. This patch ensures the "last seen" time is after
2020-01-01 0000 UTC when pulled from the Rtc.utc_time field, otherwise, last_seen updates are
ignored.
This commit is contained in:
Justin Monroe 2020-09-27 17:23:54 +00:00
parent 1de3364b5e
commit b2443ec548
1 changed files with 6 additions and 1 deletions

View File

@ -645,7 +645,12 @@ void Z_Devices::setLQI(uint16_t shortaddr, uint8_t lqi) {
void Z_Devices::setLastSeenNow(uint16_t shortaddr) {
if (shortaddr == localShortAddr) { return; }
getShortAddr(shortaddr).last_seen= Rtc.utc_time;
// Only update time if after 2020-01-01 0000.
// Fixes issue where zigbee device pings before WiFi/NTP has set utc_time
// to the correct time, and "last seen" calculations are based on the
// pre-corrected last_seen time and the since-corrected utc_time.
if (Rtc.utc_time < 1577836800) { return; }
getShortAddr(shortaddr).last_seen = Rtc.utc_time;
}