![]() |
|
Uniot Core
|
| 0.8.1 |
Complete captive portal implementation for device configuration. More...
#include <ConfigCaptivePortal.h>
Public Member Functions | |
| ConfigCaptivePortal (const IPAddress &apIp, AwsEventHandler wsHandler=nullptr) | |
| Construct a new ConfigCaptivePortal. | |
| bool | start () |
| Start the captive portal services. | |
| void | stop () |
| Stop all captive portal services. | |
| AsyncWebServer * | get () |
| Get the underlying AsyncWebServer instance. | |
| void | wsTextAll (const String &message) |
| Send text message to all connected WebSocket clients. | |
| void | wsText (uint32_t clientId, const String &message) |
| Send text message to a specific WebSocket client. | |
| void | wsCloseAll () |
| Close all WebSocket connections. | |
| void | wsEnable (bool enable) |
| Enable or disable WebSocket functionality. | |
| bool | wsClientsActive (unsigned long window=30000) const |
| Check if WebSocket clients are actively connected. | |
| const IPAddress & | ip () const |
| Get the IP address of the captive portal. | |
| virtual void | execute (short _) override |
| Execute periodic captive portal maintenance tasks. | |
Public Member Functions inherited from uniot::IExecutor | |
| virtual | ~IExecutor () |
| Virtual destructor for proper cleanup. | |
Complete captive portal implementation for device configuration.
This class implements a full-featured captive portal that combines DNS redirection, HTTP serving, WebSocket communication, and mDNS discovery. It's designed to provide a seamless configuration experience where users connecting to the device's WiFi network are automatically redirected to the configuration interface.
The captive portal operates by:
All operations are designed to be non-blocking and suitable for embedded systems with limited resources.
|
inline |
Construct a new ConfigCaptivePortal.
| apIp | IP address for the access point and web server |
| wsHandler | Optional WebSocket event handler callback |
Initializes all components of the captive portal including DNS server, HTTP server, and WebSocket handler. The WebSocket is automatically added to the HTTP server and configured with the provided event handler.
|
inlineoverridevirtual |
Execute periodic captive portal maintenance tasks.
| _ | Unused parameter (required by IExecutor interface) |
Performs essential maintenance operations including:
This method should be called regularly from the main loop or task scheduler.
Implements uniot::IExecutor.
|
inline |
Get the underlying AsyncWebServer instance.
| AsyncWebServer* | Pointer to the HTTP server for adding custom routes |
Provides access to the web server for adding custom request handlers, routes, and other HTTP-specific configuration.
|
inline |
Get the IP address of the captive portal.
| const | IPAddress& Reference to the portal's IP address |
|
inline |
Start the captive portal services.
| bool | true if all services started successfully, false otherwise |
Sequentially starts all captive portal components:
If any component fails to start, the method returns false and the portal remains in a stopped state.
|
inline |
Stop all captive portal services.
Gracefully shuts down all components in reverse order:
Includes workarounds for known memory issues with DNSServer cleanup.
|
inline |
Check if WebSocket clients are actively connected.
| window | Time window in milliseconds for considering clients active (default: 30 seconds) |
| bool | true if clients are connected and recently active, false otherwise |
Determines if there are WebSocket clients connected and whether they've been active within the specified time window. This helps distinguish between truly active clients and stale connections.
|
inline |
Close all WebSocket connections.
Disables the WebSocket server and forcibly closes all active client connections. Used during shutdown or when switching operating modes.
|
inline |
Enable or disable WebSocket functionality.
| enable | true to enable WebSocket server, false to disable |
Controls whether the WebSocket server accepts new connections and processes existing ones. Useful for temporarily suspending WebSocket operations without stopping the entire portal.
|
inline |
Send text message to a specific WebSocket client.
| clientId | ID of the target WebSocket client |
| message | Text message to send |
Sends a text message to a specific WebSocket client identified by its client ID. Useful for targeted responses and private communication.
|
inline |
Send text message to all connected WebSocket clients.
| message | Text message to broadcast |
Broadcasts a text message to all currently connected WebSocket clients. This is commonly used for status updates and configuration responses.