From a9ed2ae8c8f38ff1359d248ce52483076e433eba Mon Sep 17 00:00:00 2001 From: coja Date: Sun, 24 Mar 2024 21:45:45 +0100 Subject: [PATCH] webserver --- webserver/webserver.ino | 70 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 webserver/webserver.ino diff --git a/webserver/webserver.ino b/webserver/webserver.ino new file mode 100644 index 0000000..54e8156 --- /dev/null +++ b/webserver/webserver.ino @@ -0,0 +1,70 @@ +#include +#include + +#ifdef ESP32 +#pragma message(THIS EXAMPLE IS FOR ESP8266 ONLY!) +#error Select ESP8266 board. +#endif + +ESP8266WebServer server(80); // 80 is the port number + +const char* ssid = "Decentrala"; +const char* password = ""; + + +String ledon,ledoff,led1on,led1off; + +void Redon() +{ + digitalWrite(4, HIGH); + server.send(200, "text/html", ledon); +} + +void Redoff() +{ + digitalWrite(4, LOW); + server.send(200, "text/html", ledoff); +} + +void violeton() +{ + digitalWrite(14, HIGH); + server.send(200, "text/html", led1on); +} + +void violetoff() +{ + digitalWrite(14, LOW); + server.send(200, "text/html", led1off); +} + +void setup() { + + Serial.begin(115200); + WiFi.mode(WIFI_STA); + WiFi.begin(ssid, password); + + while (WiFi.status() != WL_CONNECTED)delay(500); + + Serial.print(WiFi.localIP()); + + server.on("/led1on", Redon); + server.on("/led1off", Redoff); + server.on("/led2on", violeton); + server.on("/led2off", violetoff); + + server.begin(); + + pinMode(14, OUTPUT);//D5 + pinMode(4, OUTPUT);//D2 + + digitalWrite(14, LOW); + digitalWrite(4, LOW); + +} + +void loop() +{ + server.handleClient(); + delay(1); +} \ No newline at end of file