PicoWebServer
global
network/PicoWebServer.h
global
Méthodes publiques
| Méthode | Description | Paramètres | Retour |
|---|---|---|---|
|
PicoWebServer()
PicoWebServer(uint16_t port = 80);
|
|||
|
connectToWiFi()
connectToWiFi(const String& ssid, const String& password, int timeout = 20000);
|
|||
|
startAP()
startAP(const String& ssid, const String& password = "", int channel = 1);
|
|||
|
on()
on(const String& method, const String& path, RouteHandler handler);
|
|||
|
get()
get(const String& path, RouteHandler handler);
|
|||
|
post()
post(const String& path, RouteHandler handler);
|
|||
|
put()
put(const String& path, RouteHandler handler);
|
|||
|
del()
del(const String& path, RouteHandler handler);
|
|||
|
onDefault()
onDefault(RouteHandler handler);
|
|||
|
onNotFound()
onNotFound(RouteHandler handler);
|
|||
|
getClientIP()
getClientIP() const;
|
|||
|
begin()
begin();
|
|||
|
handleClient()
handleClient();
|
|||
|
stop()
stop();
|
|||
|
htmlTemplate()
htmlTemplate(const String& title, const String& content);
|
|||
|
jsonResponse()
jsonResponse(bool success, const String& message, const String& data = "");
|
|||
|
getSystemInfo()
getSystemInfo();
|
|||
|
getWiFiInfo()
getWiFiInfo();
|
Méthodes privées
parseRequest(WiFiClient& client, HttpRequest& request);;
parseQueryString(const String& query, std::map& params);;
sendResponse(WiFiClient& client, const HttpResponse& response);;
urlDecode(const String& str);;
Variables membres
String method;
String path;
String queryString;
String body;
String body;
WiFiServer server;
RouteHandler defaultHandler;
RouteHandler notFoundHandler;
Code source
// // Server.h
// #pragma once
#include "../StatusDevice.h"
// #include <Arduino.h>
// #include <WiFi.h>
// #include <map>
// #include <vector>
// #include <functional>
// // Structure pour les paramètres de requête
// struct HttpRequest {
// String method;
// String path;
// String queryString;
// std::map<String, String> queryParams;
// std::map<String, String> headers;
// String body;
// // Méthodes utilitaires
// String getParam(const String& name, const String& defaultValue = "") const;
// bool hasParam(const String& name) const;
// };
// // Structure pour la réponse HTTP
// struct HttpResponse {
// int statusCode = 200;
// String contentType = "text/html";
// std::map<String, String> headers;
// String body;
// void setHeader(const String& name, const String& value);
// void setCookie(const String& name, const String& value, int maxAge = 3600);
// void redirect(const String& url);
// void sendJson(const String& json);
// };
// // Type pour les handlers de routes
// typedef std::function<void(const HttpRequest&, HttpResponse&)> RouteHandler;
// // Classe principale du serveur web
// class PicoWebServer {
// private:
// WiFiServer server;
// std::map<String, RouteHandler> getRoutes;
// std::map<String, RouteHandler> postRoutes;
// std::map<String, RouteHandler> putRoutes;
// std::map<String, RouteHandler> deleteRoutes;
// RouteHandler defaultHandler;
// RouteHandler notFoundHandler;
// // Méthodes privées
// void parseRequest(WiFiClient& client, HttpRequest& request);
// void parseQueryString(const String& query, std::map<String, String>& params);
// void sendResponse(WiFiClient& client, const HttpResponse& response);
// String urlDecode(const String& str);
// public:
// PicoWebServer(uint16_t port = 80);
// // Connexion WiFi
// bool connectToWiFi(const String& ssid, const String& password, int timeout = 20000);
// void startAP(const String& ssid, const String& password = "", int channel = 1);
// // Gestion des routes
// void on(const String& method, const String& path, RouteHandler handler);
// void get(const String& path, RouteHandler handler);
// void post(const String& path, RouteHandler handler);
// void put(const String& path, RouteHandler handler);
// void del(const String& path, RouteHandler handler);
// // Handlers spéciaux
// void onDefault(RouteHandler handler);
// void onNotFound(RouteHandler handler);
// // Méthodes utilitaires
// String getClientIP() const;
// // Gestion du serveur
// void begin();
// void handleClient();
// void stop();
// // Template HTML simple
// static String htmlTemplate(const String& title, const String& content);
// static String jsonResponse(bool success, const String& message, const String& data = "");
// // Informations système
// static String getSystemInfo();
// static String getWiFiInfo();
// };