Chat freely about anything...

User avatar
By Jimut Dhali
#22008 I am trying to make a web-server with ESP8266.

I wrote some code to send GET request to the server.

Code: Select all<html>
   <head>
      <title>ESP8266 LED Control</title>
   </head>
   <body>
   
   <!-- in the <button> tags below the ID attribute is the value sent to the arduino -->
   
   <button id="11" class="led">Toggle Pin 11</button> <!-- button for pin 11 -->
   <button id="12" class="led">Toggle Pin 12</button> <!-- button for pin 12 -->
   <button id="13" class="led">Toggle Pin 13</button> <!-- button for pin 13 -->
      
   <script src="jquery.min.js"></script>
   <script type="text/javascript">
      $(document).ready(function(){
         $(".led").click(function(){
            var p = $(this).attr('id'); // get id value (i.e. pin13, pin12, or pin11)
            // send HTTP GET request to the IP address with the parameter "pin" and value "p", then execute the function
            $.get("http://192.168.0.101:80/", {pin:p}); // execute get request
         });
      });
   </script>
   </body>
</html>

So a problem is occurring when one connection is opened and I send another GET request without closing the connection. The ESP is taking the second request as a different connection and after that it just hangs and works incorrectly until restarted.

The response of ESP looked like this, though the requests were from the same IP.

Code: Select all0,CONNECT

+IPD,0,374:GET /?pin=12 HTTP/1.1
Host: 192.168.0.101
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8

1,CONNECT

+IPD,1,348:GET /?pin=11 HTTP/1.1
Host: 192.168.0.101
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8

AT+CIPCLOSE=0

busy p...
AT+CIPCLOSE=1

busy p...

But this does not happen when I send data from some TCP Client software like Hercules, every data comes in the same connection, and everything works fine.
How do I get around this problem?