webserver
This commit is contained in:
parent
2a034b0dd9
commit
a9ed2ae8c8
70
webserver/webserver.ino
Normal file
70
webserver/webserver.ino
Normal file
@ -0,0 +1,70 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
|
||||
#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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user