77 bool valid = PersistentDataFile::validate(dataSize);
83 Log.info(
"data not valid open time =%d",
sysStatus.get_openTime());
89 Log.info(
"data not valid close time =%d",
sysStatus.get_closeTime());
94 if (
sysStatus.get_lastConnectionDuration() > 900) {
95 Log.info(
"data not valid last connection duration =%d",
sysStatus.get_lastConnectionDuration());
99 Log.info(
"sysStatus data is %s",(valid) ?
"valid":
"not valid");
104 PersistentDataFile::initialize();
106 const char message[26] =
"Loading System Defaults";
109 Log.info(
"Loading system defaults");
126 sysStatus.set_connectedReportingIntervalSec(300);
127 sysStatus.set_lowPowerReportingIntervalSec(3600);
128 sysStatus.set_connectAttemptBudgetSec(300);
129 sysStatus.set_cloudDisconnectBudgetSec(15);
134 return getValue<uint8_t>(offsetof(
SysData, structuresVersion));
138 setValue<uint8_t>(offsetof(
SysData, structuresVersion), value);
142 return getValue<bool>(offsetof(
SysData,verboseMode));
146 setValue<bool>(offsetof(
SysData, verboseMode), value);
150 return getValue<bool>(offsetof(
SysData,solarPowerMode ));
153 setValue<bool>(offsetof(
SysData, solarPowerMode), value);
157 return getValue<bool>(offsetof(
SysData,lowPowerMode ));
160 setValue<bool>(offsetof(
SysData, lowPowerMode), value);
164 return getValue<bool>(offsetof(
SysData, lowBatteryMode));
167 setValue<bool>(offsetof(
SysData, lowBatteryMode), value);
171 return getValue<uint8_t>(offsetof(
SysData,resetCount));
174 setValue<uint8_t>(offsetof(
SysData, resetCount), value);
188 return getValue<uint8_t>(offsetof(
SysData,openTime));
191 setValue<uint8_t>(offsetof(
SysData, openTime), value);
195 return getValue<uint8_t>(offsetof(
SysData,closeTime));
198 setValue<uint8_t>(offsetof(
SysData, closeTime), value);
202 return getValue<time_t>(offsetof(
SysData,lastReport));
205 setValue<time_t>(offsetof(
SysData, lastReport), value);
209 return getValue<time_t>(offsetof(
SysData,lastConnection));
212 setValue<time_t>(offsetof(
SysData, lastConnection), value);
216 return getValue<uint16_t>(offsetof(
SysData,lastConnectionDuration));
219 setValue<uint16_t>(offsetof(
SysData, lastConnectionDuration), value);
223 return getValue<time_t>(offsetof(
SysData,lastHookResponse));
226 setValue<time_t>(offsetof(
SysData, lastHookResponse), value);
230 return getValue<uint8_t>(offsetof(
SysData,sensorType));
233 setValue<uint8_t>(offsetof(
SysData, sensorType), value);
237 return getValue<bool>(offsetof(
SysData,updatesPending));
240 setValue<bool>(offsetof(
SysData,updatesPending), value);
244 return getValue<uint16_t>(offsetof(
SysData,reportingInterval));
247 setValue<uint16_t>(offsetof(
SysData, reportingInterval), value);
251 return getValue<bool>(offsetof(
SysData,disconnectedMode));
254 setValue<bool>(offsetof(
SysData,disconnectedMode), value);
258 return getValue<bool>(offsetof(
SysData,serialConnected));
261 setValue<bool>(offsetof(
SysData,serialConnected), value);
265 return getValue<time_t>(offsetof(
SysData,lastDailyCleanup));
268 setValue<time_t>(offsetof(
SysData, lastDailyCleanup), value);
272 return getValue<time_t>(offsetof(
SysData,lastTimeSync));
275 setValue<time_t>(offsetof(
SysData, lastTimeSync), value);
281 return getValue<uint8_t>(offsetof(
SysData,countingMode));
284 setValue<uint8_t>(offsetof(
SysData,countingMode), value);
288 return getValue<uint8_t>(offsetof(
SysData,operatingMode));
291 setValue<uint8_t>(offsetof(
SysData,operatingMode), value);
295 return getValue<uint32_t>(offsetof(
SysData,occupancyDebounceMs));
298 setValue<uint32_t>(offsetof(
SysData,occupancyDebounceMs), value);
302 return getValue<uint16_t>(offsetof(
SysData,connectedReportingIntervalSec));
305 setValue<uint16_t>(offsetof(
SysData,connectedReportingIntervalSec), value);
309 return getValue<uint16_t>(offsetof(
SysData,lowPowerReportingIntervalSec));
312 setValue<uint16_t>(offsetof(
SysData,lowPowerReportingIntervalSec), value);
316 return getValue<uint16_t>(offsetof(
SysData,connectAttemptBudgetSec));
319 setValue<uint16_t>(offsetof(
SysData,connectAttemptBudgetSec), value);
323 return getValue<uint16_t>(offsetof(
SysData,cloudDisconnectBudgetSec));
326 setValue<uint16_t>(offsetof(
SysData,cloudDisconnectBudgetSec), value);
330 return getValue<uint16_t>(offsetof(
SysData,modemOffBudgetSec));
333 setValue<uint16_t>(offsetof(
SysData,modemOffBudgetSec), value);
363 .withSaveDelayMs(250)
372 bool valid = PersistentDataFile::validate(dataSize);
375 Log.info(
"Sensor config: thresholds not valid (threshold1=%d, threshold2=%d)",
380 Log.info(
"Sensor config is %s", (valid) ?
"valid" :
"not valid");
385 PersistentDataFile::initialize();
387 Log.info(
"Current Data Initialized");
394 return getValue<uint16_t>(offsetof(
SensorData, threshold1));
398 setValue<uint16_t>(offsetof(
SensorData, threshold1), value);
402 return getValue<uint16_t>(offsetof(
SensorData, threshold2));
406 setValue<uint16_t>(offsetof(
SensorData, threshold2), value);
409 return getValue<uint16_t>(offsetof(
SensorData, pollingRate));
413 setValue<uint16_t>(offsetof(
SensorData, pollingRate), value);
444 .withSaveDelayMs(250)
453 current.set_lastCountTime(Time.now());
462 current.set_lastOccupancyEvent(0);
463 current.set_occupancyStartTime(0);
464 current.set_totalOccupiedSeconds(0);
468 bool valid = PersistentDataFile::validate(dataSize);
471 if (
current.get_hourlyCount() > 10000 ||
current.get_dailyCount() > 100000) {
472 Log.info(
"Current: counts appear invalid, resetting");
478 Log.info(
"Current data is %s", (valid) ?
"valid" :
"not valid");
483 PersistentDataFile::initialize();
485 Log.info(
"Current Data Initialized");
494 return getValue<uint16_t>(offsetof(
CurrentData, faceNumber));
498 setValue<uint16_t>(offsetof(
CurrentData, faceNumber), value);
502 return getValue<uint16_t>(offsetof(
CurrentData, faceScore));
506 setValue<uint16_t>(offsetof(
CurrentData, faceScore), value);
509 return getValue<uint16_t>(offsetof(
CurrentData, gestureType));
513 setValue<uint16_t>(offsetof(
CurrentData, gestureType), value);
517 return getValue<uint16_t>(offsetof(
CurrentData, gestureScore));
521 setValue<uint16_t>(offsetof(
CurrentData, gestureScore), value);
525 return getValue<time_t>(offsetof(
CurrentData, lastCountTime));
529 setValue<time_t>(offsetof(
CurrentData, lastCountTime), value);
533 return getValue<float>(offsetof(
CurrentData, internalTempC));
537 setValue<float>(offsetof(
CurrentData, internalTempC), value);
541 return getValue<float>(offsetof(
CurrentData, externalTempC));
545 setValue<float>(offsetof(
CurrentData, externalTempC), value);
549 return getValue<int8_t>(offsetof(
CurrentData, alertCode));
553 setValue<int8_t>(offsetof(
CurrentData, alertCode), value);
558 return getValue<time_t>(offsetof(
CurrentData,lastAlertTime));
562 setValue<time_t>(offsetof(
CurrentData,lastAlertTime),value);
567static int getAlertSeverity(int8_t code) {
602 if (getAlertSeverity(value) > getAlertSeverity(existing)) {
609 return getValue<float>(offsetof(
CurrentData,stateOfCharge));
612 setValue<float>(offsetof(
CurrentData, stateOfCharge), value);
616 return getValue<uint8_t>(offsetof(
CurrentData, batteryState));
619 setValue<uint8_t>(offsetof(
CurrentData, batteryState), value);
625 return getValue<uint16_t>(offsetof(
CurrentData, hourlyCount));
628 setValue<uint16_t>(offsetof(
CurrentData, hourlyCount), value);
632 return getValue<uint16_t>(offsetof(
CurrentData, dailyCount));
635 setValue<uint16_t>(offsetof(
CurrentData, dailyCount), value);
641 return getValue<bool>(offsetof(
CurrentData, occupied));
644 setValue<bool>(offsetof(
CurrentData, occupied), value);
648 return getValue<uint32_t>(offsetof(
CurrentData, lastOccupancyEvent));
651 setValue<uint32_t>(offsetof(
CurrentData, lastOccupancyEvent), value);
655 return getValue<time_t>(offsetof(
CurrentData, occupancyStartTime));
658 setValue<time_t>(offsetof(
CurrentData, occupancyStartTime), value);
662 return getValue<uint32_t>(offsetof(
CurrentData, totalOccupiedSeconds));
665 setValue<uint32_t>(offsetof(
CurrentData, totalOccupiedSeconds), value);
bool publishDiagnosticSafe(const char *eventName, const char *data, PublishFlags flags=PRIVATE)
Publish a state transition to the log handler.
bool publishDiagnosticSafe(const char *eventName, const char *data, PublishFlags flags=PRIVATE)
Publish a state transition to the log handler.
const char * persistentDataPathSensor
const char * persistentDataPathCurrent
const char * persistentDataPathSystem
Persistent Data Storage Structures - EEPROM/Retained Memory Management.
void set_gestureScore(uint16_t value)
time_t get_lastAlertTime() const
uint16_t get_gestureScore() const
uint32_t get_lastOccupancyEvent() const
float get_internalTempC() const
void setup()
Perform setup operations; call this from global application setup().
static currentStatusData & instance()
Gets the singleton instance of this class, allocating it if necessary.
void resetEverything()
Resets the current and hourly counts.
void set_internalTempC(float value)
void initialize()
Will reinitialize data if it is found not to be valid.
void raiseAlert(int8_t value)
Raise an alert, keeping the highest severity code when multiple occur.
uint32_t get_totalOccupiedSeconds() const
void set_faceNumber(uint16_t value)
float get_stateOfCharge() const
uint16_t get_dailyCount() const
int8_t get_alertCode() const
uint16_t get_hourlyCount() const
time_t get_occupancyStartTime() const
void set_batteryState(uint8_t value)
static const uint16_t CURRENT_DATA_VERSION
void set_gestureType(uint16_t value)
currentStatusData()
The constructor is protected because the class is a singleton.
float get_externalTempC() const
uint8_t get_batteryState() const
bool get_occupied() const
void set_externalTempC(float value)
void set_alertCode(int8_t value)
static currentStatusData * _instance
Singleton instance of this class.
time_t get_lastCountTime() const
void set_lastCountTime(time_t value)
static const uint32_t CURRENT_DATA_MAGIC
void set_lastOccupancyEvent(uint32_t value)
void set_occupied(bool value)
bool validate(size_t dataSize)
Validates values and, if valid, checks that data is in the correct range.
void loop()
Perform application loop operations; call this from global application loop().
void set_hourlyCount(uint16_t value)
uint16_t get_faceScore() const
void set_dailyCount(uint16_t value)
virtual ~currentStatusData()
The destructor is protected because the class is a singleton and cannot be deleted.
void set_faceScore(uint16_t value)
void set_totalOccupiedSeconds(uint32_t value)
uint16_t get_gestureType() const
void set_stateOfCharge(float value)
uint16_t get_faceNumber() const
For the Get functions, used to retrieve the value of the variable.
void set_lastAlertTime(time_t value)
void set_occupancyStartTime(time_t value)
static sensorConfigData & instance()
Gets the singleton instance of this class, allocating it if necessary.
uint16_t get_pollingRate() const
static sensorConfigData * _instance
Singleton instance of this class.
static const uint32_t SENSOR_DATA_MAGIC
virtual ~sensorConfigData()
The destructor is protected because the class is a singleton and cannot be deleted.
uint16_t get_threshold1() const
For the Get functions, used to retrieve the value of the variable.
void setup()
Perform setup operations; call this from global application setup().
sensorConfigData()
The constructor is protected because the class is a singleton.
bool validate(size_t dataSize)
Validates values and, if valid, checks that data is in the correct range.
void set_pollingRate(uint16_t value)
void set_threshold2(uint16_t value)
void initialize()
Will reinitialize data if it is found not to be valid.
void set_threshold1(uint16_t value)
void loop()
Perform application loop operations; call this from global application loop().
static const uint16_t SENSOR_DATA_VERSION
uint16_t get_threshold2() const
This class is a singleton; you do not create one as a global, on the stack, or with new.
time_t get_lastReport() const
uint16_t get_connectAttemptBudgetSec() const
void set_modemOffBudgetSec(uint16_t value)
bool get_solarPowerMode() const
time_t get_lastHookResponse() const
void set_lastConnectionDuration(uint16_t value)
uint8_t get_operatingMode() const
time_t get_lastDailyCleanup() const
bool set_timeZoneStr(const char *str)
uint8_t get_resetCount() const
void set_connectAttemptBudgetSec(uint16_t value)
bool get_lowPowerMode() const
void set_lastHookResponse(time_t value)
void set_cloudDisconnectBudgetSec(uint16_t value)
uint8_t get_structuresVersion() const
For the Get functions, used to retrieve the value of the variable.
uint16_t get_reportingInterval() const
uint8_t get_sensorType() const
void set_lastReport(time_t value)
void set_serialConnected(bool value)
static sysStatusData & instance()
Gets the singleton instance of this class, allocating it if necessary.
uint16_t get_lastConnectionDuration() const
void set_disconnectedMode(bool value)
void set_lowPowerReportingIntervalSec(uint16_t value)
void set_resetCount(uint8_t value)
void set_countingMode(uint8_t value)
void set_solarPowerMode(bool value)
void set_connectedReportingIntervalSec(uint16_t value)
void set_lowBatteryMode(bool value)
sysStatusData()
The constructor is protected because the class is a singleton.
void set_updatesPending(bool value)
bool get_disconnectedMode() const
void set_closeTime(uint8_t value)
static sysStatusData * _instance
Singleton instance of this class.
uint32_t get_occupancyDebounceMs() const
static const uint32_t SYS_DATA_MAGIC
void set_openTime(uint8_t value)
uint16_t get_cloudDisconnectBudgetSec() const
void loop()
Perform application loop operations; call this from global application loop().
uint16_t get_modemOffBudgetSec() const
String get_timeZoneStr() const
bool get_lowBatteryMode() const
void set_structuresVersion(uint8_t value)
void initialize()
Will reinitialize data if it is found not to be valid.
uint16_t get_connectedReportingIntervalSec() const
void set_sensorType(uint8_t value)
void set_lowPowerMode(bool value)
void setup()
Perform setup operations; call this from global application setup().
void set_reportingInterval(uint16_t value)
uint8_t get_closeTime() const
static const uint16_t SYS_DATA_VERSION
bool get_serialConnected() const
virtual ~sysStatusData()
The destructor is protected because the class is a singleton and cannot be deleted.
void set_occupancyDebounceMs(uint32_t value)
void set_verboseMode(bool value)
bool get_updatesPending() const
bool get_verboseMode() const
void set_lastDailyCleanup(time_t value)
uint8_t get_openTime() const
void set_operatingMode(uint8_t value)
time_t get_lastTimeSync() const
time_t get_lastConnection() const
void set_lastConnection(time_t value)
void set_lastTimeSync(time_t value)
bool validate(size_t dataSize)
Validates values and, if valid, checks that data is in the correct range.
uint8_t get_countingMode() const
uint16_t get_lowPowerReportingIntervalSec() const