I need some assistance in troubleshooting issues I am having with the Ethernet Shield. I basically loaded the example the IDE provided. For the server, I change the ip address to one that I know is available and not taken. But When I point the browser to that IP address it won't load. Ping it also failed. I don't know what I am doing wrong. I also tried the Client example as well and connection always failed with latest google.com ip address.
Any idea or suggestion on what I should try to troubleshoot what the problem is?
I am using Macbook Pro. I also tried it on Windows 7 and still with the same results. For the Web Server example, it should be as simple as changing the IP address to an available one, right? Is there any steps I might of missed? At this point, I don't know if it's software or hardware problem. I am completely lost and drained. I searched pretty much everywhere.
Any suggestions as to what else to try to track down the problem?
Are you using a public or private ip? I usually test on a private localnet behind a router.
Here is an example. This is an edited version of the example in the server library.
The localnet is 192.168.2.0/24
The ip I assigned the device 192.168.2.2
The subnet is 255.255.255.0
The gateway is 192.168.2.1
This is a telnet connection, not web. Port 23 is what is used in the library code, so I stuck with that. To connect from a computer on the localnet, I used
telnet 192.168.2.2
#include <SPI.h>
#include <Ethernet.h>
// the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//the IP address for the shield:
byte ip[] = { 192, 168, 2, 2 };
// the router's gateway address:
byte gateway[] = { 192, 168, 2, 1 };
// the subnet:
byte subnet[] = { 255, 255, 255, 0 };
// telnet defaults to port 23
Server server = Server(23);
void setup()
{
// initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
// start listening for clients
server.begin();
}
void loop()
{
// if an incoming client connects, there will be bytes available to read:
Client client = server.available();
if (client == true) {
// read bytes from the incoming client and write them back
// to any clients connected to the server:
server.write(client.read());
}
}
It connects and echos. Not well, but it does.
And it responds to a ping.
I am doing this all locally.
I just tried your example by modifying the ip address and gateway address. Still no response from telnet nor ping. Both my Arduino Uno and Ethernet Shield are official ones.
All lights are on and blinking. I don't think this could be a hardware defect because this is the second ethernet shield I have tried. Unless I have the worst luck of getting both defective shield.
Anyone else ever seen this problem before or have any other suggestions, please help.
I had some problems with the shield too and tried the above example but for some reason i cant get it to connect. here is my code:
i was wondering if anyone has any ideas. The mac address is from the sticker underneath the arduino.
ive noticed i forgot to include the subnet and gateway for the Ethernet.begin(mac, ip, gateway, subnet) function so i put that in my code, but it still doesn't work.
Before we go any further. We should first test your Web Server Example.
I wouldn't trust the MAC address from the sticker because it didn't even work for me.
Try this code,
But you need to change the ip address within your router's range.
/*
Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 4 Sep 2010
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x02, 0xAA, 0xBB, 0xCC, 0x00, 0x01 };
byte ip[] = { 192,168,1, 177 };
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
Server server(80);
void setup()
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
}
void loop()
{
// listen for incoming clients
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(analogRead(analogChannel));
client.println("
");
}
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
Then point your browser to 192.168.1.177 Let me know if it loads.
When you said point my browser to that ip address, you mean the one i assigned it correct not the one you listed? It wont work for me though. I cannot connect my browser to the ip address i assigned. I wanted to point out one thing though. I jack the shield to an ethernet port in the wall on my campus, but my computer is using wireless. There are 2 different ip addresses when i use ipconfig in command prompt depending if i have my computer use wireless or the ethernet cord. because of that i have tried both addresses in the arduino but with no success. I am hoping this doesnt mean its defective b/c that would be a major pain =(
when i use the ip assigned to the wall port, and then try to connect to that one my browser really tries for like 20secs or so, as opposed to the usual 1 second try and comes back as it couldnt connect me to it. is there anything i have to do on the software side to get this to work or should it start working automatically when i upload the code to the board?
If your wireless IP and Ethernet IP are completely different and not within range, then this is most likely the problem. Try connecting the computer to a Ethernet Port as well that way your IP are in same domain. Also, be sure the IP address you assigned to your Ethernet Shield is not already taken. Try pinging it first, if it doesn't respond, it means its open for use. It's alot easier to test this is in controlled environment like your home where you have full access and control to your router.
Try this Webserver example, I also modified IP address to fit Network Configuration. Now point your browser to 192.168.5.110
My main problem was that the Mac address provided in the IDE Example didn't worked on my network. So try that out and let me know what happens.
/*
Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 4 Sep 2010
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x02, 0xAA, 0xBB, 0xCC, 0x00, 0x01 };
byte ip[] = { 192,168,5,110 };
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
Server server(80);
void setup()
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
}
void loop()
{
// listen for incoming clients
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(analogRead(analogChannel));
client.println("
");
}
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
This affected all 16 bit register communications with the ethernet shield. Same symptoms as you. Pings ok, but no web client/server response.
The web services count on that for the client.read() function. Those registers contain the counters and buffer pointers for the inbound data from the network/web to the Arduino device.