|
Generalized-Core-Counter 3.20
Particle-based generalized core counter firmware
|
#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 |
| AB1805 ab1805 | ( | Wire | ) |
| Timer countSignalTimer | ( | 1000 | , |
| countSignalTimerISR | , | ||
| true | ) |
References countSignalTimerISR().
| void countSignalTimerISR | ( | ) |
Definition at line 684 of file Generalized-Core-Counter.cpp.
References BLUE_LED.
Referenced by countSignalTimer().
| 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().
| bool isWithinOpenHours | ( | ) |
Definition at line 428 of file Generalized-Core-Counter.cpp.
References sysStatus.
Referenced by handleIdleState(), handleSleepingState(), secondsUntilNextOpen(), and setup().
| void loop | ( | ) |
Definition at line 346 of file Generalized-Core-Counter.cpp.
References ab1805, CONNECTING_STATE, COUNTING, current, ERROR_STATE, FIRMWARE_UPDATE_STATE, handleConnectingState(), handleCountingMode(), handleErrorState(), handleFirmwareUpdateState(), handleIdleState(), handleOccupancyMode(), handleReportingState(), handleSleepingState(), IDLE_STATE, Cloud::instance(), Cloud::loop(), OCCUPANCY, outOfMemory, REPORTING_STATE, sensorConfig, SLEEPING_STATE, state, sysStatus, and userSwitchDetected.
Referenced by handleCountingMode(), and handleOccupancyMode().
| 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 | ( | 3 | ) |
References FIRMWARE_RELEASE_NOTES, and FIRMWARE_VERSION.
| 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().
| 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.
| eventName | The event name for the publish. |
| data | The event data payload. |
| flags | Particle publish flags (e.g., PRIVATE). |
Definition at line 633 of file Generalized-Core-Counter.cpp.
Referenced by dailyCleanup(), handleConnectingState(), sysStatusData::initialize(), and UbidotsHandler().
| 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().
| void publishStateTransition | ( | ) |
Definition at line 651 of file Generalized-Core-Counter.cpp.
References IDLE_STATE, oldState, state, and stateNames.
Referenced by handleConnectingState(), handleErrorState(), handleFirmwareUpdateState(), handleIdleState(), handleReportingState(), and handleSleepingState().
| int secondsUntilNextOpen | ( | ) |
Definition at line 454 of file Generalized-Core-Counter.cpp.
References isWithinOpenHours(), and sysStatus.
Referenced by handleSleepingState().
| void sensorISR | ( | ) |
Definition at line 675 of file Generalized-Core-Counter.cpp.
References sensorDetect, and sysStatus.
| void setup | ( | ) |
Definition at line 125 of file Generalized-Core-Counter.cpp.
References ab1805, BLUE_LED, BUTTON_PIN, CONNECTED, CONNECTING_STATE, conv, current, FIRMWARE_RELEASE_NOTES, FIRMWARE_VERSION, SensorDefinitions::getDefinition(), IDLE_STATE, INITIALIZATION_STATE, SensorManager::initializeFromConfig(), initializePinModes(), Cloud::instance(), Particle_Functions::instance(), SensorManager::instance(), isWithinOpenHours(), SensorDefinition::ledDefaultOn, ledPower, SensorManager::onEnterSleep(), outOfMemoryHandler(), publishStartupStatus(), sensorConfig, Cloud::setup(), Particle_Functions::setup(), state, suppressAlert40ThisSession, sysStatus, UbidotsHandler(), and userSwitchISR().
| 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().
| void userSwitchISR | ( | ) |
Definition at line 673 of file Generalized-Core-Counter.cpp.
References userSwitchDetected.
Referenced by setup().
| SystemSleepConfiguration config |
Definition at line 87 of file Generalized-Core-Counter.cpp.
Referenced by handleSleepingState().
| unsigned long connectedStartMs = 0 |
Definition at line 115 of file Generalized-Core-Counter.cpp.
Referenced by handleConnectingState(), and handleIdleState().
| LocalTimeConvert conv |
Definition at line 89 of file Generalized-Core-Counter.cpp.
Referenced by handleSleepingState(), and setup().
| bool dataInFlight |
Definition at line 105 of file Generalized-Core-Counter.cpp.
Referenced by UbidotsHandler().
|
extern |
Definition at line 7 of file Version.cpp.
Referenced by PRODUCT_VERSION(), and setup().
|
extern |
Definition at line 6 of file Version.cpp.
| bool firstConnectionObserved = false |
Definition at line 109 of file Generalized-Core-Counter.cpp.
Referenced by handleConnectingState(), and handleIdleState().
| bool firstConnectionQueueDrainedLogged = false |
Definition at line 110 of file Generalized-Core-Counter.cpp.
Referenced by handleConnectingState(), and handleIdleState().
| bool hibernateDisabledForSession = false |
Definition at line 112 of file Generalized-Core-Counter.cpp.
Referenced by handleSleepingState().
| const unsigned long maxConnectAttemptMs = 5UL * 60UL * 1000UL |
Definition at line 123 of file Generalized-Core-Counter.cpp.
Referenced by handleConnectingState().
| State oldState = INITIALIZATION_STATE |
Definition at line 100 of file Generalized-Core-Counter.cpp.
Referenced by handleConnectingState(), handleErrorState(), handleFirmwareUpdateState(), handleIdleState(), handleReportingState(), handleSleepingState(), and publishStateTransition().
| int outOfMemory = -1 |
Definition at line 93 of file Generalized-Core-Counter.cpp.
Referenced by loop(), and outOfMemoryHandler().
| const unsigned long resetWait = 30000 |
Definition at line 122 of file Generalized-Core-Counter.cpp.
Referenced by handleErrorState().
| volatile bool sensorDetect = false |
Definition at line 104 of file Generalized-Core-Counter.cpp.
Referenced by handleIdleState(), handleSleepingState(), and sensorISR().
| State state = INITIALIZATION_STATE |
Definition at line 99 of file Generalized-Core-Counter.cpp.
Referenced by handleConnectingState(), handleErrorState(), handleFirmwareUpdateState(), handleIdleState(), handleReportingState(), handleSleepingState(), loop(), publishStateTransition(), and setup().
| char stateNames[7][16] |
Definition at line 96 of file Generalized-Core-Counter.cpp.
Referenced by publishStateTransition().
| bool suppressAlert40ThisSession = false |
Definition at line 118 of file Generalized-Core-Counter.cpp.
Referenced by handleReportingState(), and setup().
| volatile bool userSwitchDetected = false |
Definition at line 103 of file Generalized-Core-Counter.cpp.
Referenced by handleSleepingState(), loop(), and userSwitchISR().
| const int wakeBoundary = 1 * 3600 |
Definition at line 121 of file Generalized-Core-Counter.cpp.
Referenced by handleSleepingState().