feat(clock): a node with no GPS starts at its build epoch, not in 2024
Measured 7. 8. 2026: bench-board had been running 811 days behind since it was deployed, and every board on the bench was 812 days behind. Nobody had ever set their clocks, because setting one was a manual step documented in two places and performed in neither. That is not cosmetic. Mesh.cpp stamps every advert a node transmits from the RTC, and a receiver drops a stale timestamp as a replay -- so a wrong clock turns into replies that vanish. Nothing could fix it by itself. The only automatic sources in the tree are GPS (which these nodes do not have) and BaseChatMesh, which the repeater build does not link; and `clock sync` cannot work from the console at all, because USB and BLE share one command buffer and pass sender_timestamp = 0, so the `sender_timestamp > curr` guard is never satisfied. So build_version.py now also stamps FIRMWARE_BUILD_EPOCH, and that -- not a hardcoded 15 May 2024 -- is where a clock with no other source comes up. A freshly flashed board is right to within "time since compile". It needs no GPS, nothing carrying a correct time on air, and no host: the one case the host-side tooling cannot reach. Verified on x1: build epoch 1786100869 = 11:07:49, and after a reboot the board came up at 11:07:47. The #ifndef fallback is load-bearing, not decoration: build_version.py is nRF52-only and reaches 7 of the 16 local envs, so upstream envs never define it. Verifying an integer define is not `strings` -- dump .text and look for the word, and check the old literal is gone from all three sites. `clock` also reports the epoch now. Its human part is minutes only, so a host comparing clocks could not see a difference under a minute and had to leave a 59 s deadband; appended, so anything that just prints the reply is unaffected. Also here, and DISABLED, is carrying the clock across a soft reset in retained RAM. It was tried and measured not to work: the record at 0x2003FFE0 came back as `00000000 10001000 00000000` after a reboot -- not zeroed, OVERWRITTEN, and 0x10001000 is the nRF52 UICR base, i.e. a UICR pointer left on the Adafruit bootloader's stack. The bootloader runs before the app on every reset and links against the full RAM, so it owns the top of it; being outside the app's linker region is not enough. The code stays because it self-disables against __StackTop and now says so at boot, and because the same doubt applies to the hardfault record at 0x2003FFF0, which sits HIGHER -- treat a missing hardfault report as "unknown", not as "nothing crashed". Two things that cost a cycle each and are now designed out: the restore's "nothing stored" branch was silent, which is indistinguishable from "working"; and `clkreboot` would have undone itself, writing the build epoch and then having the reboot restore the value it just discarded (weak retainedClockInvalidate() closes that). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a49bbb914d
commit
4fb886170f
8 files changed
+248
-8
No files matched your search
@@ -47,18 +47,36 @@ This document provides an overview of CLI commands that can be sent to MeshCore
|
||||
|
||||
**Note:** No reply is sent.
|
||||
|
||||
Resets the clock to the firmware's build epoch (or, on an unstamped build, the
|
||||
upstream 15 May 2024 literal) and reboots. This is the **only** way to move a
|
||||
clock backwards: `time` and `clock sync` both refuse to.
|
||||
|
||||
---
|
||||
|
||||
### Sync the clock with the remote device
|
||||
**Usage:**
|
||||
- `clock sync`
|
||||
|
||||
Takes the time from the *packet's* `sender_timestamp`, so it works **only over
|
||||
the remote admin CLI**, never from the USB or BLE console — those pass
|
||||
`sender_timestamp = 0` (they share one command buffer, see
|
||||
`examples/simple_repeater/main.cpp`), and `0 > curr` is never true, so a local
|
||||
`clock sync` always answers `ERR: clock cannot go backwards`. Use `time <epoch>`
|
||||
locally.
|
||||
|
||||
---
|
||||
|
||||
### Display current time in UTC
|
||||
**Usage:**
|
||||
- `clock`
|
||||
|
||||
**Reply:** `HH:MM - D/M/YYYY UTC (epoch <seconds>)`
|
||||
|
||||
The epoch is a TeTeHacko addition. The human part is minutes only, so a host
|
||||
comparing clocks cannot see a difference smaller than a minute and has to leave
|
||||
a deadband of over 59 s; the epoch makes the comparison exact. It is appended,
|
||||
so anything that only prints the reply is unaffected.
|
||||
|
||||
---
|
||||
|
||||
### Set the time to a specific timestamp
|
||||
@@ -68,6 +86,23 @@ This document provides an overview of CLI commands that can be sent to MeshCore
|
||||
**Parameters:**
|
||||
- `epoch_seconds`: Unix epoch time
|
||||
|
||||
Refuses to go backwards (`secs > curr`), answering
|
||||
`(ERR: clock cannot go backwards)`. That reply usually means the clock was
|
||||
already right, so treat it as success and judge by reading `clock` back.
|
||||
|
||||
**Where the clock comes from if nobody sets it.** Without GPS and without an
|
||||
I2C RTC the clock is volatile: it starts at the build epoch and only ticks from
|
||||
`millis()`. It is worth setting, because the RTC stamps every advert the node
|
||||
transmits and a receiver drops a stale timestamp as a replay. Automatic sources,
|
||||
in order of preference:
|
||||
|
||||
- **GPS** (`gps duty` is enough — see `docs/power-saving.md`);
|
||||
- **an attached host** — `tools/ble_cli.py <MAC> "time {epoch}"`, the
|
||||
`meshcore-ble-bridge`/`meshcore-serial-bridge` scrape, or
|
||||
`tools/xiao_uf2_flash.sh`, which sets it right after every flash;
|
||||
- **the build epoch**, which is where a freshly flashed board starts, and
|
||||
which needs nothing at all.
|
||||
|
||||
---
|
||||
|
||||
### Send a flood advert
|
||||
|
||||
Reference in new issue
Block a user