diff --git a/README.md b/README.md index e69de29..1dc17bf 100644 --- a/README.md +++ b/README.md @@ -0,0 +1 @@ +#ESP8266 ArduinoIDE \ No newline at end of file diff --git a/webserver/index.html b/webserver/index.html new file mode 100644 index 0000000..9878ddd --- /dev/null +++ b/webserver/index.html @@ -0,0 +1,135 @@ + + + + + + + + + +
+
+

Switches

+
+ + +
+
+ + +
+
+ + + + \ No newline at end of file diff --git a/webserver/webserver.ino b/webserver/webserver.ino index 54e8156..0dec2de 100644 --- a/webserver/webserver.ino +++ b/webserver/webserver.ino @@ -1,70 +1,66 @@ -#include #include +#include #ifdef ESP32 -#pragma message(THIS EXAMPLE IS FOR ESP8266 ONLY!) +#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 = ""; +const char *ssid = "Decentrala"; +const char *password = ""; +String resSwitch1On = "Switch1 is On", resSwitch1Off = "Switch1 is Off", + resSwitch2On = "Switch2 is On", resSwitch2Off = "Switch2 is Off"; -String ledon,ledoff,led1on,led1off; - -void Redon() -{ +void switch1On() { digitalWrite(4, HIGH); - server.send(200, "text/html", ledon); + server.send(200, "text/html", resSwitch1On); } -void Redoff() -{ +void switch1Off() { digitalWrite(4, LOW); - server.send(200, "text/html", ledoff); + server.send(200, "text/html", resSwitch1Off); } -void violeton() -{ +void switch2On() { digitalWrite(14, HIGH); - server.send(200, "text/html", led1on); + server.send(200, "text/html", resSwitch2On); } -void violetoff() -{ +void switch2Off() { digitalWrite(14, LOW); - server.send(200, "text/html", led1off); + server.send(200, "text/html", resSwitch2Off); } void setup() { - Serial.begin(115200); + Serial.begin(74880); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); - while (WiFi.status() != WL_CONNECTED)delay(500); + 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.on("/switch1on", switch1On); + server.on("/switch1off", switch1Off); + server.on("/switch2on", switch2On); + server.on("/switch2off", switch2Off); + server.enableCORS(true); server.begin(); - pinMode(14, OUTPUT);//D5 - pinMode(4, OUTPUT);//D2 + pinMode(14, OUTPUT); // D5 + pinMode(4, OUTPUT); // D2 digitalWrite(14, LOW); digitalWrite(4, LOW); - } -void loop() -{ +void loop() { server.handleClient(); delay(1); } \ No newline at end of file