114 uint8_t pinBtn = UINT8_MAX,
115 uint8_t activeLevelBtn = LOW,
116 uint8_t pinLed = UINT8_MAX,
117 uint8_t activeLevelLed = HIGH,
118 uint8_t maxRebootCount = 3,
119 uint32_t rebootWindowMs = 10000)
122 mNetworkLastState(
events::network::Msg::SUCCESS),
125 mActiveLevelLed(activeLevelLed),
126 mMaxRebootCount(maxRebootCount),
127 mRebootWindowMs(rebootWindowMs),
129 if (pinLed != UINT8_MAX) {
130 pinMode(mPinLed, OUTPUT);
132 if (pinBtn != UINT8_MAX) {
136 if (mClickCounter > 3)
139 mpNetwork->reconnect();
142 if (!mClickCounter) {
143 mpTaskResetClickCounter->attach(5000, 1);
152 _checkAndHandleReboot();
206 int lastState = _resetNetworkLastState(msg);
222 mpNetwork->reconnect();
226 mpNetwork->reconnect();
247 scheduler.
push(
"signal_led", mpTaskSignalLed);
248 scheduler.
push(
"rst_reboot_count", mpTaskResetRebootCounter);
250 scheduler.
push(
"btn_config", mpTaskConfigBtn);
251 scheduler.
push(
"rst_click_count", mpTaskResetClickCounter);
262 mpTaskResetRebootCounter->once(mRebootWindowMs);
264 mpTaskConfigBtn->attach(100);
277 mpTaskSignalLed->attach(1000);
287 mpTaskSignalLed->attach(500);
297 mpTaskSignalLed->attach(200);
307 mpTaskSignalLed->attach(200, 1);
318 return _hasButton() ? mpConfigBtn.get() :
nullptr;
331 static bool signalLevel =
true;
332 signalLevel = (!signalLevel && t);
336 digitalWrite(mPinLed, signalLevel ? mActiveLevelLed : !mActiveLevelLed);
362 void _checkAndHandleReboot() {
365 if (mRebootCount >= mMaxRebootCount) {
366 mpTaskResetRebootCounter->detach();
382 int _resetNetworkLastState(
int newState) {
383 auto oldState = mNetworkLastState;
384 mNetworkLastState = newState;
392 inline bool _hasButton() {
393 return mpConfigBtn.get() !=
nullptr;
400 inline bool _hasLed() {
401 return mPinLed != UINT8_MAX;
404 NetworkScheduler *mpNetwork;
405 int mNetworkLastState;
407 uint8_t mClickCounter;
409 uint8_t mActiveLevelLed;
410 uint8_t mMaxRebootCount;
411 uint32_t mRebootWindowMs;
412 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:399
CBORObject & put(int key, int value)
Put an integer value at a specific integer key.
Definition CBORObject.h:170
virtual bool restore() override
Restore the CBOR object from the filesystem.
Definition CBORStorage.h:92
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:306
virtual ~NetworkController()
Destroy the NetworkController.
Definition NetworkController.h:162
NetworkController(NetworkScheduler &network, uint8_t pinBtn=UINT8_MAX, uint8_t activeLevelBtn=LOW, uint8_t pinLed=UINT8_MAX, uint8_t activeLevelLed=HIGH, uint8_t maxRebootCount=3, uint32_t rebootWindowMs=10000)
Construct a new NetworkController.
Definition NetworkController.h:113
virtual void onEventReceived(unsigned int topic, int msg) override
Handle network events and update controller state.
Definition NetworkController.h:204
void statusAlarm()
Set LED to alarm status pattern.
Definition NetworkController.h:296
void statusWaiting()
Set LED to waiting status pattern.
Definition NetworkController.h:276
void statusBusy()
Set LED to busy status pattern.
Definition NetworkController.h:286
virtual bool restore() override
Restore controller state from persistent storage.
Definition NetworkController.h:186
Button * getButton()
Get access to the configuration button.
Definition NetworkController.h:317
virtual void attach() override
Attach the controller and start initial operations.
Definition NetworkController.h:261
virtual void pushTo(TaskScheduler &scheduler) override
Push all controller tasks to the scheduler.
Definition NetworkController.h:246
virtual bool store() override
Store controller state to persistent storage.
Definition NetworkController.h:174
Complete WiFi network management and configuration scheduler.
Definition NetworkScheduler.h:100
Definition TaskScheduler.h:67
Definition TaskScheduler.h:164
std::unique_ptr< T > UniquePointer
Type alias for std::unique_ptr with cleaner syntax.
Definition Common.h:152
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:179
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:293
SharedPointer< SchedulerTask > TaskPtr
Shared pointer type for scheduler tasks.
Definition TaskScheduler.h:171
static TaskPtr make(SchedulerTask::SchedulerTaskCallback callback)
Static factory method to create a task with a callback.
Definition TaskScheduler.h:193
TaskScheduler & push(const char *name, TaskPtr task)
Add a named task to the scheduler.
Definition TaskScheduler.h:214
@ 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.