/** * @file WiFiManager.h * @brief WiFi connection management for AP and Client modes * * Handles WiFi connectivity in both Access Point and Client modes, * with automatic reconnection support. * * @author Locomotive Test Bench Project * @date 2025 */ #ifndef WIFI_MANAGER_H #define WIFI_MANAGER_H #include #include #include "Config.h" /** * @class WiFiManager * @brief Manages WiFi connectivity and modes * * Provides WiFi functionality in two modes: * - Access Point (AP): Creates standalone network * - Client (STA): Connects to existing WiFi network * * Features automatic reconnection in client mode. */ class WiFiManager { public: /** * @brief Constructor * @param cfg Pointer to Config object for WiFi settings */ WiFiManager(Config* cfg); /** * @brief Initialize WiFi based on configuration * * Sets up either AP or Client mode based on config settings. * Called during system startup. */ void begin(); /** * @brief Set up Access Point mode * * Creates a standalone WiFi network using configured * SSID and password. Default IP: 192.168.4.1 */ void setupAccessPoint(); /** * @brief Connect to existing WiFi network * * Attempts to connect as client to configured network. * Falls back to AP mode if connection fails after 10 seconds. */ void connectToWiFi(); /** * @brief Check if WiFi is connected * @return true if connected (or AP mode active), false otherwise */ bool isConnected(); /** * @brief Get current IP address * @return IP address as string (AP IP or STA IP) */ String getIPAddress(); /** * @brief Update WiFi status and handle reconnection * * Should be called regularly from main loop. * Handles automatic reconnection in client mode. */ void update(); private: Config* config; ///< Pointer to configuration object unsigned long lastReconnectAttempt; ///< Timestamp of last reconnect attempt static const unsigned long RECONNECT_INTERVAL = 30000; ///< Reconnect interval (30 seconds) }; #endif