From 6dd4f2c950ea8a64d1e029a5c9f02c8b9c307eb0 Mon Sep 17 00:00:00 2001 From: taco Date: Tue, 24 Jun 2025 15:54:11 +1000 Subject: [PATCH 1/4] base uptime on first boot time --- examples/simple_repeater/main.cpp | 14 +++++++++++++- src/helpers/CommonCLI.cpp | 8 ++++++++ src/helpers/CommonCLI.h | 4 +++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index c33cadda3..1771e80db 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -195,7 +195,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { stats.n_packets_recv = radio_driver.getPacketsRecv(); stats.n_packets_sent = radio_driver.getPacketsSent(); stats.total_air_time_secs = getTotalAirTime() / 1000; - stats.total_up_time_secs = _ms->getMillis() / 1000; + stats.total_up_time_secs = getUptimeSecs(); stats.n_sent_flood = getNumSentFlood(); stats.n_sent_direct = getNumSentDirect(); stats.n_recv_flood = getNumRecvFlood(); @@ -254,6 +254,14 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { if (packet->isRouteFlood() && packet->path_len >= _prefs.flood_max) return false; return true; } + + uint32_t getUptimeSecs() const { + if (_cli.bootTime == 0) { + return _ms->getMillis() / 1000; + } else { + return (getRTCClock()->getCurrentTime() - _cli.bootTime); + } + } const char* getLogDateTime() override { static char tmp[32]; @@ -647,6 +655,10 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { void setLoggingOn(bool enable) override { _logging = enable; } + void setBootTime(uint32_t boot_time) { + _cli.bootTime = boot_time; // set the boot time for CLI + } + void eraseLogFile() override { _fs->remove(PACKET_LOG_FILE); } diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index 323f36338..71d01e18a 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -143,6 +143,10 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch } else if (memcmp(command, "clock sync", 10) == 0) { uint32_t curr = getRTCClock()->getCurrentTime(); if (sender_timestamp > curr) { + if (bootTime == 0) { + MESH_DEBUG_PRINTLN("clock sync: setting boot time..."); + _callbacks->setBootTime(sender_timestamp - (millis()/1000)); + } getRTCClock()->setCurrentTime(sender_timestamp + 1); uint32_t now = getRTCClock()->getCurrentTime(); DateTime dt = DateTime(now); @@ -162,6 +166,10 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch uint32_t secs = _atoi(&command[5]); uint32_t curr = getRTCClock()->getCurrentTime(); if (secs > curr) { + if (bootTime == 0) { + MESH_DEBUG_PRINTLN("clock set time: setting boot time..."); + _callbacks->setBootTime(sender_timestamp - (millis()/1000)); + } getRTCClock()->setCurrentTime(secs); uint32_t now = getRTCClock()->getCurrentTime(); DateTime dt = DateTime(now); diff --git a/src/helpers/CommonCLI.h b/src/helpers/CommonCLI.h index 1778c715c..7f44083d1 100644 --- a/src/helpers/CommonCLI.h +++ b/src/helpers/CommonCLI.h @@ -44,7 +44,8 @@ class CommonCLICallbacks { virtual void setTxPower(uint8_t power_dbm) = 0; virtual void formatNeighborsReply(char *reply) = 0; virtual const uint8_t* getSelfIdPubKey() = 0; - virtual void clearStats() = 0; + virtual void clearStats() = 0; + virtual void setBootTime(uint32_t bootTime) = 0; }; class CommonCLI { @@ -65,6 +66,7 @@ class CommonCLI { CommonCLI(mesh::MainBoard& board, mesh::RTCClock& rtc, NodePrefs* prefs, CommonCLICallbacks* callbacks) : _board(&board), _rtc(&rtc), _prefs(prefs), _callbacks(callbacks) { } + uint32_t bootTime = 0; void loadPrefs(FILESYSTEM* _fs); void savePrefs(FILESYSTEM* _fs); void handleCommand(uint32_t sender_timestamp, const char* command, char* reply); From 38f528b634d162abac89fbece2e777711cd6fe4f Mon Sep 17 00:00:00 2001 From: taco Date: Tue, 24 Jun 2025 16:04:33 +1000 Subject: [PATCH 2/4] add uptime fix to room server --- examples/simple_room_server/main.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/simple_room_server/main.cpp b/examples/simple_room_server/main.cpp index f5c1e9dc7..760984839 100644 --- a/examples/simple_room_server/main.cpp +++ b/examples/simple_room_server/main.cpp @@ -305,7 +305,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { stats.n_packets_recv = radio_driver.getPacketsRecv(); stats.n_packets_sent = radio_driver.getPacketsSent(); stats.total_air_time_secs = getTotalAirTime() / 1000; - stats.total_up_time_secs = _ms->getMillis() / 1000; + stats.total_up_time_secs = getUptimeSecs(); stats.n_sent_flood = getNumSentFlood(); stats.n_sent_direct = getNumSentDirect(); stats.n_recv_flood = getNumRecvFlood(); @@ -403,6 +403,14 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { return (int) ((pow(_prefs.rx_delay_base, 0.85f - score) - 1.0) * air_time); } + uint32_t getUptimeSecs() const { + if (_cli.bootTime == 0) { + return _ms->getMillis() / 1000; + } else { + return (getRTCClock()->getCurrentTime() - _cli.bootTime); + } + } + const char* getLogDateTime() override { static char tmp[32]; uint32_t now = getRTCClock()->getCurrentTime(); @@ -807,6 +815,10 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { } } + void setBootTime(uint32_t boot_time) { + _cli.bootTime = boot_time; // set the boot time for CLI + } + void setLoggingOn(bool enable) override { _logging = enable; } void eraseLogFile() override { From 55ee35ee4856c15e7ddf0058d3a6d668a53f4739 Mon Sep 17 00:00:00 2001 From: taco Date: Tue, 24 Jun 2025 23:16:48 +1000 Subject: [PATCH 3/4] remove unnecessary comments and debug lines --- examples/simple_repeater/main.cpp | 2 +- src/helpers/CommonCLI.cpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 1771e80db..43c82da43 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -656,7 +656,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { void setLoggingOn(bool enable) override { _logging = enable; } void setBootTime(uint32_t boot_time) { - _cli.bootTime = boot_time; // set the boot time for CLI + _cli.bootTime = boot_time; } void eraseLogFile() override { diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index 71d01e18a..289128bc6 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -144,7 +144,6 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch uint32_t curr = getRTCClock()->getCurrentTime(); if (sender_timestamp > curr) { if (bootTime == 0) { - MESH_DEBUG_PRINTLN("clock sync: setting boot time..."); _callbacks->setBootTime(sender_timestamp - (millis()/1000)); } getRTCClock()->setCurrentTime(sender_timestamp + 1); @@ -167,7 +166,6 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch uint32_t curr = getRTCClock()->getCurrentTime(); if (secs > curr) { if (bootTime == 0) { - MESH_DEBUG_PRINTLN("clock set time: setting boot time..."); _callbacks->setBootTime(sender_timestamp - (millis()/1000)); } getRTCClock()->setCurrentTime(secs); From cf3e5e88f8da0f85dccbff0cfb1db346185066b3 Mon Sep 17 00:00:00 2001 From: taco Date: Wed, 25 Jun 2025 10:37:19 +1000 Subject: [PATCH 4/4] remove whitespace --- src/helpers/CommonCLI.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/CommonCLI.h b/src/helpers/CommonCLI.h index 7f44083d1..6ee263232 100644 --- a/src/helpers/CommonCLI.h +++ b/src/helpers/CommonCLI.h @@ -44,7 +44,7 @@ class CommonCLICallbacks { virtual void setTxPower(uint8_t power_dbm) = 0; virtual void formatNeighborsReply(char *reply) = 0; virtual const uint8_t* getSelfIdPubKey() = 0; - virtual void clearStats() = 0; + virtual void clearStats() = 0; virtual void setBootTime(uint32_t bootTime) = 0; };