#pragma once /** * @file WifiManager.h * @brief WiFi Access Point + Async Web Server for configuration and OTA. * * Responsibilities: * - Start a WPA2 Access Point with credentials from AppConfig. * - Host a lightweight web UI on port 80: * GET / → configuration page (tile/page editor) * GET /api/config → current config as JSON * POST /api/config → apply new config (JSON body) * POST /api/ble/cmd → forward BLE command (restart, wifi_sta, wifi_ap) * GET /api/state → current BoatState as JSON (live data snapshot) * POST /update → OTA firmware upload * - Signal OTA progress to the display. * - Accept a BLE passkey submission from the web UI. */ #include "Config.h" #include class WifiManager { public: /** * @brief Start the AP and the async web server. * Must be called from setup() or on button combo. */ void begin(const char* ssid, const char* password); /** @brief Stop the AP and server (e.g. when switching back to BLE-only). */ void stop(); /** @brief Returns true when the AP is active and the server is running. */ bool isActive() const { return _active; } /** @brief IP address of the AP interface (always 192.168.4.1). */ static constexpr const char* AP_IP = "192.168.4.1"; /** @brief Call from loop() — no-op currently, kept for future use. */ void update(); private: AsyncWebServer _server{80}; bool _active = false; void _setupRoutes(); // Route handlers void _handleRoot (AsyncWebServerRequest*); void _handleGetConfig (AsyncWebServerRequest*); void _handlePostConfig (AsyncWebServerRequest*, uint8_t*, size_t, size_t, size_t); void _handleGetState (AsyncWebServerRequest*); void _handleBleCmd (AsyncWebServerRequest*, uint8_t*, size_t, size_t, size_t); void _handlePasskey (AsyncWebServerRequest*, uint8_t*, size_t, size_t, size_t); void _handleOtaUpload (AsyncWebServerRequest*, const String&, size_t, uint8_t*, size_t, bool); void _handleNotFound (AsyncWebServerRequest*); // Serve the embedded HTML (stored in PROGMEM) static const char INDEX_HTML[] PROGMEM; }; // Singleton accessor extern WifiManager wifiManager;