Generalized-Core-Counter 3.20
Particle-based generalized core counter firmware
Loading...
Searching...
No Matches
Generalized-Core-Counter.cpp File Reference
#include "Particle.h"
#include "Config.h"
#include "AB1805_RK.h"
#include "Cloud.h"
#include "LocalTimeRK.h"
#include "MyPersistentData.h"
#include "Particle_Functions.h"
#include "PublishQueuePosixRK.h"
#include "SensorManager.h"
#include "device_pinout.h"
#include "ISensor.h"
#include "SensorFactory.h"
#include "SensorDefinitions.h"
#include "Version.h"
#include "StateMachine.h"
#include "StateHandlers.h"
#include "ProjectConfig.h"

Go to the source code of this file.

Functions

AB1805 ab1805 (Wire)
Timer countSignalTimer (1000, countSignalTimerISR, true)
void countSignalTimerISR ()
void dailyCleanup ()
 Cleanup function that is run at the beginning of the day.
bool isWithinOpenHours ()
void loop ()
void outOfMemoryHandler (system_event_t event, int param)
 PRODUCT_VERSION (3)
void publishData ()
 Publish sensor data to Ubidots webhook and device-data ledger.
bool publishDiagnosticSafe (const char *eventName, const char *data, PublishFlags flags)
 Publish a state transition to the log handler.
void publishStartupStatus ()
 Enqueue a one-time startup status event summarizing firmware version, reset reason, and any active alert.
void publishStateTransition ()
int secondsUntilNextOpen ()
void sensorISR ()
void setup ()
void UbidotsHandler (const char *event, const char *data)
void userSwitchISR ()

Variables

SystemSleepConfiguration config
unsigned long connectedStartMs = 0
LocalTimeConvert conv
bool dataInFlight
const char * FIRMWARE_RELEASE_NOTES
const char * FIRMWARE_VERSION
bool firstConnectionObserved = false
bool firstConnectionQueueDrainedLogged = false
bool hibernateDisabledForSession = false
const unsigned long maxConnectAttemptMs = 5UL * 60UL * 1000UL
State oldState = INITIALIZATION_STATE
int outOfMemory = -1
const unsigned long resetWait = 30000
volatile bool sensorDetect = false
State state = INITIALIZATION_STATE
char stateNames [7][16]
bool suppressAlert40ThisSession = false
volatile bool userSwitchDetected = false
const int wakeBoundary = 1 * 3600

Function Documentation

◆ ab1805()

AB1805 ab1805 ( Wire )

◆ countSignalTimer()

Timer countSignalTimer ( 1000 ,
countSignalTimerISR ,
true  )

References countSignalTimerISR().

◆ countSignalTimerISR()

void countSignalTimerISR ( )

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

References BLUE_LED.

Referenced by countSignalTimer().

◆ 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 ( )

◆ loop()

◆ outOfMemoryHandler()

void outOfMemoryHandler ( system_event_t event,
int param )

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

References outOfMemory.

Referenced by setup().

◆ PRODUCT_VERSION()

PRODUCT_VERSION ( 3 )

◆ 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().

◆ publishDiagnosticSafe()

bool publishDiagnosticSafe ( const char * eventName,
const char * data,
PublishFlags flags )

Publish a state transition to the log handler.

Safely publish diagnostic message through queue with depth guard.

Routes low-priority diagnostic messages through PublishQueuePosix only when queue depth is below threshold, preventing displacement of critical telemetry data during tight loops or error conditions.

Parameters
eventNameThe event name for the publish.
dataThe event data payload.
flagsParticle publish flags (e.g., PRIVATE).
Returns
true if message was queued or published, false if queue was too full.

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

Referenced by dailyCleanup(), handleConnectingState(), sysStatusData::initialize(), and UbidotsHandler().

◆ publishStartupStatus()

void publishStartupStatus ( )

Enqueue a one-time startup status event summarizing firmware version, reset reason, and any active alert.

This uses PublishQueuePosix so the event will be delivered after the next successful cloud connection, even if called before the radio is brought up.

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

References current, and FIRMWARE_VERSION.

Referenced by setup().

◆ publishStateTransition()

◆ secondsUntilNextOpen()

int secondsUntilNextOpen ( )

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

References isWithinOpenHours(), and sysStatus.

Referenced by handleSleepingState().

◆ sensorISR()

void sensorISR ( )

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

References sensorDetect, and sysStatus.

◆ setup()

◆ UbidotsHandler()

void UbidotsHandler ( const char * event,
const char * data )

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

References current, dataInFlight, publishDiagnosticSafe(), and sysStatus.

Referenced by setup().

◆ userSwitchISR()

void userSwitchISR ( )

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

References userSwitchDetected.

Referenced by setup().

Variable Documentation

◆ config

SystemSleepConfiguration config

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

Referenced by handleSleepingState().

◆ connectedStartMs

unsigned long connectedStartMs = 0

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

Referenced by handleConnectingState(), and handleIdleState().

◆ conv

LocalTimeConvert conv

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

Referenced by handleSleepingState(), and setup().

◆ dataInFlight

bool dataInFlight
Initial value:
=
false

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

Referenced by UbidotsHandler().

◆ FIRMWARE_RELEASE_NOTES

const char* FIRMWARE_RELEASE_NOTES
extern

Definition at line 7 of file Version.cpp.

Referenced by PRODUCT_VERSION(), and setup().

◆ FIRMWARE_VERSION

const char* FIRMWARE_VERSION
extern

Definition at line 6 of file Version.cpp.

◆ firstConnectionObserved

bool firstConnectionObserved = false

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

Referenced by handleConnectingState(), and handleIdleState().

◆ firstConnectionQueueDrainedLogged

bool firstConnectionQueueDrainedLogged = false

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

Referenced by handleConnectingState(), and handleIdleState().

◆ hibernateDisabledForSession

bool hibernateDisabledForSession = false

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

Referenced by handleSleepingState().

◆ maxConnectAttemptMs

const unsigned long maxConnectAttemptMs = 5UL * 60UL * 1000UL

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

Referenced by handleConnectingState().

◆ oldState

◆ outOfMemory

int outOfMemory = -1

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

Referenced by loop(), and outOfMemoryHandler().

◆ resetWait

const unsigned long resetWait = 30000

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

Referenced by handleErrorState().

◆ sensorDetect

volatile bool sensorDetect = false

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

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

◆ state

◆ stateNames

char stateNames[7][16]
Initial value:
= {"Initialize", "Error", "Idle",
"Sleeping", "Connecting", "Reporting",
"FirmwareUpdate"}

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

Referenced by publishStateTransition().

◆ suppressAlert40ThisSession

bool suppressAlert40ThisSession = false

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

Referenced by handleReportingState(), and setup().

◆ userSwitchDetected

volatile bool userSwitchDetected = false

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

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

◆ wakeBoundary

const int wakeBoundary = 1 * 3600

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

Referenced by handleSleepingState().