SHARE
TWEET

Untitled

a guest Jul 20th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /////////////////////////////////
  2. // Generated with a lot of love//
  3. // with TUNIOT FOR ESP32     //
  4. // Website: Easycoding.tn      //
  5. /////////////////////////////////
  6. #include <WiFi.h>
  7.  
  8. String  ClientRequest;
  9. WiFiServer server(80);
  10.  
  11. WiFiClient client;
  12.  
  13. String myresultat;
  14.  
  15. String ReadIncomingRequest(){
  16. while(client.available()) {
  17. ClientRequest = (client.readStringUntil('\r'));
  18.  if ((ClientRequest.indexOf("HTTP/1.1")>0)&&(ClientRequest.indexOf("/favicon.ico")<0)){
  19. myresultat = ClientRequest;
  20. }
  21. }
  22. return myresultat;
  23. }
  24.  
  25. void setup()
  26. {
  27. ClientRequest = "";
  28.  
  29. Serial.begin(9600);
  30.  
  31. pinMode(5, OUTPUT);
  32.   WiFi.disconnect();
  33.   delay(3000);
  34.   Serial.println("START");
  35.  
  36.   WiFi.begin("stemup","pitajkonobara");
  37.   while ((!(WiFi.status() == WL_CONNECTED))){
  38.     delay(300);
  39.     Serial.print("..");
  40.  
  41.   }
  42.   Serial.println("Connected");
  43.   Serial.println("Your IP is");
  44.   Serial.println((WiFi.localIP()));
  45.   server.begin();
  46.  
  47. }
  48.  
  49.  
  50. void loop()
  51. {
  52.  
  53.     client = server.available();
  54.     if (!client) { return; }
  55.     while(!client.available()){  delay(1); }
  56.     ClientRequest = (ReadIncomingRequest());
  57.     ClientRequest.remove(0, 5);
  58.     ClientRequest.remove(ClientRequest.length()-9,9);
  59.     if (ClientRequest == "db_on") {
  60.       digitalWrite(5,HIGH);
  61.  
  62.     }
  63.     if (ClientRequest == "db_off") {
  64.       digitalWrite(5,LOW);
  65.  
  66.     }
  67.     client.println("HTTP/1.1 200 OK");
  68.     client.println("Content-Type: text/html");
  69.     client.println("");
  70.     client.println("<!DOCTYPE HTML>");
  71.     client.println("<html>");
  72.     client.println("Fran");
  73.     client.println("</html>");
  74.     client.stop();
  75.     delay(1);
  76.     client.flush();
  77.  
  78. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top