ESP32 Webserver not accessible (Timeout)

Gmanc2
Posts: 1
Joined: Sun Oct 25, 2020 6:10 am

ESP32 Webserver not accessible (Timeout)

Postby Gmanc2 » Sun Oct 25, 2020 6:17 am

My esp32 webserver is in accessible here's the serial monitor and picture\

02:06:02.408 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
02:06:02.453 -> configsip: 0, SPIWP:0xee
02:06:02.453 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
02:06:02.453 -> mode:DIO, clock div:1
02:06:02.453 -> load:0x3fff0018,len:4
02:06:02.453 -> load:0x3fff001c,len:1044
02:06:02.453 -> load:0x40078000,len:8896
02:06:02.453 -> load:0x40080400,len:5816
02:06:02.453 -> entry 0x400806ac
02:06:02.685 -> Connecting to homemesh24
02:06:02.779 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 0 - WIFI_READY
02:06:02.779 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 2 - STA_START
02:06:03.012 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 4 - STA_CONNECTED
02:06:03.059 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 7 - STA_GOT_IP
02:06:03.059 -> [D][WiFiGeneric.cpp:381] _eventCallback(): STA IP: 192.168.68.66, MASK: 255.255.252.0, GW: 192.168.68.1
02:06:03.294 -> .
02:06:03.294 -> WiFi connected.
02:06:03.294 -> IP address:
02:06:03.294 -> 192.168.68.66
02:06:03.294 -> Done



https://gyazo.com/83957d964d5d94ffd0e27001f0068491.png
  1. /*********
  2.   Rui Santos
  3.   Complete project details at http://randomnerdtutorials.com  
  4. *********/
  5.  
  6. #include <WiFi.h>
  7. #include <Servo.h>
  8.  
  9. Servo myservo;  // create servo object to control a servo
  10. // twelve servo objects can be created on most boards
  11.  
  12. // GPIO the servo is attached to
  13. static const int servoPin = 13;
  14.  
  15. // Replace with your network credentials
  16. const char* ssid     = "homemesh24";
  17. const char* password = "!";
  18.  
  19. // Set web server port number to 80
  20. WiFiServer server(80);
  21.  
  22. // Variable to store the HTTP request
  23. String header;
  24.  
  25. // Decode HTTP GET value
  26. String valueString = String(5);
  27. int pos1 = 0;
  28. int pos2 = 0;
  29.  
  30. // Current time
  31. unsigned long currentTime = millis();
  32. // Previous time
  33. unsigned long previousTime = 0;
  34. // Define timeout time in milliseconds (example: 2000ms = 2s)
  35. const long timeoutTime = 2000;
  36.  
  37. void setup() {
  38.   Serial.begin(115200);
  39.  
  40.   myservo.attach(servoPin);  // attaches the servo on the servoPin to the servo object
  41.  
  42.   // Connect to Wi-Fi network with SSID and password
  43.   Serial.print("Connecting to ");
  44.   Serial.println(ssid);
  45.   WiFi.begin(ssid, password);
  46.   while (WiFi.status() != WL_CONNECTED) {
  47.     delay(500);
  48.     Serial.print(".");
  49.   }
  50.   // Print local IP address and start web server
  51.   Serial.println("");
  52.   Serial.println("WiFi connected.");
  53.   Serial.println("IP address: ");
  54.   Serial.println(WiFi.localIP());
  55.   Serial.println("Done");
  56.   server.begin();
  57. }
  58.  
  59. void loop(){
  60.   WiFiClient client = server.available();   // Listen for incoming clients
  61.   if (client) {                             // If a new client connects,
  62.     currentTime = millis();
  63.     previousTime = currentTime;
  64.     Serial.println("New Client.");          // print a message out in the serial port
  65.     String currentLine = "";                // make a String to hold incoming data from the client
  66.     while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected
  67.       currentTime = millis();
  68.       if (client.available()) {             // if there's bytes to read from the client,
  69.         char c = client.read();             // read a byte, then
  70.         Serial.write(c);                    // print it out the serial monitor
  71.         header += c;
  72.         if (c == '\n') {                    // if the byte is a newline character
  73.           // if the current line is blank, you got two newline characters in a row.
  74.           // that's the end of the client HTTP request, so send a response:
  75.           if (currentLine.length() == 0) {
  76.             // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
  77.             // and a content-type so the client knows what's coming, then a blank line:
  78.             client.println("HTTP/1.1 200 OK");
  79.             client.println("Content-type:text/html");
  80.             client.println("Connection: close");
  81.             client.println();
  82.  
  83.             // Display the HTML web page
  84.             client.println("<!DOCTYPE html><html>");
  85.             client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
  86.             client.println("<link rel=\"icon\" href=\"data:,\">");
  87.             // CSS to style the on/off buttons
  88.             // Feel free to change the background-color and font-size attributes to fit your preferences
  89.             client.println("<style>body { text-align: center; font-family: \"Trebuchet MS\", Arial; margin-left:auto; margin-right:auto;}");
  90.             client.println(".slider { width: 300px; }</style>");
  91.             client.println("<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>");
  92.                      
  93.             // Web Page
  94.             client.println("</head><body><h1>ESP32 with Servo</h1>");
  95.             client.println("<p>Position: <span id=\"servoPos\"></span></p>");          
  96.             client.println("<input type=\"range\" min=\"0\" max=\"180\" class=\"slider\" id=\"servoSlider\" onchange=\"servo(this.value)\" value=\""+valueString+"\"/>");
  97.            
  98.             client.println("<script>var slider = document.getElementById(\"servoSlider\");");
  99.             client.println("var servoP = document.getElementById(\"servoPos\"); servoP.innerHTML = slider.value;");
  100.             client.println("slider.oninput = function() { slider.value = this.value; servoP.innerHTML = this.value; }");
  101.             client.println("$.ajaxSetup({timeout:1000}); function servo(pos) { ");
  102.             client.println("$.get(\"/?value=\" + pos + \"&\"); {Connection: close};}</script>");
  103.            
  104.             client.println("</body></html>");    
  105.            
  106.             //GET /?value=180& HTTP/1.1
  107.             if(header.indexOf("GET /?value=")>=0) {
  108.               pos1 = header.indexOf('=');
  109.               pos2 = header.indexOf('&');
  110.               valueString = header.substring(pos1+1, pos2);
  111.              
  112.               //Rotate the servo
  113.               myservo.write(valueString.toInt());
  114.               Serial.println(valueString);
  115.             }        
  116.             // The HTTP response ends with another blank line
  117.             client.println();
  118.             // Break out of the while loop
  119.             break;
  120.           } else { // if you got a newline, then clear currentLine
  121.             currentLine = "";
  122.           }
  123.         } else if (c != '\r') {  // if you got anything else but a carriage return character,
  124.           currentLine += c;      // add it to the end of the currentLine
  125.         }
  126.       }
  127.     }
  128.     // Clear the header variable
  129.     header = "";
  130.     // Close the connection
  131.     client.stop();
  132.     Serial.println("Client disconnected.");
  133.     Serial.println("");
  134.   }
  135. }

Who is online

Users browsing this forum: No registered users and 93 guests