3#include <ESPAsyncWebServer.h>
9#include "ArduinoJson.h"
25#ifndef HTTP_SERVER_PORT
26#define HTTP_SERVER_PORT 80
31 using std::placeholders::_1;
45 request->send(405,
"text/plain",
46 F(
"PUT to /config not allowed.\n"));
50 std::map<String, Configurable*>::iterator
it =
53 request->send(404,
"text/plain",
54 F(
"Configuration key not found.\n"));
62 request->send(400,
"text/plain",
63 F(
"Unable to extract keys from JSON.\n"));
67 request->send(200,
"text/plain",
F(
"Configuration successful.\n"));
81 this->handle_config_list(
request);
87 request->send(404,
"text/plain",
F(
"Configuration key not found.\n"));
93 request->beginResponseStream(
"application/json");
104 debugD(
"Serving gziped index.html");
107 response->addHeader(
"Content-Encoding",
"gzip");
113 debugD(
"Serving gziped bootstrap.min.css");
116 response->addHeader(
"Content-Encoding",
"gzip");
122 debugD(
"Serving gziped jsoneditor.min.js");
125 response->addHeader(
"Content-Encoding",
"gzip");
130 debugD(
"Serving gziped sensesp.js");
133 response->addHeader(
"Content-Encoding",
"gzip");
137 server->on(
"/device/reset",
HTTP_GET,
139 server->on(
"/device/restart",
HTTP_GET,
151 debugI(
"HTTP server started");
153 debugW(
"HTTP server not started, WiFi not connected");
159 debugI(
"HTTP server started");
164 MDNS.addService(
"http",
"tcp", 80);
188 if (
request->contentLength()) {
196 debugD(
"_HEADER[%s]: %s",
h->name().c_str(),
h->value().c_str());
203 debugD(
"_FILE[%s]: %s, size: %u",
p->name().c_str(),
p->value().c_str(),
205 }
else if (
p->isPost()) {
206 debugD(
"_POST[%s]: %s",
p->name().c_str(),
p->value().c_str());
208 debugD(
"_GET[%s]: %s",
p->name().c_str(),
p->value().c_str());
220 request->beginResponseStream(
"application/json");
226 serializeJson(json_doc, *response);
227 request->send(response);
232 request->send(200,
"text/plain",
"/config");
238 "OK, resetting the device settings back to factory defaults.\n");
243 request->send(200,
"text/plain",
"OK, restarting\n");
244 ReactESP::app->onDelay(50, []() {
ESP.restart(); });
249 std::vector<std::pair<int, String>>
pairs;
308 debugI(
"Handle button_it %s id=%s",
request->url().c_str(),
id.c_str());
310 request->send(200,
"text/html",
"Success!");
312 request->send(404,
"text/html",
"Command not found!");
315 request->send(400,
"text/html",
"Missing id parameter.");
An object that is capable of having configuration data that can be set remotely using a RESTful API,...
virtual void save_configuration()
void handle_info(AsyncWebServerRequest *request)
void handle_device_reset(AsyncWebServerRequest *request)
void add_sorted_configurables(JsonArray &config)
void handle_command(AsyncWebServerRequest *request)
void handle_device_restart(AsyncWebServerRequest *request)
void handle_config(AsyncWebServerRequest *request)
void handle_not_found(AsyncWebServerRequest *request)
virtual void start() override
static SensESPBaseApp * get()
Get the singleton instance of the SensESPBaseApp.
Automatic calling of the start() method at startup.
static const std::map< String, UIOutputBase * > * get_ui_outputs()
const uint PAGE_css_bootstrap_size
const uint PAGE_index_size
const uint PAGE_js_jsoneditor_size
std::map< String, Configurable * > configurables
std::map< String, UIOutputBase * > ui_outputs