43 lines
1.1 KiB
C++
43 lines
1.1 KiB
C++
#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_;
|
|
};
|