Connectivity Manager
Relevant source files
The following files were used as context for generating this wiki page:
The Connectivity Manager serves as the central orchestration layer for all network-related communication within FlxOS. It integrates disparate subsystems—including WiFi Station mode, WiFi Hotspot (SoftAP), and Bluetooth—into a unified interface. This module decouples the underlying hardware drivers and ESP-IDF network stack from the application layer, providing reactive data streams for UI components and system services.
The manager is responsible for managing network state persistence, handling concurrent access to shared wireless hardware, and exposing real-time telemetry such as hotspot data usage, signal strength, and connection status.
Sources: main/core/connectivity/README.md, main/core/connectivity/ConnectivityManager.hpp:15-25
Architecture and Components
The Connectivity Manager operates as a singleton that coordinates several specialized managers. It leverages a reactive programming model using "Observables" and "Subjects" to notify observers of state changes without requiring polling.
Subsystem Orchestration
The manager encapsulates the following primary components:
- WiFi Manager: Handles Station mode connections, scanning, and IP acquisition.
- Hotspot Manager: Manages SoftAP creation, NAT (Network Address Translation), and client tracking.
- Bluetooth Manager: Controls basic Bluetooth radio state.
The diagram above shows the hierarchical relationship where ConnectivityManager acts as the primary API for the rest of the OS.
Sources: main/core/connectivity/ConnectivityManager.hpp:78-85, main/core/connectivity/ConnectivityManager.cpp:20-40, main/CMakeLists.txt:3-15
Core Functionality
WiFi Management
The Connectivity Manager provides high-level control over WiFi operations, including enabling the radio, scanning for access points, and establishing connections. It exposes the current connection state and network metadata (SSID, IP) through observables.
| Function | Description |
|---|---|
setWiFiEnabled(bool) | Powers the WiFi radio on or off. |
scan(callback) | Triggers an asynchronous scan for nearby networks. |
connect(ssid, pass) | Connects to a specific Access Point. |
disconnect() | Terminates the current WiFi Station connection. |
Sources: main/core/connectivity/ConnectivityManager.hpp:35-45, main/core/services/cli/CliService.cpp:188-215
Hotspot (SoftAP) and NAT
The manager facilitates the creation of a local hotspot. A critical feature identified in the source is the ability to enable NAT (Network Address Translation), allowing connected hotspot clients to share the device's WiFi Station internet connection.
Reactive Data Streams
The Connectivity Manager uses an observable pattern to expose system state. This allows UI components (like the Status Bar or Settings App) to react instantly to network changes.
Available Observables
| Observable Type | Data Provided |
|---|---|
WiFiStatus | Current state (Disconnected, Connecting, Connected). |
WiFiIp | The local IP address assigned to the station. |
HotspotClients | List of MAC addresses and info for connected clients. |
HotspotUsage | Sent/Received byte counts and real-time speeds. |
HotspotUptime | Duration the hotspot has been active. |
Sources: main/core/connectivity/ConnectivityManager.hpp:63-75, reports/docs.txt:18-32
Implementation Details
Thread Safety
The manager implements internal locking mechanisms to ensure that concurrent requests from the CLI, GUI, and background services do not cause race conditions in the underlying ESP-IDF stack. It provides a dedicated getWifiMutex() for synchronized operations.
Sources: main/core/connectivity/ConnectivityManager.hpp:32, reports/includes.txt:10
Resource Monitoring
The Hotspot subsystem includes specific logic for tracking data consumption and client counts, which is reported back through the Connectivity Manager.
- Client Tracking: Monitored via
HotspotManager::getConnectedClients. - Performance: High cyclomatic complexity in event handlers indicates robust handling of various WiFi events (Disconnects, Auth failures).
Sources: main/core/connectivity/hotspot/HotspotManager.cpp:113, reports/complexity.txt:14-18
CLI Integration
The CliService provides a direct interface to the Connectivity Manager, allowing for manual network control via terminal commands.
// Example of CLI integration with ConnectivityManager
static int cmdHotspot(int argc, char** argv) {
auto& conn_mgr = System::ConnectivityManager::getInstance();
// ... logic to call conn_mgr.startHotspot or stopHotspot
}
Sources: main/core/services/cli/CliService.cpp:245-280
Conclusion
The Connectivity Manager is a pivotal module in FlxOS that abstracts complex networking tasks into a manageable, reactive API. By coordinating WiFi, Hotspot, and NAT services, it ensures that FlxOS can maintain stable external connections while simultaneously acting as a network gateway for other devices.