Ethernet shield question about Ethernet.maintain() function

Hello Dude,
I have some problem with programming for Ethernet shield and new to Ethernet library. I have an arduino official shield. I tried the example and got it work until come to Ethernet.maintain() function. IDE is v1.0.3. I want to check whether Arduino is connected and stay online or not. My reference is from Google Code Archive - Long-term storage for Google Code Project Hosting.. Here is my code for checking connection via DHCP,

void checkConnection()
{
  Serial.print(F("\n\rInside checkConnection() function"));
  delay(1000);
  switch(Ethernet.maintain()) {
   case 0:   Serial.print(F("\n\rDHCP: Nothing happened")); break;
   case 1:   Serial.print(F("\n\rDHCP: Renew failed")); break;
   case 2:   Serial.print(F("\n\rDHCP: Renew success")); break;
   case 3:   Serial.print(F("\n\rDHCP: Rebind fail")); break;
   case 4:   Serial.print(F("\n\rDHCP: Rebind success")); break;
   default:  Serial.print(F("\n\rDHCP: Unexpected number")); break;
  }
  // print your local IP address:
  Serial.print(F("\n\rCurrent IP address: "));
  Serial.print(Ethernet.localIP()); // print your local IP address: 
}

My problem is that "Ethernet.maintain() function" still showing "nothing happened" even if I disconnected the RJ-45 cable from the Ethernet Shield. Please refer to Ethernet - Arduino Reference. Am I missing something? And is it correct way to check connection?

Inside checkConnection() function
DHCP: Nothing happened
Current IP address: 192.168.1.2

Merry Christmas and happy new year,
pak

The Ethernet::maintain() function is only concerned about renewing a DHCP address, if the one it has has expired.

Since unplugging the ethernet cable does not cause the DHCP address to expire, I wouldn't expect maintain() to do anything.

Thank you for a quick reply, can I conclude that Ethernet.maintain() function is to check expiry of DHCP address? And could you please tell me how to check whether Arduino is connected and stay online or not? Currently, I use the following method to check,

if (clientGoogle.connect(serverGoogle, 80)) {
   ...
   if (clientGoogle.available()){
        ...
   }
}

pak

pak:
And could you please tell me how to check whether Arduino is connected and stay online or not?

Having an IP address doesn't mean you're connected. So your method of connecting to an external server is probsbly the best option.

Yes, until now, one question please, when can I use ethernet.begin() function again? I mean, at what situation, should I use that function again?

Pak

Hey pak,

i'd like to know if you solved your problem and how.

It's an old thread, yes.. but why not trying it? :stuck_out_tongue:

Greetz Chris