Ethernet Dhcp

Hello,

i'm using the arduino for an UDP communication. But as first the arduino need to find himself a good IP. That works with Ethernet.begin(mac); this i do in my void setup()

when my program is working, i also like to detect if cable is still connected. and if the cable is reconnected i use dhcp again. I try it with the Ethernet.maintain() but he keeps saying nothing happends when i remvove the cable, use a laptop with same ip as my arduino and reconnect arduino. all this time the maintain funcion says nothing happen also the ip adress is not change.

the reasing i need this: what if a pc with the same ip as my arduino connects on the network while de arduino is disconnected. then the arduino connetcs again, it need to change his ip adres but that didn't happend. how can i program this?

thnx

Why should anything happen? The dhcp lease has an "expires" value. The lease will not be renewed until at least half the time to the expires has elapsed. You have an ip, just occasionally not a connection. That has nothing to do with dhcp.

edit: If you issue the same ip to multiple devices, you get what you deserve. :)

the dhcp makes an ip. but when i lose connection (cable disconnected) and an reconnect the arduino need to check again for an ip. because it is possible that an other device take the old ip of the arduino. For this reason to fix this i need the check if i have got connection.

Or how do you think i can best program this.

No problem! Get into the setup for your router, and change the lease time to 30 minutes. The device will need to renew the lease at 15 minutes.

mnxvolders: it is possible that an other device take the old ip of the arduino.

How do you think that would happen?

Having your Arduino connected or disconnected doesn't enable or prevent another host from 'taking' the IP address (whatever that means). If you assign the addresses statically, you need to ensure each address is only assigned once. If you assign them dynamically, you need to ensure that each DHCP client is online at least often enough to renew its lease before it expires and it is the DHCP server's job to ensure that each address is only assigned to one host at a time. Whether the network interface happens to come up or down in the meantime is irrelevant.

If your device has a "current" lease, then the lease agent won't assign the IP to anyone else until the lease expires. Your device has the responsibility to ascertain whether the lease is still good and then renew it. Or it could just renew it anyway and if it's been reasigned, the lease agent will not honor the "request" to keep the IP, it will hand out a new one. Any decent lease agent will ping the network before handing out an IP just in case a device is hard coded. They're not all decent though.

Any decent lease agent will ping the network before handing out an IP just in case a device is hard coded.

That helps not at all if the duplicate device is not online at the time.

SurferTim:

Any decent lease agent will ping the network before handing out an IP just in case a device is hard coded.

That helps not at all if the duplicate device is not online at the time.

I guess I could have said that, but I thought it was obvious. What else could the lease agent do? Any "decent" device will check to see if a conflict exists before coming on line with a hard coded IP. Of course there are even less of these "decent" devices than the others.

Maybe i choose my toppic little wrong, If i program my arduino and in my setup i execute the ethernet.begin(mac); then the arduino makes his own IP. correct? for examble 10.10.10.10 now i disconnect the ethernet cable, the arduino is still running and after 2 houres i reconnect my ethernet cable. the arduino still has the same IP adres. In the the houres the arduino is disconnected a other device connects to the network. it is possible that this new device get the adres 10.10.10.10. correct. Now i reconnect my arduino, the old adres of the arduino is in use and the arduino needs to find a other IP correct? how can i make shure that the arduino takes an unussed IP adres?

i'm sorry for the long text but my knowledge of network is verry little.

greet MNX

@afremont: You are correct on that point. These devices expect us to be smarter than they are. Sometimes that is not true.

@OP: The Ethernet.maintain() does NOTHING if half the "expires" time has not elapsed. No renew, no sign of any ethernet activity until HALF THE TIME has expired. This is not a guess.

i can't change something in the router because i don't use this at home but in school

mnxvolders: i can't change something in the router because i don't use this at home but in school

Aren't you lucky?!! I bet the school IT would be thrilled to talk to someone who has any idea what is going on. Ask him/her! You will be surprised. :)

sow if i understand correct. the ethernet.maintain(function); check for example every 30 minutes if there is a ip confilct? how can i prevent this conflict?

Don't reboot your router every 15 minutes! :)

Aren't you lucky?!! I bet the school IT would be thrilled to talk to someone who has any idea what is going on. Ask him/her! You will be surprised.

the IT of my school isn't that smart. the instal a 32 bit windows version on a new desktop with 16GB ram :) And i'm shure they want make any changes for me :p

i don't get it? surferTim :s

I'm not saying the IT will change things for you, but he/she may help you get around this. I would if I were the IT there. I help my clients get around tech stuff.

Do not underestimate the IT's skill level until you discuss this with him/her. If your network is up and running, the IT isn't stupid.

that's true. but they won't make time for student if they got a problem with a project. they only help if you got problems loggin in on de desktops of the school.

I know that is not true. The IT at my college (decades ago) would probably ignore you if you approached him with that attitude. He did not ignore me, as I suspect yours will not ignore you if you use the correct approach.

if i know how i can check with the arduino that my ethernet cable is connected i think i can solve my problem. if reconnected then get new IP or something. Do you know how i can check if my ethernet cable is connected?