120 uint8_t pinBtn = UINT8_MAX,
121 uint8_t activeLevelBtn = LOW,
122 uint8_t pinLed = UINT8_MAX,
123 uint8_t activeLevelLed = HIGH,
128 mNetworkLastState(
events::network::Msg::SUCCESS),
131 mActiveLevelLed(activeLevelLed),
132 mMaxRebootCount(maxRebootCount),
133 mRebootWindowMs(rebootWindowMs),
135 if (pinLed != UINT8_MAX) {
136 pinMode(mPinLed, OUTPUT);
138 if (pinBtn != UINT8_MAX) {
142 if (mClickCounter > 3)
145 mpNetwork->reconnect();
148 if (!mClickCounter) {
149 mpTaskResetClickCounter->attach(5000, 1);
158 _checkAndHandleReboot();
212 int lastState = _resetNetworkLastState(msg);
228 mpNetwork->reconnect();
232 mpNetwork->reconnect();
253 scheduler.
push(
"signal_led", mpTaskSignalLed);
254 scheduler.
push(
"rst_reboot_count", mpTaskResetRebootCounter);
256 scheduler.
push(
"btn_config", mpTaskConfigBtn);
257 scheduler.
push(
"rst_click_count", mpTaskResetClickCounter);
268 if (_hasRebootReset()) {
269 mpTaskResetRebootCounter->once(mRebootWindowMs);
272 mpTaskConfigBtn->attach(100);
285 mpTaskSignalLed->attach(1000);
295 mpTaskSignalLed->attach(500);
305 mpTaskSignalLed->attach(200);
315 mpTaskSignalLed->attach(200, 1);
326 return _hasButton() ? mpConfigBtn.get() :
nullptr;
339 static bool signalLevel =
true;
340 signalLevel = (!signalLevel && t);
344 digitalWrite(mPinLed, signalLevel ? mActiveLevelLed : !mActiveLevelLed);
370 void _checkAndHandleReboot() {
371 if (!_hasRebootReset()) {
376 if (mRebootCount >= mMaxRebootCount) {
377 mpTaskResetRebootCounter->detach();
393 int _resetNetworkLastState(
int newState) {
394 auto oldState = mNetworkLastState;
395 mNetworkLastState = newState;
403 inline bool _hasButton() {
404 return mpConfigBtn.get() !=
nullptr;
411 inline bool _hasLed() {
412 return mPinLed != UINT8_MAX;
422 inline bool _hasRebootReset() {
423 return mMaxRebootCount != UINT8_MAX;
426 NetworkScheduler *mpNetwork;
427 int mNetworkLastState;
429 uint8_t mClickCounter;
431 uint8_t mActiveLevelLed;
432 uint8_t mMaxRebootCount;
433 uint32_t mRebootWindowMs;
434 uint8_t mRebootCount;
Network event definitions for the Uniot event system.
Complete WiFi network management and configuration system.
long getInt(int key) const
Get an integer value at a specific integer key.
Definition CBORObject.h:409
CBORObject & put(int key, int value)
Put an integer value at a specific integer key.
Definition CBORObject.h:180
virtual bool restore() override
Restore the CBOR object from the filesystem.
Definition CBORStorage.h:102
virtual bool store() override
Store the CBOR object to the filesystem.
Definition CBORStorage.h:74
CBORStorage(const String &path)
Constructs a new CBORStorage object.
Definition CBORStorage.h:46
CBORObject & object()
Get access to the underlying CBORObject.
Definition CBORStorage.h:60
void emitEvent(unsigned int topic, int msg)
EventListener * stopListeningToEvent(unsigned int topic)
EventListener * listenToEvent(unsigned int topic)
Interface for connecting components to the TaskScheduler.
Definition ISchedulerConnectionKit.h:35
void statusIdle()
Set LED to idle status pattern.
Definition NetworkController.h:314
virtual ~NetworkController()
Destroy the NetworkController.
Definition NetworkController.h:168
virtual void onEventReceived(unsigned int topic, int msg) override
Handle network events and update controller state.
Definition NetworkController.h:210
void statusAlarm()
Set LED to alarm status pattern.
Definition NetworkController.h:304
void statusWaiting()
Set LED to waiting status pattern.
Definition NetworkController.h:284
NetworkController(NetworkScheduler &network, uint8_t pinBtn=UINT8_MAX, uint8_t activeLevelBtn=LOW, uint8_t pinLed=UINT8_MAX, uint8_t activeLevelLed=HIGH, uint8_t maxRebootCount=UNIOT_WIFI_REBOOT_RESET_COUNT, uint32_t rebootWindowMs=UNIOT_WIFI_REBOOT_WINDOW_MS)
Construct a new NetworkController.
Definition NetworkController.h:119
void statusBusy()
Set LED to busy status pattern.
Definition NetworkController.h:294
virtual bool restore() override
Restore controller state from persistent storage.
Definition NetworkController.h:192
Button * getButton()
Get access to the configuration button.
Definition NetworkController.h:325
virtual void attach() override
Attach the controller and start initial operations.
Definition NetworkController.h:267
virtual void pushTo(TaskScheduler &scheduler) override
Push all controller tasks to the scheduler.
Definition NetworkController.h:252
virtual bool store() override
Store controller state to persistent storage.
Definition NetworkController.h:180
Complete WiFi network management and configuration scheduler.
Definition NetworkScheduler.h:100
Definition TaskScheduler.h:67
Definition TaskScheduler.h:183
std::unique_ptr< T > UniquePointer
Type alias for std::unique_ptr with cleaner syntax.
Definition Common.h:305
#define UNIOT_WIFI_REBOOT_WINDOW_MS
How long after boot a reboot still counts towards the reset, in ms.
Definition Common.h:115
auto MakeUnique(Args &&...args) -> decltype(std::make_unique< T >(std::forward< Args >(args)...))
Creates a unique pointer instance, alias for std::make_unique.
Definition Common.h:332
#define UNIOT_WIFI_REBOOT_RESET_COUNT
Consecutive reboots that reset the stored network configuration.
Definition Common.h:104
EventListener< unsigned int, int, Bytes > CoreEventListener
Type alias for the common EventListener configuration used in the core system.
Definition EventListener.h:100
#define UNIOT_LOG_DEBUG(...)
Log an DEBUG level message Used for general information about system operation. Only compiled if UNIO...
Definition Logger.h:340
SharedPointer< SchedulerTask > TaskPtr
Shared pointer type for scheduler tasks.
Definition TaskScheduler.h:190
static TaskPtr make(SchedulerTask::SchedulerTaskCallback callback)
Static factory method to create a task with a callback.
Definition TaskScheduler.h:212
TaskScheduler & push(const char *name, TaskPtr task)
Add a named task to the scheduler.
Definition TaskScheduler.h:233
@ SUCCESS
Network operation completed successfully.
Definition NetworkEvents.h:86
@ ACCESS_POINT
Device is operating in access point mode.
Definition NetworkEvents.h:90
@ AVAILABLE
Configured network is available for connection.
Definition NetworkEvents.h:91
@ DISCONNECTED
Network connection has been lost or terminated.
Definition NetworkEvents.h:89
@ FAILED
Network operation failed (connection, scan, etc.)
Definition NetworkEvents.h:85
@ CONNECTING
Currently attempting to connect to network.
Definition NetworkEvents.h:87
@ WIFI_STATUS_LED
LED status indicators for network state.
Definition NetworkEvents.h:75
@ CONNECTION
WiFi connection state changes and operations.
Definition NetworkEvents.h:74
Definition DateEvents.h:51
Contains all classes and functions related to the Uniot Core.