Uniot Core
0.8.1
Loading...
Searching...
No Matches
uniot::NetworkController Class Reference

Network management controller with user interface integration. More...

#include <NetworkController.h>

Inheritance diagram for uniot::NetworkController:
[legend]

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.
 
ButtongetButton ()
 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.
 
EventListenerlistenToEvent (unsigned int topic)
 Subscribe to events of a specific topic.
 
EventListenerstopListeningToEvent (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.
 
EventListenerlistenToEvent (unsigned int topic)
 Subscribe to events of a specific topic.
 
EventListenerstopListeningToEvent (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.
 
CBORObjectobject ()
 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.
 

Detailed Description

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:

  • Connection status tracking and LED indication
  • Button click counting for advanced configuration modes
  • Reboot counting for automatic configuration reset
  • Persistent storage of critical state information

Constructor & Destructor Documentation

◆ NetworkController()

uniot::NetworkController::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 )
inline

Construct a new NetworkController.

Parameters
networkReference to the NetworkScheduler to control
pinBtnGPIO pin for configuration button (UINT8_MAX to disable)
activeLevelBtnActive logic level for button (LOW or HIGH)
pinLedGPIO pin for status LED (UINT8_MAX to disable)
activeLevelLedActive logic level for LED (LOW or HIGH)
maxRebootCountMaximum reboots before auto-reset (default: 3)
rebootWindowMsTime 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:

  • Single click: Increment click counter
  • Long press: Reconnect (normal) or reset configuration (if >3 clicks)
  • Multiple rapid clicks enable advanced configuration modes

◆ ~NetworkController()

virtual uniot::NetworkController::~NetworkController ( )
inlinevirtual

Destroy the NetworkController.

Cleanly shuts down the controller by stopping event listening and clearing network references to prevent dangling pointers.

Member Function Documentation

◆ attach()

virtual void uniot::NetworkController::attach ( )
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.

◆ getButton()

Button * uniot::NetworkController::getButton ( )
inline

Get access to the configuration button.

Return values
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.

◆ onEventReceived()

virtual void uniot::NetworkController::onEventReceived ( unsigned int topic,
int msg )
inlineoverridevirtual

Handle network events and update controller state.

Parameters
topicEvent topic identifier
msgEvent 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 >.

◆ pushTo()

virtual void uniot::NetworkController::pushTo ( TaskScheduler & scheduler)
inlineoverridevirtual

Push all controller tasks to the scheduler.

Parameters
schedulerTaskScheduler 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.

◆ restore()

virtual bool uniot::NetworkController::restore ( )
inlineoverridevirtual

Restore controller state from persistent storage.

Return values
booltrue 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.

◆ statusAlarm()

void uniot::NetworkController::statusAlarm ( )
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.

◆ statusBusy()

void uniot::NetworkController::statusBusy ( )
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.

◆ statusIdle()

void uniot::NetworkController::statusIdle ( )
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.

◆ statusWaiting()

void uniot::NetworkController::statusWaiting ( )
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.

◆ store()

virtual bool uniot::NetworkController::store ( )
inlineoverridevirtual

Store controller state to persistent storage.

Return values
booltrue 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.


The documentation for this class was generated from the following file: