Guest User

ESP_Server

a guest
Oct 3rd, 2018
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include <ESP8266WebServer.h>
  3. #include <ESP8266mDNS.h>
  4.  
  5. const char *ssid = "DataJugling";
  6. const char *password = "jugle123";
  7. const char *mDNS = "dataserver";
  8.  
  9. ESP8266WebServer server(80);
  10.  
  11. bool ledState = LOW;
  12.  
  13. String getData() {
  14.   return String("{\"state\": ") + String(ledState) + String("}");
  15. }
  16.  
  17. void setup() {      
  18.   WiFi.mode(WIFI_AP);
  19.   WiFi.softAP(ssid, password);
  20.   MDNS.begin(mDNS);
  21.  
  22.   server.on("/", []() {
  23.     server.send(200, "text/html", getData());
  24.   });
  25.  
  26.   server.begin();
  27. }
  28.  
  29. void loop() {
  30.   server.handleClient();
  31.   if(millis() % 1000 == 0) ledState = !ledState;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment