#include "web_server.hpp" #include "app_config.hpp" #include #include static const char *TAG = "web_server"; WebServer WebServer::instance; // Root handler - serves a simple dashboard static esp_err_t rootHandler(httpd_req_t* req) { const char* response = R"( ZoneBridge Dashboard

ZoneBridge Control Panel

System Online

ESP32-S3 Touch LCD 4.3" is running

)"; httpd_resp_set_type(req, "text/html"); return httpd_resp_send(req, response, strlen(response)); } // API handler for status static esp_err_t apiStatusHandler(httpd_req_t* req) { const char* json_response = R"({"status":"online","uptime":0})"; httpd_resp_set_type(req, "application/json"); return httpd_resp_send(req, json_response, strlen(json_response)); } WebServer& WebServer::getInstance() { return instance; } void WebServer::start(int port) { if (server != nullptr) { ESP_LOGW(TAG, "Web server already running"); return; } httpd_config_t config = HTTPD_DEFAULT_CONFIG(); config.server_port = port; config.stack_size = WEB_SERVER_STACK_SIZE; config.max_uri_handlers = 16; if (httpd_start(&server, &config) != ESP_OK) { ESP_LOGE(TAG, "Failed to start web server"); return; } // Register URL handlers httpd_uri_t root = { .uri = "/", .method = HTTP_GET, .handler = rootHandler, .user_ctx = nullptr }; httpd_register_uri_handler(server, &root); httpd_uri_t api_status = { .uri = "/api/status", .method = HTTP_GET, .handler = apiStatusHandler, .user_ctx = nullptr }; httpd_register_uri_handler(server, &api_status); ESP_LOGI(TAG, "Web server started on port %d", port); } void WebServer::stop() { if (server != nullptr) { httpd_stop(server); server = nullptr; ESP_LOGI(TAG, "Web server stopped"); } } bool WebServer::isRunning() const { return server != nullptr; }