Chat here about code rewrites, mods, etc... with respect to the github project https://github.com/esp8266/Arduino

Moderator: igrr

User avatar
By Evocg
#20050 Hi all,

I have been working with my ESP01 module over the last few days and I found an issue I cant find the root cause to. So I am using my module to control a LED. I do this by open a TCP-socket and keeping it open, then I check the received data and turn the LED on if I receive a H(IGH) and turn it off if I receive a L(OW). So this works fine if I connect to my module using telnet but when I try the same thing using chrome.sockets cordova plugin. It seems like WiFiClient.connected() fails to detect that the other part has disconnected and the module gets stuck in a infinite loop.

This is my implmenentation:

Code: Select allWiFiClient client = server.available();
 
  if (client) {
   
    Serial.println("Client connected.");
   
    while (client.connected()) { 
      if (client.available()) {
       
        char command = client.read();
       
        if (command == 'H') {
         
          digitalWrite(ledPin, HIGH);
          Serial.println("Led is now on.");
        }
        else if (command == 'L') {
         
          digitalWrite(ledPin, LOW);
          Serial.println("Led is now off.");
        }       
      }
    }
    Serial.println("Client disconnected.");
    client.stop();
  }


Have any one seen something similar?