Report an unset clock when the session opens and once a minute while reports are sent
When no NTP server answers (DNS for the pool fails, outbound UDP port 123 is blocked) the bridge connects after 5 s and every report carries a timeOfSample in 1970 for as long as the board runs. The only trace was one line at boot. 1.1.0 did not need the time of day: the HTTP route of the backend stamped the reports. Alex2ESP::timestamp() now checks the clock it reads. While it is not set, the line that says so is printed when the session opens and then at most once per 60 s while reports are built; timestamp() runs once per property, so the line is limited by time and not per call. The line names what to check: "the clock is not set, reports carry a time in 1970: no answer from pool.ntp.org or time.nist.gov (DNS, outbound UDP port 123)", or, after setTimeSource(false), that the clock is left to the sketch. It replaces "clock not set after 5000 ms: ...". For a sketch: the reports are sent as before, with the time the clock has. The readme says in its Session paragraph that the board has to reach an NTP server. Measured with the bridge built for the host against a fake MQTT client (not in the repository), clock never set, a report of two properties every 10 s for 300 s: 30 reports sent, the line printed once at the connect and 5 times in the 300 s; with the clock set, not at all. Not checked here: what Alexa does with a report stamped 1970. That needs the board (TEST-PLAN 3.1, last row). examples/basicLight.cpp for d1_mini, static RAM / flash in bytes: 34,444 / 337,145 -> 34,452 / 337,401, no warnings. 41 host tests pass. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
6fe8311a6f
commit
39717d5287
3 changed files with 38 additions and 5 deletions
|
|
@ -73,6 +73,7 @@ public:
|
|||
|
||||
private:
|
||||
static const unsigned long CLOCK_WAIT_MS = 5000; // How long the first connect waits for SNTP
|
||||
static const unsigned long CLOCK_WARNING_MS = 60000; // How often an unset clock is reported while it is used
|
||||
static const unsigned long RECONNECT_INTERVAL_MS = 5000;
|
||||
static const unsigned long DISCOVERY_WINDOW_MS = 5000; // How long the backend keeps collecting a discovery answer
|
||||
static const unsigned long DISCOVERY_RETRY_MS = 20; // Pause before a refused discovery publish is tried again
|
||||
|
|
@ -89,6 +90,8 @@ private:
|
|||
AsyncMqttClientDisconnectReason disconnectReason;
|
||||
bool useSntp;
|
||||
unsigned long beginTime; // millis() when begin() ran
|
||||
bool clockWarned; // The unset clock has been reported
|
||||
unsigned long lastClockWarning; // millis() of that report
|
||||
unsigned long lastReconnectTime;
|
||||
uint16_t discoverSubscription; // Packet ids of the two SUBSCRIBEs, to match their acknowledgements
|
||||
uint16_t directiveSubscription;
|
||||
|
|
@ -113,6 +116,7 @@ private:
|
|||
|
||||
//loop processing function
|
||||
void connectWhenClockIsSet();
|
||||
void warnAboutClock();
|
||||
void handleMqttReconnection();
|
||||
void continueDiscovery();
|
||||
void publishDiscovery();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue