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

Go to the source code of this file.

Functions

void handleConnectingState ()
 CONNECTING_STATE: establish cloud connection using a phased, non-blocking state machine.
void handleCountingMode ()
 Handle sensor events in COUNTING mode.
void handleErrorState ()
void handleFirmwareUpdateState ()
void handleIdleState ()
void handleOccupancyMode ()
 Handle sensor events in OCCUPANCY mode.
void handleReportingState ()
void handleSleepingState ()
 SLEEPING_STATE: deep sleep between reporting intervals.
void updateOccupancyState ()
 Update occupancy state based on debounce timeout.

Function Documentation

◆ handleConnectingState()

void handleConnectingState ( )

CONNECTING_STATE: establish cloud connection using a phased, non-blocking state machine.

Uses an internal ConnectPhase enum to break connection into small steps that each complete within a single loop() iteration:

  • CONN_PHASE_START: log signal strength and request Particle.connect().
  • CONN_PHASE_WAIT_CLOUD: poll Particle.connected() up to connectAttemptBudgetSec (from sysStatus / Ledger), raising alert 31 on timeout.
  • CONN_PHASE_LOAD_CONFIG: load configuration from cloud ledgers and raise alert 41 on failure.
  • CONN_PHASE_PUBLISH_LEDGER: optionally publish device-data to the ledger (skipped when entered from REPORTING_STATE to avoid clobbering hourlyCount), log queue depth, and transition to FIRMWARE_UPDATE_STATE when updates are pending or back to IDLE_STATE. Connection duration is tracked in sysStatus so budgets and field behaviour can be analysed from device-status data.

Definition at line 68 of file State_Connect.cpp.

References connectedStartMs, current, FIRMWARE_UPDATE_STATE, firstConnectionObserved, firstConnectionQueueDrainedLogged, IDLE_STATE, Cloud::instance(), Cloud::loadConfigurationFromCloud(), maxConnectAttemptMs, measure, oldState, publishDiagnosticSafe(), publishStateTransition(), REPORTING_STATE, requestFullDisconnectAndRadioOff(), SLEEPING_STATE, state, and sysStatus.

Referenced by loop().

◆ handleCountingMode()

void handleCountingMode ( )

Handle sensor events in COUNTING mode.

In counting mode, each sensor detection increments counters. Counts are tracked hourly and daily. Used for: traffic counting, people counting, event tracking

Definition at line 24 of file State_Modes.cpp.

References BLUE_LED, countSignalTimer, current, SensorManager::instance(), and loop().

Referenced by loop().

◆ handleErrorState()

void handleErrorState ( )

◆ handleFirmwareUpdateState()

void handleFirmwareUpdateState ( )

◆ handleIdleState()

◆ handleOccupancyMode()

void handleOccupancyMode ( )

Handle sensor events in OCCUPANCY mode.

In occupancy mode, first detection marks space as "occupied". Space remains occupied until debounce timeout expires without new detections. Tracks total occupied time for reporting. Used for: room occupancy, parking space detection, resource availability

Definition at line 58 of file State_Modes.cpp.

References BLUE_LED, current, SensorManager::instance(), loop(), sysStatus, and updateOccupancyState().

Referenced by loop().

◆ handleReportingState()

void handleReportingState ( )

◆ handleSleepingState()

◆ updateOccupancyState()

void updateOccupancyState ( )

Update occupancy state based on debounce timeout.

If space is occupied and debounce timeout has expired without new sensor events, mark space as unoccupied. Accumulates total occupied time for daily reporting.

Definition at line 91 of file State_Modes.cpp.

References BLUE_LED, current, and sysStatus.

Referenced by handleOccupancyMode().