Hi, this is my first time posting and I am fairly new with Arduino.
I have code running on the Arduino Ethernet to act as an ethernet client. At first it worked perfectly, (well not perfectly but that is a different problem) and got an IP address whether static or through DHCP. However, now, without having made any changes to the code since it last worked I get this problem:
When I try to initialize ethernet using DHCP Serial monitor just doesn't print anything. When I try assigning a static IP, Serial monitor shows the Arduino connect, but says it's IP is 0.0.0.0 and the sketch continues to run/display but obviously with that IP the network connection doesn't work.
I really don't know what could have happened, and would really appreciate an answer as soon as possible as I am working with a deadline.
I am including my code anyway, but since as I said I didn't change anything I think it is probably more related to Arduino set up/issue.
Thanks for your reply; I have the if statement there just to try DHCP before using the static IP. When I do what you suggested (which I have tried) I get the problem I described where it shows an IP of 0.0.0.0.
One thing to check is whether your DHCP server is configured to only give out IP addresses for machines whose network address was recorded. You would need to check out the web site for the DHCP server to see what its configuration is. Or perhaps, the Arduino needs to send in more information to the DHCP server. You might check the logs of your server.
andrewmh20:
I'll try to find out... But again, this worked fine before with the same network setup.
How does one access logs of a router?
It depends on the router, and whether you've ever accessed the admin panel. On mine, I log into the router via the web, and go into the advanced menu screen. I suspect most people never do that. One thing you might try is power cycling the router. Maybe it isn't giving out new IP addresses, and your current machines just don't notice.
There is no menu to see a log of, just settings to change. There isa list of who it has given IP's to and my arduino is not there. This problem has happened on multiple routers.
I just narrowed it down to not being my code because when I run this example code from the PING library I get the same results.
/*
Ping Example
This example repeatedly sends ICMP pings and sends the result over the serial port.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
created 30 Sep 2010
by Blake Foster
*/
#include <SPI.h>
#include <Ethernet.h>
#include <ICMPPing.h>
byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0x27, 0x80}; // max address for ethernet shield
byte ip[] = {10,10,5,105}; // ip address for ethernet shield
byte pingAddr[] = {10,10,5,1}; // ip address to ping
SOCKET pingSocket = 0;
char buffer [256];
void setup()
{
// start Ethernet
Ethernet.begin(mac);
Serial.begin(9600);
Serial.println(Ethernet.localIP());
}
void loop()
{
ICMPPing ping(pingSocket);
ping(4, pingAddr, buffer);
Serial.println(buffer);
delay(500);
}
Router reset didn't help. It's not my code, or my network setup.
If every thing was working, and now it isn't, then most likely have a lose wire or some other mechanical issue. Yesterday I was testing some previously good code that then failed when a pin was set high. The problem was a bare ended test wire in the pin hole had moved and was touching another wire, causing the arduino to freeze when the pin was set high.
That's what I would suspect, I just don't know what it could be since I have tried with nothing attached except the Arduino itself.
Tomorrow I will attach it directly to my PC with a crossover cable, and watch it through WireShark to see if any MAC level packets are even being sent. If not, then I guess I have a problem with the actual Wiznet chip or network interface/adapter.
All I see that could possibly be the Arduino are some ICMP packets (even when I do not have a PING sketch running) from IP 0.0.0.0 and a mac address of all 0's.
It does not matter if you are "not using it". If it is inserted into the slot, it connects to the SPI bus. That causes severe problems with the w5100, especially UDP. DHCP and NTP I have found fail if the SD card is not removed, disabled, or initialized.
Are you using IDE v1.0.1? IDE v1.0 and earlier had some issues with that. Just checking...
I recommend leaving the SD card out until the ethernet stuff is ok.
Have you tried the DhcpAddressPrinter in the ethernet examples? I've compiled it on both Windows and Ubuntu, and it works fine. It may take a minute or so to time out if there is a problem with the dhcp server, or the connection to it. If it doesn't timeout in a couple minutes, you may have a hardware issue.