Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Twoaster
#49905 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! :D

Code: Select allvoid 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);
         }
    }