Maybe an odd question. I have here two standard Arduino Ethernet boards, both run the same simple 'Chatserver' example code.
Now here is the tricky part.
Both have an unique Mac address assigned in code so no problems there. BUT on purpose both have the same IP address assigned. Now I can connect one of them to my router and ping it just fine. Now I connect the other one and no surprise there this device can not respond to the ping command, also IP scan software can not see it.
This is all expected of course and probably the router is rejecting the second device with the same IP address. Now, I am wondering if there is some code that can detect whether or not it is 'accepted' by a router/switch? And if it is rejected it can flash a led or something indicating it has a problem.
This is all expected of course and probably the router is rejecting the second device with the same IP address. Now, I am wondering if there is some code that can detect whether or not it is 'accepted' by a router/switch? And if it is rejected it can flash a led or something indicating it has a problem.
The router assigns an IP address to each device that connects. You need to configure the router to always assign the same address to the Arduino (or Arduinos) and you need to keep track of which Arduino gets assigned which address.
Then, you don't make this dumb mistake that you are trying to solve in code.
trc2013:
I am wondering if there is some code that can detect whether or not it is 'accepted' by a router/switch? And if it is rejected it can flash a led or something indicating it has a problem.
There is an Internet protocol (ICMP PING ECHO REQUEST) which might be useful for you.
Do an (ICMP PING ECHO REQUEST) before using a fixed IP address in your LAN! If you get a response back, DO NOT USE THAT IP address, it is already in use! If you get a timeout, the IP address is most likely not occupied by another device and there is a big chance that the IP address is usable by xour device (at that time).
To be sure to get a usable IP address use DHCP and get a dynymically assigned IP address (should be 100% safe for 'clients'' of all types, but may be inappropriate for servers that need a fixed address.
If you connect 2 devices with the same ip to a subnet, both of them wil come online. A router wil not deny any of them.
You can test this by by connecting 2 of such devices and ping them from another device, ie laptop. Ping will probably report DUPs... duplicate replies.
What you see as rejected is probably "the other device" beating it in the reply.
Switches - layer 2 devices - have no knowledge of ip addresses.... just MACs. A switch wil remember which MAC it can connect to on which port.
The router does know about ip adresses - its a layer 3 device - and probably gets confused because different MAC will appear in its ARP list with the same ip address.
Routers do not assign ip addresses. That would be a DHCP server. Not a bad idea to have one
jurs:
Do an (ICMP PING ECHO REQUEST) before using a fixed IP address in your LAN! If you get a response back, DO NOT USE THAT IP address, it is already in use! If you get a timeout, the IP address is most likely not occupied by another device and there is a big chance that the IP address is usable by xour device (at that time).
to be able to do a ping you need an ip number assigned... if you assign an already used number to do the check it will also fail.... his own interface wil respond. when lucky you wil see a DUP reply... but usually not when a device is pinging his own interface.
The DHCP server is a good suggestion though.... if you're not sure with ip configuration use a DHCP server... perhaps make a reservation on MAC.
Thanks for the replies. I will explain the situation a bit more.
I am developing a device with is essentially an Ethernet based motor controller based on the Arduino Ethernet bits and pieces. There will be many of these controllers hooked up to a 100mbit switch. Its a special situation and DHCP is sadly out of the question. So IP addresses and all must be predefined in code. More of these devices will be added to the 100mbit switch overtime.
We will have to keep track of the IP's used in the past so we will not program a controller with an IP that is already used in previous controllers. BUT mistakes happen and there might be a case where a controller does get programmed with an IP already in use. And once this new device it added to the switch it will not work due to an IP conflict. But I would like to have a way to have a flashing led that indicated there is a network error (due to the duplicate IP) and needs to be examined. So I would need a code that somehow notices a problem like this.
Be really careful about assigning IP addresses.
or
Set aside one IP address as the default and all devices start with that IP. Start pinging up the localnet until you get no response. Then change the device to that IP. Add only one device at a time.
#2 has some drawbacks. If all devices are not up and running when you start a new device, you will still get duplicate IPs.
SurferTim:
2) Set aside one IP address as the default and all devices start with that IP. Start pinging up the localnet until you get no response. Then change the device to that IP. Add only one device at a time.
#2 has some drawbacks. If all devices are not up and running when you start a new device, you will still get duplicate IPs.
not a bad idea at all
you can get away with that if you do not save the ip address for after a reboot.... every device which turns on has find out - every time - if an ip is free.