Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/simple_repeater/MyMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
return _prefs.multi_acks;
}

bool shouldSyncClockFromMesh() const override { return true; }

#if ENV_INCLUDE_GPS == 1
void applyGpsPrefs() {
sensors.setSettingValue("gps", _prefs.gps_enabled?"1":"0");
Expand Down Expand Up @@ -252,4 +254,4 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
#if defined(USE_SX1262) || defined(USE_SX1268)
void setRxBoostedGain(bool enable) override;
#endif
};
};
12 changes: 12 additions & 0 deletions src/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,18 @@ DispatcherAction Mesh::onRecvPacket(Packet* pkt) {
}
if (is_ok) {
MESH_DEBUG_PRINTLN("%s Mesh::onRecvPacket(): valid advertisement received!", getLogDateTime());

// sync clock from verified advert if local clock is clearly wrong (for repeaters without hardware RTC)
if (shouldSyncClockFromMesh()) {
uint32_t local_time = _rtc->getCurrentTime();
if (local_time < 1735689600UL // local clock before Jan 2025 (clearly wrong)
&& timestamp > 1735689600UL // advert after Jan 2025
&& timestamp < 2082758400UL) { // advert before Jan 2036
_rtc->setCurrentTime(timestamp);
MESH_DEBUG_PRINTLN(" clock synced from advert: %lu", (unsigned long)timestamp);
}
}

onAdvertRecv(pkt, id, timestamp, app_data, app_data_len);
action = routeRecvPacket(pkt);
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class Mesh : public Dispatcher {
*/
virtual bool filterRecvFloodPacket(Packet* packet) { return false; }

// sync clock from verified advert if local clock is clearly wrong
virtual bool shouldSyncClockFromMesh() const { return false; }

/**
* \brief Check whether this packet should be forwarded (re-transmitted) or not.
* Is sub-classes responsibility to make sure given packet is only transmitted ONCE (by this node)
Expand Down Expand Up @@ -222,4 +225,4 @@ class Mesh : public Dispatcher {

};

}
}