feat: enhance UDPClient initialization with local port binding and add WebServerHandler for HTTP server management

This commit is contained in:
GW_MC
2026-02-02 20:46:54 +08:00
parent bcbde510e0
commit 12ad5be48a
6 changed files with 200 additions and 4 deletions

View File

@@ -0,0 +1,42 @@
#pragma once
#include "esp_http_server.h"
#include "esp_err.h"
#include <string>
#include <functional>
class WebServerHandler {
public:
WebServerHandler();
~WebServerHandler();
// Start web server, finds a free port starting from base_port
// Returns the actual port used, or 0 on failure
uint16_t start(const std::string& auth_key, uint16_t base_port = 8080);
// Stop web server
esp_err_t stop();
// Check if server is running
bool is_running() const { return server_ != nullptr; }
// Get the current port
uint16_t get_port() const { return current_port_; }
// Get the auth key
std::string get_auth_key() const { return auth_key_; }
// Register a URI handler
esp_err_t register_uri_handler(const httpd_uri_t* uri_handler);
// Validate auth key from query string
bool validate_auth(const char* query_string) const;
private:
// Prevent copying
WebServerHandler(const WebServerHandler&) = delete;
WebServerHandler& operator=(const WebServerHandler&) = delete;
httpd_handle_t server_ = nullptr;
uint16_t current_port_ = 0;
std::string auth_key_;
};