ESP: first implementation; compiles fine; not tested with MCU
This commit is contained in:
1 parent
5bdcb51bff
commit
6bda641ce8
36 files changed
+6234
No files matched your search
@@ -0,0 +1,42 @@
|
||||
// device_stats.h — the counters reported in the conditions payload.
|
||||
//
|
||||
// Kept in RTC slow memory, so they survive deep sleep. They do NOT survive a
|
||||
// power cycle, which is deliberate: the endpoint already has the authoritative
|
||||
// count of what arrived, and a device-side counter that claimed to be durable
|
||||
// would just be a second source of truth to disagree with the first. Treat
|
||||
// these as "what this device believes it did today" and reconcile against the
|
||||
// database, not the other way round.
|
||||
//
|
||||
// "Today" is local-midnight to local-midnight, using the TZ pushed from the
|
||||
// endpoint. Rollover needs a synced clock; before the first sync the counters
|
||||
// accumulate under day 0 and roll over once when time arrives.
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
struct DeviceStats {
|
||||
uint16_t captured_today; // frames handed to the uploader
|
||||
uint16_t delivered_today; // frames the endpoint accepted (2xx)
|
||||
uint16_t failed_today; // upload attempts that did not get a 2xx
|
||||
uint16_t events_today; // trigger events, not frames
|
||||
uint32_t day_index; // days since epoch, local — the rollover key
|
||||
|
||||
uint16_t captured_boot; // since this boot, for spotting a reset
|
||||
uint16_t delivered_boot;
|
||||
};
|
||||
|
||||
void statsBegin();
|
||||
|
||||
// Roll the daily counters over if the local date has changed. Cheap; call
|
||||
// from the main loop and before building any status payload.
|
||||
void statsRollover();
|
||||
|
||||
void statsCountEvent();
|
||||
void statsCountCaptured(uint16_t frames);
|
||||
void statsCountDelivered(uint16_t frames);
|
||||
void statsCountFailed(uint16_t frames);
|
||||
|
||||
DeviceStats statsGet();
|
||||
|
||||
// Ticks since the device last woke, in ms — "ticks since last sleep".
|
||||
uint32_t statsAwakeMs();
|
||||
Reference in new issue
Block a user