NetworkController
The NetworkController class manages network configurations, user interactions through buttons, and status indicators using LEDs. It integrates with the NetworkScheduler to handle connection events, manage reboot logic based on connection stability, and ensure that the device maintains a reliable network connection. The controller also handles user-initiated actions such as reconnecting to the network or resetting network configurations.
Constructor and Destructor:
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)Initializes theNetworkController, setting up the LED and button if specified. It initializes tasks for LED signaling, button configuration, and reboot count management. The constructor also restores any saved reboot counts and starts monitoring for reboot conditions. Additionally, it listens to network connection events to update the system status accordingly.network(NetworkScheduler &): Reference to theNetworkSchedulerinstance for managing network tasks.pinBtn(uint8_t): GPIO pin number for the configuration button. Defaults toUINT8_MAXif no button is used.activeLevelBtn(uint8_t): Active logic level for the button (HIGHorLOW). Defaults toLOW.pinLed(uint8_t): GPIO pin number for the status LED. Defaults toUINT8_MAXif no LED is used.activeLevelLed(uint8_t): Active logic level for the LED (HIGHorLOW). Defaults toHIGH.maxRebootCount(uint8_t): Maximum number of reboots allowed within the reboot window. Defaults to3.rebootWindowMs(uint32_t): Time window in milliseconds to monitor reboot counts. Defaults to10000ms.
virtual ~NetworkController()Destructor that ensures proper cleanup by stopping event listening and releasing network scheduler references.
Methods:
bool store() overrideStores the current reboot count to persistent storage.bool restore() overrideRestores the reboot count from persistent storage.void onEventReceived(unsigned int topic, int msg) overrideHandles network connection events such asACCESS_POINT,SUCCESS,CONNECTING,DISCONNECTED, andFAILED. Based on the event, it updates the LED status and manages reconnection attempts or resets the network configuration as needed.void pushTo(TaskScheduler &scheduler) overridePushes the controller's tasks to the providedTaskScheduler.void attach() overrideAttaches the controller's tasks to the scheduler and initializes the system status.void statusWaiting()Updates the LED to indicate a waiting status.void statusBusy()Updates the LED to indicate a busy status.void statusAlarm()Updates the LED to indicate an alarm or error status.void statusIdle()Updates the LED to indicate an idle status.Button* getButton()Retrieves the configuration button instance if available.
Private Members:
NetworkScheduler *mpNetworkPointer to the associatedNetworkSchedulerinstance responsible for managing network tasks.int mNetworkLastStateStores the last known network state to track changes and handle reconnections appropriately.uint8_t mClickCounterCounts the number of button clicks within a specific time window to handle multi-click actions.uint8_t mPinLedGPIO pin number assigned to the status LED. If set toUINT8_MAX, no LED is used.uint8_t mActiveLevelLedActive logic level for the LED (HIGHorLOW), determining how the LED is controlled.uint8_t mMaxRebootCountMaximum number of allowed reboots within the reboot window before triggering a network forget/reset.uint32_t mRebootWindowMsTime window in milliseconds to monitor the number of reboots.uint8_t mRebootCountCurrent count of reboots that have occurred within the specified reboot window.UniquePointer<Button> mpConfigBtnUnique pointer to the configurationButtoninstance. Manages button interactions for network configuration.TaskScheduler::TaskPtr mpTaskSignalLedTask pointer for managing LED signaling based on network status.TaskScheduler::TaskPtr mpTaskConfigBtnTask pointer for handling button configuration actions.TaskScheduler::TaskPtr mpTaskResetClickCounterTask pointer for resetting the button click counter after a specified duration.TaskScheduler::TaskPtr mpTaskResetRebootCounterTask pointer for resetting the reboot count after the reboot window duration.
Type Definitions:
enum Topic { NETWORK_LED = FOURCC(nled) }Enumeration defining event topics related to network LED signaling.
Last updated