![]() |
|
Uniot Core
|
| 0.8.1 |
Network management controller with user interface integration. More...
#include <NetworkController.h>
Public Member Functions | |
| 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. | |
| virtual | ~NetworkController () |
| Destroy the NetworkController. | |
| virtual bool | store () override |
| Store controller state to persistent storage. | |
| virtual bool | restore () override |
| Restore controller state from persistent storage. | |
| virtual void | onEventReceived (unsigned int topic, int msg) override |
| Handle network events and update controller state. | |
| virtual void | pushTo (TaskScheduler &scheduler) override |
| Push all controller tasks to the scheduler. | |
| virtual void | attach () override |
| Attach the controller and start initial operations. | |
| void | statusWaiting () |
| Set LED to waiting status pattern. | |
| void | statusBusy () |
| Set LED to busy status pattern. | |
| void | statusAlarm () |
| Set LED to alarm status pattern. | |
| void | statusIdle () |
| Set LED to idle status pattern. | |
| Button * | getButton () |
| Get access to the configuration button. | |
Public Member Functions inherited from uniot::ISchedulerConnectionKit | |
| virtual | ~ISchedulerConnectionKit () |
| Virtual destructor for proper cleanup. | |
Public Member Functions inherited from uniot::EventListener< unsigned int, int, Bytes > | |
| virtual | ~EventListener ()=default |
| Virtual destructor. | |
| virtual type_id | getTypeId () const override |
| Get the type ID of this class for RTTI. | |
| EventListener * | listenToEvent (unsigned int topic) |
| Subscribe to events of a specific topic. | |
| EventListener * | stopListeningToEvent (unsigned int topic) |
| Unsubscribe from events of a specific topic. | |
| bool | isListeningToEvent (unsigned int topic) |
| Check if this listener is subscribed to a specific topic. | |
| virtual | ~EventListener ()=default |
| Virtual destructor. | |
| virtual type_id | getTypeId () const override |
| Get the type ID of this class for RTTI. | |
| EventListener * | listenToEvent (unsigned int topic) |
| Subscribe to events of a specific topic. | |
| EventListener * | stopListeningToEvent (unsigned int topic) |
| Unsubscribe from events of a specific topic. | |
| bool | isListeningToEvent (unsigned int topic) |
| Check if this listener is subscribed to a specific topic. | |
Public Member Functions inherited from uniot::EventEmitter< unsigned int, int, Bytes > | |
| virtual | ~EventEmitter ()=default |
| Virtual destructor to ensure proper cleanup of derived classes. | |
| void | emitEvent (unsigned int topic, int msg) |
| Emits an event to all registered event buses. | |
| virtual | ~EventEmitter ()=default |
| Virtual destructor to ensure proper cleanup of derived classes. | |
| void | emitEvent (unsigned int topic, int msg) |
| Emits an event to all registered event buses. | |
Public Member Functions inherited from uniot::EventEntity< T_topic, T_msg, T_data > | |
| virtual | ~EventEntity () |
| Destructor - disconnects from all connected EventBus instances. | |
| bool | sendDataToChannel (T_topic channel, T_data data) |
| Sends data to a specific channel on all connected EventBus instances. | |
| void | receiveDataFromChannel (T_topic channel, DataChannelCallback callback) |
| Receives data from a specific channel on all connected EventBus instances. | |
Public Member Functions inherited from uniot::CBORStorage | |
| CBORStorage (const String &path) | |
| Constructs a new CBORStorage object. | |
| virtual | ~CBORStorage () |
| Virtual destructor. | |
| CBORObject & | object () |
| Get access to the underlying CBORObject. | |
| virtual bool | clean () override |
| Clean the CBOR object and remove the storage file. | |
Public Member Functions inherited from uniot::Storage | |
| Storage (const String &path) | |
| Constructs a Storage object for a specific file. | |
| virtual | ~Storage () |
| Destructor. | |
Additional Inherited Members | |
Public Types inherited from uniot::EventEntity< T_topic, T_msg, T_data > | |
| using | DataChannelCallback = std::function<void(unsigned int, bool, T_data)> |
| Callback type for handling data received from channels. | |
Static Public Member Functions inherited from uniot::Storage | |
| static void | unmount () |
| Explicitly unmounts the filesystem. | |
Protected Member Functions inherited from uniot::EventEntity< T_topic, T_msg, T_data > | |
| bool | connectUnique (EventBus< T_topic, T_msg, T_data > *eventBus) |
| Connects to an EventBus instance if not already connected. | |
Protected Member Functions inherited from uniot::Storage | |
| void | setPath (const String &path) |
| Sets the file path, ensuring it starts with "/". | |
Protected Attributes inherited from uniot::EventEntity< T_topic, T_msg, T_data > | |
| IterableQueue< EventBus< T_topic, T_msg, T_data > * > | mEventBusQueue |
| Queue of EventBus instances this entity is connected to. | |
Protected Attributes inherited from uniot::CBORStorage | |
| CBORObject | mCbor |
| The CBOR object used for data serialization/deserialization. | |
Protected Attributes inherited from uniot::Storage | |
| Bytes | mData |
| The byte array containing the data to be stored or the loaded data. | |
| String | mPath |
| The file path where data is stored. | |
Network management controller with user interface integration.
This class provides a complete network management solution that combines the NetworkScheduler with physical user interface elements. It handles button interactions for network configuration, LED status indication, automatic recovery mechanisms, and persistent state management.
The controller operates as a finite state machine that responds to both network events and user input, providing intelligent behavior patterns for device configuration and management. It implements multiple fallback mechanisms to ensure devices remain configurable even after connection failures or repeated reboots.
State management includes:
|
inline |
Construct a new NetworkController.
| network | Reference to the NetworkScheduler to control |
| pinBtn | GPIO pin for configuration button (UINT8_MAX to disable) |
| activeLevelBtn | Active logic level for button (LOW or HIGH) |
| pinLed | GPIO pin for status LED (UINT8_MAX to disable) |
| activeLevelLed | Active logic level for LED (LOW or HIGH) |
| maxRebootCount | Maximum reboots before auto-reset (default: 3) |
| rebootWindowMs | Time window for reboot counting in milliseconds (default: 10000) |
Initializes the network controller with specified hardware configuration. The controller will automatically handle GPIO configuration for enabled components and set up event listeners for network state changes.
Button behavior:
|
inlinevirtual |
Destroy the NetworkController.
Cleanly shuts down the controller by stopping event listening and clearing network references to prevent dangling pointers.
|
inlineoverridevirtual |
Attach the controller and start initial operations.
Starts the reboot counter timer, button monitoring (if configured), and sets initial status indication to busy state.
Implements uniot::ISchedulerConnectionKit.
|
inline |
Get access to the configuration button.
| Button* | Pointer to button instance, or nullptr if no button configured |
Provides access to the button instance for external control or status checking. Returns nullptr if no button was configured during construction.
|
inlineoverridevirtual |
Handle network events and update controller state.
| topic | Event topic identifier |
| msg | Event message identifier |
Processes network events and implements the controller's state machine logic for automatic network recovery, status indication, and user interaction handling. Responds to connection state changes with appropriate LED patterns and recovery actions.
Implements uniot::EventListener< unsigned int, int, Bytes >.
|
inlineoverridevirtual |
Push all controller tasks to the scheduler.
| scheduler | TaskScheduler instance to receive the tasks |
Registers all controller tasks including LED signaling, reboot counter reset, button handling, and click counter reset. Only registers button- related tasks if a button is configured.
Implements uniot::ISchedulerConnectionKit.
|
inlineoverridevirtual |
Restore controller state from persistent storage.
| bool | true if restoration was successful, false otherwise |
Loads previously saved controller state from CBOR storage, particularly the reboot counter used for automatic configuration reset detection.
Reimplemented from uniot::CBORStorage.
|
inline |
Set LED to alarm status pattern.
Configures LED to indicate error/alarm state with fast 200ms blinking pattern. Used when network connection has failed and requires attention.
|
inline |
Set LED to busy status pattern.
Configures LED to indicate busy/connecting state with 500ms blinking pattern. Used when device is attempting network connection.
|
inline |
Set LED to idle status pattern.
Configures LED to indicate successful connection with single brief flash. Used when device is successfully connected to the network.
|
inline |
Set LED to waiting status pattern.
Configures LED to indicate waiting/configuration mode with 1-second blinking pattern. Used when device is in access point mode waiting for user configuration.
|
inlineoverridevirtual |
Store controller state to persistent storage.
| bool | true if storage was successful, false otherwise |
Saves critical controller state including reboot counter to CBOR storage. This enables reboot detection and automatic configuration reset behavior.
Reimplemented from uniot::CBORStorage.