ESP8266-Websocket icon indicating copy to clipboard operation
ESP8266-Websocket copied to clipboard

Program is dead after send json data several times

Open YaoQ opened this issue 9 years ago • 2 comments

Hi, I program the nodeMCU as my websocketclient, and send humidity and temperature data to the websocket server, for the first 5 times, the program update the data to the server successfully, but for the 6th time to send data, seemly the program is dead, this is no other information printed on the serial terminal. I have no idea what had happened. I am sure the server is OK, and the following is the information of the sketch.

Sketch uses 235,746 bytes (22%) of program storage space. Maximum is 1,044,464 bytes. Global variables use 32,624 bytes (39%) of dynamic memory, leaving 49,296 bytes for local variables. Maximum is 81,920 bytes.

void loop() {
 h =  h + 1 ; //just for test
  t = t + 0.5; //just for test

  if (client.connected()) 
  {
   String       postStr ="{";
          postStr +="\"action\":\"update\",";
          postStr +="\"apikey\":\"";
          postStr += apikey;
          postStr +="\",";
          postStr +="\"deviceid\":\"";
          postStr += deviceID;
          postStr +="\",";
          postStr += "\"params\":";
          postStr += "{";
          postStr += "\"humidity\":\"";
          postStr += String(h);
          postStr +="\",";
          postStr += "\"temperature\":\"";
          postStr += String(t);
          postStr +="\"";
          postStr +="}";
          postStr +="}";

    webSocketClient.sendData(postStr);
    Serial.println("Update data");
    Serial.print("humidity: ");
    Serial.println(h);

  } else {
    Serial.println("Client disconnected.");
    while (1) {
      // Hang on disconnected
    }
  }

  // wait to fully let the client disconnect
  delay(20000);

}

YaoQ avatar Feb 22 '16 02:02 YaoQ

is ur problem solved???

selvabha avatar Dec 09 '16 19:12 selvabha

We noticed this library can't handle sending long strings. 5-6 bytes max, especially at these speeds. Highly recommend debouncing this as well.

peterb0yd avatar Apr 16 '18 17:04 peterb0yd