timeout problem on ethernet library

Hello

I test to transmit IOT data to my webside with HTTP POST, with arduino Mega and Ethernet board, and I have a strange phenomen :

The Ethernet connect needs generaly about 70ms, and from time to time it needs exactly 15000ms. This is too long, to protect my program by a Wathdog (I understood limited to 8s).

How can I avoid, that the Connect comand blocks so long time the programm ?

The timeout definition seem to have no influence !!

I joined the essential programm lines, to send the POST and measure the connection time

thanks for any idea

Armin

void setup()
{
  Serial.begin(9600);
  if (Ethernet.begin(mac) == 0) {
    Serial.println("ETHERNET :  Failed to configure Ethernet using DHCP");
  }
  else {
    Serial.println("ETHERNET :  DHCP assigned IP successfully");
    IP = Ethernet.localIP();
    IP1 = IP[0];
    IP2 = IP[1];
    IP3 = IP[2];
    IP4 = IP[3];
    ConnexionEthernet_Message = String(IP1) + String(".") + String(IP2) + String(".") + String(IP3) + String(".") + String(IP4);
    Serial.println( ConnexionEthernet_Message);
    delay(1000);
    Ethernet_ClientWEB.setConnectionTimeout(500);
  }
}

void loop() {
  Debut = millis();
  Ethernet_ClientWEB.setConnectionTimeout(500);
  if (Ethernet_ClientWEB.connect("www.steinhilber.eu", 80)) { 
    Fin = millis();
    Serial.println("ETHERNET :  trame sended to steinhilber.eu");
    Ethernet_ClientWEB.println("POST /add_lora.php HTTP/1.1");  
    Ethernet_ClientWEB.println("Host: steinhilber.eu"); 
    Ethernet_ClientWEB.println("Content-Type: application/x-www-form-urlencoded");
    Ethernet_ClientWEB.print("Content-Length: ");
    Ethernet_ClientWEB.println(ArdWeb.length());
    Ethernet_ClientWEB.println();
    Ethernet_ClientWEB.print(ArdWeb);
  }
  else {
    Fin = millis();
    Serial.println("ETHERNET :  not able to connect to steinhilber.eu");
  }
  Diff = Fin - Debut;
  Serial.println("ETHERNET :  connection time=");
  Serial.println( String(Diff));
  Serial.println( "");
  delay(1000);
}

and a print of result :

ETHERNET :  trame sended to steinhilber.eu
ETHERNET :  connection time=
72

ETHERNET :  trame sended to steinhilber.eu
ETHERNET :  connection time=
70

ETHERNET :  trame sended to steinhilber.eu
ETHERNET :  connection time=
71

ETHERNET :  not able to connect to steinhilber.eu
ETHERNET :  connection time=
15025

ETHERNET :  trame sended to steinhilber.eu
ETHERNET :  connection time=
71

ETHERNET :  trame sended to steinhilber.eu
ETHERNET :  connection time=
273

ETHERNET :  trame sended to steinhilber.eu
ETHERNET :  connection time=
73

ETHERNET :  trame sended to steinhilber.eu
ETHERNET :  connection time=
71

Use a loop that controls the long time, and in that loop use the mills for part of your delay and pat the dog each time that times out. When the outer loop count is exceeded do a reset routine (forces WDT to time out). Sorry I do not have time to delve into this further but this should get you started.

Hello,

thanks for your answer,

but arduino is entierly blocked at the line of Ethernet.connect, so no way to build a loop around :frowning:

Armin

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.