feat: enhance UDPClient initialization with local port binding and add WebServerHandler for HTTP server management
This commit is contained in:
42
main/network/web_server_handler.h
Normal file
42
main/network/web_server_handler.h
Normal 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_;
|
||||
};
|
||||
Reference in New Issue
Block a user