11//
22// A simple server implementation showing how to:
33// * serve static messages
4- // * read GET and POST parameters
54// * handle missing pages / 404s
5+ // * setup an http update server
66//
77
88#include < Arduino.h>
1616#include < ESPAsyncWebServer.h>
1717#include < ESPAsyncHTTPUpdateServer.h>
1818
19+ // create an object from the UpdateServer
1920ESPAsyncHTTPUpdateServer updateServer;
2021AsyncWebServer server (80 );
2122
2223const char * ssid = " YOUR_SSID" ;
2324const char * password = " YOUR_PASSWORD" ;
2425
25- const char * PARAM_MESSAGE = " message" ;
26-
2726void notFound (AsyncWebServerRequest *request) {
2827 request->send (404 , " text/plain" , " Not found" );
2928}
@@ -45,30 +44,9 @@ void setup() {
4544 request->send (200 , " text/plain" , " Hello, world" );
4645 });
4746
48- // Send a GET request to <IP>/get?message=<message>
49- server.on (" /get" , HTTP_GET, [] (AsyncWebServerRequest *request) {
50- String message;
51- if (request->hasParam (PARAM_MESSAGE)) {
52- message = request->getParam (PARAM_MESSAGE)->value ();
53- } else {
54- message = " No message sent" ;
55- }
56- request->send (200 , " text/plain" , " Hello, GET: " + message);
57- });
58-
59- // Send a POST request to <IP>/post with a form field message set to <message>
60- server.on (" /post" , HTTP_POST, [](AsyncWebServerRequest *request){
61- String message;
62- if (request->hasParam (PARAM_MESSAGE, true )) {
63- message = request->getParam (PARAM_MESSAGE, true )->value ();
64- } else {
65- message = " No message sent" ;
66- }
67- request->send (200 , " text/plain" , " Hello, POST: " + message);
68- });
69-
7047 server.onNotFound (notFound);
7148
49+ // setup the updateServer with credentials
7250 updateServer.setup (&server, " admin" , " admin" );
7351 server.begin ();
7452}
0 commit comments