Client.print() error after 2 minutes connected to server
Posted: Tue Jun 28, 2016 6:50 am
Hi all,
I am using an ESP8266 to send a file from an Arduino DUE to a server using PHP.
Basically, I read the data from the Serial and send 1000 bytes packages to the server.
It works perfectly for any file that takes less than 2 minutes to send.
I noticed that, independently of the size of the file, after 2 minutes the client.print() doesn´t work anymore. The server doesn´t return any error too.
I thought it could be the timeout but timeouts are related to idle time... I am sending the data constantly.
Do you know anything about this issue? Thanks!
I am using an ESP8266 to send a file from an Arduino DUE to a server using PHP.
Basically, I read the data from the Serial and send 1000 bytes packages to the server.
It works perfectly for any file that takes less than 2 minutes to send.
I noticed that, independently of the size of the file, after 2 minutes the client.print() doesn´t work anymore. The server doesn´t return any error too.
I thought it could be the timeout but timeouts are related to idle time... I am sending the data constantly.
Do you know anything about this issue? Thanks!
Code: Select all
void postToHTTP()
{
long interval = 20000;
unsigned long previousMillis = millis();
String temp ="";
unsigned long total_size = 0;
if (client.connect(host, 80))
{
Serial.println("Client Connected");
while (!temp.endsWith("AaB03x--")) // wait until the end of the file
{
if(Serial.available()) // if there is data coming fron the arduino
{
temp.concat((char)Serial.read()); // concat string
if (temp.length() > 1000)
{
Serial.println('S'); // inform arduino that is writing - avoid losing packages
if(!client.print(temp)) // error after 2 minutes
{
Serial.print("client print error after: ");
Serial.println(millis() - previousMillis); // usually returns 125000 miliseconds
while (client.connected())
{
if ( client.available() )
{
char ch2 = client.read(); // doesn´t show anything
Serial.print(ch2);
}
}
}
while(client.available())
{
Serial.print((char)client.read());
}
total_size = total_size + temp.length();
Serial.println(total_size);
temp = "";
Serial.println('K'); // pode mandar mais dados
}
}
if(temp.endsWith("AaB03x--"))
{
total_size = total_size + temp.length();
Serial.println(total_size);
Serial.println('K');
total_size = 0;
client.print(temp);
client.println();
delay(200);
}
if(!client.connected())
{
delay(500);
Serial.println("Client disconnected");
client.connect(host, 80);
}
}