Generalized-Core-Counter 3.20
Particle-based generalized core counter firmware
Loading...
Searching...
No Matches
StateMachine.h File Reference
#include "Particle.h"
#include "AB1805_RK.h"

Go to the source code of this file.

Enumerations

enum  State {
  INITIALIZATION_STATE , ERROR_STATE , IDLE_STATE , SLEEPING_STATE ,
  CONNECTING_STATE , REPORTING_STATE , FIRMWARE_UPDATE_STATE
}

Functions

void dailyCleanup ()
 Cleanup function that is run at the beginning of the day.
bool isWithinOpenHours ()
void publishData ()
 Publish sensor data to Ubidots webhook and device-data ledger.
void publishStateTransition ()
int secondsUntilNextOpen ()

Variables

AB1805 ab1805
SystemSleepConfiguration config
unsigned long connectedStartMs
Timer countSignalTimer
bool dataInFlight
bool firstConnectionObserved
bool firstConnectionQueueDrainedLogged
bool hibernateDisabledForSession
bool lastLowPowerMode
const unsigned long maxConnectAttemptMs
const unsigned long maxOnlineWorkMs
State oldState
int outOfMemory
const unsigned long resetWait
volatile bool sensorDetect
State state
char stateNames [7][16]
const unsigned long stayAwakeLong
volatile bool userSwitchDetected
const int wakeBoundary

Enumeration Type Documentation

◆ State

enum State
Enumerator
INITIALIZATION_STATE 
ERROR_STATE 
IDLE_STATE 
SLEEPING_STATE 
CONNECTING_STATE 
REPORTING_STATE 
FIRMWARE_UPDATE_STATE 

Definition at line 7 of file StateMachine.h.

Function Documentation

◆ dailyCleanup()

void dailyCleanup ( )

Cleanup function that is run at the beginning of the day.

May or may not be in connected state. Syncs time with remote service and sets low power mode. Called from Reporting State ONLY. Cleans house at the beginning of a new day.

Definition at line 693 of file Generalized-Core-Counter.cpp.

References current, publishDiagnosticSafe(), and sysStatus.

Referenced by handleReportingState().

◆ isWithinOpenHours()

bool isWithinOpenHours ( )

◆ publishData()

void publishData ( )

Publish sensor data to Ubidots webhook and device-data ledger.

1) Builds a compact JSON payload expected by the Ubidots webhook template and enqueues it via PublishQueuePosix to the "Ubidots-Parking-Hook-v1" event. 2) Updates the Particle Ledger "device-data" with a richer JSON snapshot via Cloud::publishDataToLedger() for Console visibility.

Definition at line 509 of file Generalized-Core-Counter.cpp.

References batteryContext, current, Cloud::instance(), and sysStatus.

Referenced by handleReportingState().

◆ publishStateTransition()

◆ secondsUntilNextOpen()

int secondsUntilNextOpen ( )

Definition at line 454 of file Generalized-Core-Counter.cpp.

References isWithinOpenHours(), and sysStatus.

Referenced by handleSleepingState().

Variable Documentation

◆ ab1805

AB1805 ab1805
extern

◆ config

SystemSleepConfiguration config
extern

Definition at line 87 of file Generalized-Core-Counter.cpp.

Referenced by handleSleepingState().

◆ connectedStartMs

unsigned long connectedStartMs
extern

Definition at line 115 of file Generalized-Core-Counter.cpp.

Referenced by handleConnectingState(), and handleIdleState().

◆ countSignalTimer

Timer countSignalTimer
extern

◆ dataInFlight

bool dataInFlight
extern

Definition at line 105 of file Generalized-Core-Counter.cpp.

Referenced by UbidotsHandler().

◆ firstConnectionObserved

bool firstConnectionObserved
extern

Definition at line 109 of file Generalized-Core-Counter.cpp.

Referenced by handleConnectingState(), and handleIdleState().

◆ firstConnectionQueueDrainedLogged

bool firstConnectionQueueDrainedLogged
extern

Definition at line 110 of file Generalized-Core-Counter.cpp.

Referenced by handleConnectingState(), and handleIdleState().

◆ hibernateDisabledForSession

bool hibernateDisabledForSession
extern

Definition at line 112 of file Generalized-Core-Counter.cpp.

Referenced by handleSleepingState().

◆ lastLowPowerMode

bool lastLowPowerMode
extern

◆ maxConnectAttemptMs

const unsigned long maxConnectAttemptMs
extern

Definition at line 123 of file Generalized-Core-Counter.cpp.

Referenced by handleConnectingState().

◆ maxOnlineWorkMs

const unsigned long maxOnlineWorkMs
extern

◆ oldState

◆ outOfMemory

int outOfMemory
extern

Definition at line 93 of file Generalized-Core-Counter.cpp.

Referenced by loop(), and outOfMemoryHandler().

◆ resetWait

const unsigned long resetWait
extern

Definition at line 122 of file Generalized-Core-Counter.cpp.

Referenced by handleErrorState().

◆ sensorDetect

volatile bool sensorDetect
extern

Definition at line 104 of file Generalized-Core-Counter.cpp.

Referenced by handleIdleState(), handleSleepingState(), and sensorISR().

◆ state

◆ stateNames

char stateNames[7][16]
extern

Definition at line 96 of file Generalized-Core-Counter.cpp.

Referenced by publishStateTransition().

◆ stayAwakeLong

const unsigned long stayAwakeLong
extern

◆ userSwitchDetected

volatile bool userSwitchDetected
extern

Definition at line 103 of file Generalized-Core-Counter.cpp.

Referenced by handleSleepingState(), loop(), and userSwitchISR().

◆ wakeBoundary

const int wakeBoundary
extern

Definition at line 121 of file Generalized-Core-Counter.cpp.

Referenced by handleSleepingState().