Ethernet Dhcp

yes the arduino needs to the correct thing but how does the arduino knows when to ask for a new ip. It needs to ask for a new ip when he is connected to the server. how can the arduino know when he is connected and when not? if know how to do this i think i can program the rest of my code:)

SurferTim:
Don't reboot your router every 15 minutes! :slight_smile:

Right. Problems can always be forced, but just following the established rules and going the extra mile in your software to perform basic sanity checks to "just make sure" will eliminate most problems like the ones being discussed here.

Set the dhcp lease to a very very short time. If the network is stable, then you should not have a problem with this. Ask your IT how often the network must be restarted.

SurferTim:
The Arduino does not need to know the time. The lease is normally issued by length. It doesn't say "the lease expires on 3-5-2013", it says "the lease expires in 2 days".
What does it matter if it is 1 January 1970 or 5 March 2013

If you reboot the Arduino, the dhcp request will be sent and a new ip will be issued if a duplicate was issued to another device in the meantime.

That's correct, it is issued in minutes I believe, but I'm not sure. While the client doesn't need to know the calender date/time, it does need to accurately know how long it has been since the lease was granted. Maybe it's a matter of semantics, but the client does need to know the time in some sense of the word.

I agree, it's a non-issue. There are no requirements (on the network side anyway) to wait any certain amount of time before renewing or obtaining a lease.

To the OP, know whether the server is available would be resolved by just attempting to access it in some way. Maybe PING is enough for you. I haven't used it yet, but I'd be willing to bet that there is a function call in the Arduino TCP/IP software to see if the cable is connected. The network card hardware certainly knows.

The network card hardware certainly knows.

That is not true. Only the w5200 knows that. You can unplug the CAT5 cable from a w5100, and it doesn't have a clue!

SurferTim:

The network card hardware certainly knows.

That is not true. Only the w5200 knows that. You can unplug the CAT5 cable from a w5100, and it doesn't have a clue!

I think this answers (in the negative) to the main question of how the sketch can detect the physical disconnection of the cable.

SurferTim:

The network card hardware certainly knows.

That is not true. Only the w5200 knows that. You can unplug the CAT5 cable from a w5100, and it doesn't have a clue!

Wow, you're kidding. Even the cheapest NE2000 compatible cards that I've seen can tell if the cable is connected. Heck, most MACs will auto-negotiate the connection. I'll have to look at that data sheet. Let's say I'm skeptical right now, but stranger things have been proven to me. :slight_smile:

EDIT: I see that this is an all-in-one chip with a TCP/IP stack built in. The datasheet seems to indicated that the device should know if the cable is connected since it supports auto-negotiation and has a LINK STATE LED output pin. If the embedded software can't tell the caller the state of the link, then I'd say it was a bug in the embedded software.

The w5100 has a tcp/udp stack built-in, but does not have the sensor to detect the the physical state of the device. If the physical device becomes disconnected, the w5100 does not have a way to detect if the cable is disconnected.

You can file a complaint with Wiznet, but I almost guarantee they will say "get a W5200".

a lot of reactions thnx:)

i got a standaard ethernet shield with the W5100.
So i need an other shield with the W5200 to detect the cable?

It also depends on setting the proper MAC address, but I assume it is properly configured.

This the code i use for my mac:

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
Ethernet.begin(mac)

I don't know how else i can doe this. it is like in the example code

i use the Ethernet.maintain(); in the begin of my void loop()

Ethernet.maintain() does nothing but return until the lease is half expired. If the dhcp lease was 2 days, then for the first 24 hours, Ethernet.maintain() returns "no action taken".

mnxvolders:

It also depends on setting the proper MAC address, but I assume it is properly configured.

This the code i use for my mac:

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };

Ethernet.begin(mac)




I don't know how else i can doe this. it is like in the example code

Not exactly the best choice, but it may work. The mac address is a unique identifier for network devices, and by using the example configuration you can be sure that many other devices will use it. However, most other devices in your network will use their true, unique mac address, so you can get along with it... until some of your colleagues connect their Arduinos using the sample configuration.

Look if you can find the mac address printed somewhere on the shield or the box. At the moment, however, this doesn't seem to be a problem.

mnxvolders:
i use the Ethernet.maintain(); in the begin of my void loop()

Not a perfect solution (but it seems there are none, apart from resetting the Arduino), but that would reduce the risk of reusing an invalid address. Just remember to check whether the function really returns 0 and use Ethernet.localIP() if it doesn't.

mnxvolders:
a lot of reactions thnx:)

i got a standaard ethernet shield with the W5100.
So i need an other shield with the W5200 to detect the cable?

The main difference is that the W5200 has a status register that keeps track of the link state (whether the cable is attached or not). But this also requires a different version of the Ethernet library, specific for the W5200. I don't know the status of this library, whether it's complete and provides the required functionality (you can always inspect the status register within your code, but a library should give you something more, such as interrupts when the link is down).

I will change that when i know how to get always a good ip and detecting when my cable is connected:)

Do you know how i can change the lease time in my arduino.
On my desktop is is 4h, on my labtop is 1h (cmd -> ipconfig/all)
with arduino it is about half houre. (waited that long)

And it is not possible with de ethernetshield based on th W5100 to detect if there is a physical connection?
i think there is becaus when i connect my cable LED's start to work. and those led are connected to the W5100 if you look at the schematic of the ethernet shield.
sow i think it is possible but i don't know how. does someone know this?

second question.
when you use Ethernet.maintain();
what is de the diffrents betweem renew and rebind?
The time they check is that the same and how can i change this?

mnxvolders:
And it is not possible with de ethernetshield based on th W5100 to detect if there is a physical connection?
i think there is becaus when i connect my cable LED's start to work. and those led are connected to the W5100 if you look at the schematic of the ethernet shield.
sow i think it is possible but i don't know how. does someone know this?

You may attach something to pin 66 of the chip to see if it's down, or a light sensor to the LED. It seems is an output-only pin, not something you can inspect through a register. There may be some hidden API, but if there is one, it's well hidden.

Renew, rebind... Not sure about this, but I think not all calls to maintain() are actually sent to the DHCP server. Some (most) are resolved 'internally' by checking a timeout. So, if you just got your lease the next time you call maintain() it will simply return with a Nothing happened code.
Renew means you asked the DHCP server to keep your leased address, and the request was granted. Rebind means that your DHCP server did not accept your request OR did not respond, you went on asking for a while, addressing your requests to the same DHCP server, and finally broadcasted your request to whomever could give you an answer (possibly a different DHCP server).

You may attach something to pin 66 of the chip to see if it's down, or a light sensor to the LED. It seems is an output-only pin, not something you can inspect through a register. There may be some hidden API, but if there is one, it's well hidden.

I see it is an output pun of the w5100. that i the reason i think he can detect the connection because he needs to turn on the leds when my cable is connected. How does he know when he must turn on this led? and how can i found out with the arduino?

I also tried to send a mail to arduino support but can't find the mail adres. :s

I contacted the arduino support. I hope they can give me some tips.
when i use dhcp (ethernet.begin(mac):wink: and i have no cable connection, it takes a while before he notice that there is no connection to the router/server. how can i reduce that time? then i can ask a dhcp in beginning of my loop. it is a solution, if it good i don't know:)

...and i have no cable connection, it takes a while before he notice that there is no connection to the router/server. how can i reduce that time?

Plug the cable in
or
use a static ip
or
modify the ethernet dhcp library
or
get a W5200 shield
otherwise
it takes a couple minutes to determine there is no dhcp server available.