Chat freely about anything...

User avatar
By sgthoppa
#36267 The ESP8266 wifi module sends data sometimes to the server and sometimes it does not. Its very random and I am not understanding how to go about fixing this problem. Below is the part of the code where the data for the server is made ready and is transmitted using the wifi module.

The part where I do if(ser.find(">")) doesn't give a success always and so the data does not get sent to the server.Is there a way to get the data sent to server without much failure.

// TCP connection
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += "184.106.153.149"; // api.thingspeak.com
cmd += "\",80";
ser.println(cmd);

if(ser.find("Error")){
Serial.println("AT+CIPSTART error");
return;
}

// prepare GET string
String getStr = "GET /update?api_key=";
getStr += apiKey;
getStr +="&field2=";
getStr += String(strTemp1,6);
getStr +="&field3=";
getStr += String(strTemp2,6);
getStr += "\r\n\r\n";

delay(200);
// send data length
cmd = "AT+CIPSEND=";
cmd += String(getStr.length());
ser.println(cmd);

delay(200);

if(ser.find(">")){
Serial.println("success");
ser.print(getStr);
Serial.println("Tx Done");
}
else{
Serial.println("Trying again");
loop(); //Loop is the part where I call the wifi transmit function again.
}