Device telemetry uptime in seconds (#3614)

This commit is contained in:
Ben Meadors
2024-04-14 10:27:01 -05:00
committed by GitHub
parent 5047468d9f
commit 4f205718f0
2 changed files with 30 additions and 12 deletions

View File

@@ -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;
};