Last active
March 1, 2020 05:39
-
-
Save gresan-gits/f391d727acf1bbeacd55ababd834ab64 to your computer and use it in GitHub Desktop.
AsyncWebserver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "WiFi.h" | |
#include "ESPAsyncWebServer.h" | |
const char* ssid = "yourNetworkName"; | |
const char* password = "yourNetworkPass"; | |
AsyncWebServer server(80); | |
void setup(){ | |
Serial.begin(115200); | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(1000); | |
Serial.println("Connecting to WiFi.."); | |
} | |
Serial.println(WiFi.localIP()); | |
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ | |
int paramsNr = request->params(); | |
Serial.println(paramsNr); | |
for(int i=0;i<paramsNr;i++){ | |
AsyncWebParameter* p = request->getParam(i); | |
Serial.print("Param name: "); | |
Serial.println(p->name()); | |
Serial.print("Param value: "); | |
Serial.println(p->value()); | |
Serial.println("------"); | |
} | |
request->send(200, "text/plain", "message received"); | |
}); | |
server.begin(); | |
} | |
void loop(){} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){ | |
if(!index){ | |
Serial.printf("UploadStart: %s\n", filename.c_str()); | |
} | |
for(size_t i=0; i<len; i++){ | |
Serial.write(data[i]); | |
} | |
if(final){ | |
Serial.printf("UploadEnd: %s, %u B\n", filename.c_str(), index+len); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void handleBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total){ | |
if(!index){ | |
Serial.printf("BodyStart: %u B\n", total); | |
} | |
for(size_t i=0; i<len; i++){ | |
Serial.write(data[i]); | |
} | |
if(index + len == total){ | |
Serial.printf("BodyEnd: %u B\n", total); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for(int i=0;i<paramsNr;i++){ | |
AsyncWebParameter* p = request->getParam(i); | |
Serial.print("Param name: "); | |
Serial.println(p->name()); | |
Serial.print("Param value: "); | |
Serial.println(p->value()); | |
Serial.println("------"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment