-->
Page 1 of 1

Keeping the web client alive while looping on an input

PostPosted: Mon Jan 23, 2017 10:03 pm
by DonFrench
My application makes the ESP8266 into an access point and is designed to be used interactively by a user with a smart phone. One of the functions of the app waits for a digital input to go high before reacting. The code is the following:
Code: Select all   while(digitalRead(DIGITAL_IN) != 1){
      delay(1);
   }
   doYourThing( );


And this works - it does its thing when the input goes high, no matter how long it takes for that to happen. But while waiting, the client on the smart phone loses the connection and the user has to reboot the ESP8266 to regain access. But so far I haven't found a way to keep the client alive. Any ideas on how to do this?

Re: Keeping the web client alive while looping on an input

PostPosted: Tue Jan 24, 2017 8:40 am
by AcmeUK
Have you tried a Meta tag on your initial page telling the remote browser to keep refreshing the page?

Have a look at this example which refreshes the page every 30 seconds :-
Code: Select all<html>
  <head>
    <title>Your page title</title>
    <meta http-equiv="refresh" content="30;url=index.html">
  </head>
  <body>
  </body>
</html>

Re: Keeping the web client alive while looping on an input

PostPosted: Tue Jan 24, 2017 11:56 am
by eduperez
As AcmeUK pointed out, you should design your application such as the client polls the server for updates on the status. You can use a refresh, ajax, web sockets, ... Also, you should code your sketch so you only have a loop, that both serves clients and checks for pin status.