mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-23 11:10:52 +00:00
Device telemetry uptime in seconds (#3614)
This commit is contained in:
@@ -12,6 +12,8 @@ class DeviceTelemetryModule : private concurrency::OSThread, public ProtobufModu
|
||||
: concurrency::OSThread("DeviceTelemetryModule"),
|
||||
ProtobufModule("DeviceTelemetry", meshtastic_PortNum_TELEMETRY_APP, &meshtastic_Telemetry_msg)
|
||||
{
|
||||
uptimeWrapCount = 0;
|
||||
uptimeLastMs = millis();
|
||||
setIntervalFromNow(45 * 1000); // Wait until NodeInfo is sent
|
||||
}
|
||||
virtual bool wantUIFrame() { return false; }
|
||||
@@ -28,8 +30,27 @@ class DeviceTelemetryModule : private concurrency::OSThread, public ProtobufModu
|
||||
*/
|
||||
bool sendTelemetry(NodeNum dest = NODENUM_BROADCAST, bool phoneOnly = false);
|
||||
|
||||
/**
|
||||
* Get the uptime in seconds
|
||||
* Loses some accuracy after 49 days, but that's fine
|
||||
*/
|
||||
uint32_t getUptimeSeconds() { return (0xFFFFFFFF / 1000) * uptimeWrapCount + (uptimeLastMs / 1000); }
|
||||
|
||||
private:
|
||||
meshtastic_Telemetry getDeviceTelemetry();
|
||||
uint32_t sendToPhoneIntervalMs = SECONDS_IN_MINUTE * 1000; // Send to phone every minute
|
||||
uint32_t lastSentToMesh = 0;
|
||||
|
||||
void refreshUptime()
|
||||
{
|
||||
auto now = millis();
|
||||
// If we wrapped around (~49 days), increment the wrap count
|
||||
if (now < uptimeLastMs)
|
||||
uptimeWrapCount++;
|
||||
|
||||
uptimeLastMs = now;
|
||||
}
|
||||
|
||||
uint32_t uptimeWrapCount;
|
||||
uint32_t uptimeLastMs;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user