From 89a9ccf627b3ece0d5e7e42bb48495cebfca15c1 Mon Sep 17 00:00:00 2001 From: DenialOfIntelligence <135235065+DenialOfIntelligence@users.noreply.github.com> Date: Fri, 29 Sep 2023 18:37:52 +0200 Subject: [PATCH] Add explanation.md --- simple_web/explanation.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 simple_web/explanation.md diff --git a/simple_web/explanation.md b/simple_web/explanation.md new file mode 100644 index 0000000..dd50798 --- /dev/null +++ b/simple_web/explanation.md @@ -0,0 +1,32 @@ +# An explanation for the code in this dir + +``` +AsyncWebServer server(80); +``` +Start the Web Server on port 80 + +``` +WiFi.begin(ssid, password); + if (WiFi.waitForConnectResult() != WL_CONNECTED) { + Serial.printf("WiFi Failed!\n"); + return; +} +``` +Start the WIFI with `WiFi.begin(ssid, password);` and wait for connection + +``` +server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ + request->send(200, "text/html", "Turn the LED ONTurn the LED OFF"); + }); +``` +`server.on` Defines an Endpoint for a request (e.g /index.html) + +`request->send(200, "text/html", " ");` on Request answer with 200 in the format text/html with this string + +``` +server.on("/on", HTTP_GET, [](AsyncWebServerRequest *request){ + request->send(200, "text/plain", "Was there ever anything here?"); + digitalWrite(LED_BUILTIN, HIGH); + }); +``` +This is for when the user clicks on the ON button and fetches the /on url it turns the LED on!