Advertisement
Ruddog

Works but then goes offline

Feb 18th, 2018
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.32 KB | None | 0 0
  1. /////////////////////////////////
  2. // Generated with a lot of love//
  3. // with TUNIOT FOR ESP8266     //
  4. // Website: Easycoding.tn      //
  5. /////////////////////////////////
  6. #include <ESP8266WiFi.h>
  7.  
  8. String  ClientRequest;
  9. IPAddress staticIP483_6(192,168,1,9);
  10. IPAddress gateway483_6(192,168,1,1);
  11. IPAddress subnet483_6(255,255,255,0);
  12.  
  13. WiFiServer server(80);
  14.  
  15. void setup()
  16. {
  17.   pinMode(16, OUTPUT);
  18.   ClientRequest = "";
  19.  
  20.   Serial.begin(115200);
  21.     digitalWrite(16,HIGH);
  22.    
  23.   WiFi.disconnect();
  24.   delay(3000);
  25.   Serial.println("START");
  26.    WiFi.begin("SSID","PASSWORD");
  27.   while ((!(WiFi.status() == WL_CONNECTED))){
  28.     delay(300);
  29.     Serial.print("..");
  30.  
  31.   }
  32.   Serial.println("Connected");
  33.   WiFi.config(staticIP483_6, gateway483_6, subnet483_6);
  34.   Serial.println("Your IP is");
  35.   Serial.println((WiFi.localIP()));
  36.   server.begin();
  37.  
  38. }
  39.  
  40.  
  41. void loop()
  42. {
  43.  
  44.     WiFiClient client = server.available();
  45.     if (!client) { return; }
  46.     while(!client.available()){  delay(1); }
  47.     ClientRequest = (client.readStringUntil('\r'));
  48.     client.flush();
  49.     if (ClientRequest.indexOf("LED=ON") > 0) {
  50.      
  51.       digitalWrite(16,LOW);
  52.       delay(900000);
  53.       digitalWrite(16,HIGH);
  54.      
  55.  
  56.     }
  57.     if (ClientRequest.indexOf("LED=OFF") > 0) {
  58.       digitalWrite(16,HIGH);
  59.      
  60.     }
  61.     client.println("HTTP/1.1 200 OK");
  62.     client.println("Content-Type: text/html");
  63.     client.println("");
  64.     client.println("<!DOCTYPE HTML>");
  65.     client.println("<html>");
  66.     client.println("<head>");
  67.     client.println("</head>");
  68.     client.println("<body>");
  69.       client.println("<h1 style=""color:#ff0000"">");
  70.       client.println("Sprinkler Timer");
  71.       client.println("</h1>");
  72.       client.println("<a href=");
  73.       client.println("LED=ON");
  74.       //client.println("><button>");
  75.       client.println("><button style=\"height:200px;width:200px\">");
  76.       client.println("Start Timer");
  77.       client.println("</button></a>");
  78.      
  79.       client.println("<a href=");
  80.       client.println("LED=OFF");
  81.       //client.println("><button>");
  82.       client.println("><button style=\"height:200px;width:200px\">");
  83.       client.println("15 Minutes");
  84.       client.println("</button></a>");
  85.      
  86.     client.println("</body>");
  87.     client.println("</html>");
  88.     client.stop();
  89.      delay(1);
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement