Pages: [1] 2   Go Down
Author Topic: Arduino Ethernet Shield (W5100) Cannot Access Outside Network  (Read 4083 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This problem is a little odd... I'm trying to get the WebClient example working, though it's refusing to connect to any IP address outside my LAN. I can change the server IP in the example to my router's web interface and it will happily bring it up, though if I were to keep the default for Google or try another IP that isn't on the network, it will fail to connect.

I have attempted to manually set the gateway and subnet with no success.
« Last Edit: February 18, 2011, 12:10:47 am by benjgvps » Logged

0
Offline Offline
Tesla Member
***
Karma: 118
Posts: 8956
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some test code you can try. Make sure the arduino IP address matches the format used by your router and that IP address is not already used.

Code:
//zoomkat 11-13-10
//simple ethernet client test code
//for use with IDE 0021 and W5100 ethernet shield
//modify the arduino lan ip address as needed
//open serial monitor to see what the arduino receives
//push the shield reset button to run client again

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 102 }; // Arduino IP address
byte server[] = { 208, 104, 2, 86 }; // zoomkat's web site

Client client(server, 80);

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  Serial.println("starting simple arduino client test");
  Serial.println();

  delay(1000);

  Serial.println("connecting...");

  if (client.connect()) {
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.0");
    client.println();
  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    Serial.println("==================================");
    Serial.println("");
    client.stop();
    for(;;);
  }
}
 
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some test code you can try. Make sure the arduino IP address matches the format used by your router and that IP address is not already used.

Code:
//zoomkat 11-13-10
//simple ethernet client test code
//for use with IDE 0021 and W5100 ethernet shield
//modify the arduino lan ip address as needed
//open serial monitor to see what the arduino receives
//push the shield reset button to run client again

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 102 }; // Arduino IP address
byte server[] = { 208, 104, 2, 86 }; // zoomkat's web site

Client client(server, 80);

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  Serial.println("starting simple arduino client test");
  Serial.println();

  delay(1000);

  Serial.println("connecting...");

  if (client.connect()) {
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.0");
    client.println();
  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    Serial.println("==================================");
    Serial.println("");
    client.stop();
    for(;;);
  }
}
 

Thank you, though it doesn't seem to work, here is the output from the serial monitor:
Code:

starting simple arduino client test

connecting...
connection failed

disconnecting.
==================================

I rebooted my router and it had no effect. All other devices can access the internet just fine...
« Last Edit: February 18, 2011, 12:35:36 am by benjgvps » Logged

0
Offline Offline
Tesla Member
***
Karma: 118
Posts: 8956
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You may need to log into your router and verify that your ethernet shield is connected to the router. I tried the code before I posted it and it worked for me, so there may be something different doing on in your setup.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I use the Tomato firmware on my router and it did show up there when I was testing it out. As I said, other networked computers can be connected to without issue.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well what the heck.

It worked once... Then I tried it again and it didn't work. Weird.

EDIT: I changed the IP and the MAC address and it seemed to work.
Networks love to be picky...
« Last Edit: February 18, 2011, 01:20:56 am by benjgvps » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

<.................Well what the heck.

It worked once... Then I tried it again and it didn't work. Weird...............>

Same here, wish I could find out why as well....

Connects first time no problems but then it wont connect again either after pushing
reset button or re loading the program...


Logged

Offline Offline
Full Member
***
Karma: 8
Posts: 147
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds like a duplicate IP address on the network.
Logged

0
Offline Offline
Tesla Member
***
Karma: 118
Posts: 8956
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You may have router issues due to disconnecting/reconnecting the arduino to the router. The router may have to scan for attached and detached clients, which may take some amout of time to complete. I just loaded my code in my arduino and pushed the reset button ~10 times in a row. The appropriate result appeard in the serial monitor each time. I'm using a ~$40 netgear wireless router.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Possibly. I do have an unused router running DD-WRT that I could try.
Logged

Lancashire, UK
Offline Offline
Edison Member
*
Karma: 8
Posts: 1992
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You don't have gateway / router IP address in your sketch.  Without it, getting out can be very hit and miss because the arduino doesn't know where the internet is.

Code:
byte gateway[] = { 192, 168, 1, 1 };   //your router's IP address
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You don't have gateway / router IP address in your sketch.  Without it, getting out can be very hit and miss because the arduino doesn't know where the internet is.

Code:
byte gateway[] = { 192, 168, 1, 1 };   //your router's IP address

After resetting it about 10 times and changing the IP address, zoomcat's code now works, though I'm not sure how consistent it will be.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmmmmm... really frustrating..
Still can't connect using Zoomcats test program...
Well, to be exact, it connects one out of twenty or more tries.
Same with any of the ethernet example sketches...

I know I have a correct and unused ip address and the mac address is right.
Makes no difference weather I use gateway or not.
I can ping the arduino no problems...

Using latest ethernet board with SD card reader.... using Arduino 0022. on Windows 7

My router is a Netgear supplied by Sky boadband.....

99% of time it hangs for some seconds showing connecting then I just get connection failed.....disconnecting..

Would be very grateful for any further suggestions on this, as far as I can see, the ethernet
board is either faulty or it's the router that's not compatible with this stuff...
Can't try another router as the contract stipulates you can only use the broadband suppliers router...

Thanks for any help

Regards Philip
Logged

Rural Arizona
Offline Offline
Edison Member
*
Karma: 7
Posts: 1711
Incorrigible tinkerer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can't try another router as the contract stipulates you can only use the broadband suppliers router...
If your "spare" router is not a modem+router combo, you can always give it a static IP address on its "WAN" port, and interpose it between the Arduino and Sky's router.

You'll need to temporarily change the Arduino to a different subnet (like 192.168.2.*) so your DD-WRT router can have different subnets on its "LAN" and "WAN" sides.

That'll give you more ability to snoop on what's going on, via the DD-WRT tools.
Logged

New River, Arizona
Offline Offline
God Member
*****
Karma: 16
Posts: 907
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I had a similar problem with the 'official' arduino shield.  My symptom was always accompanied by a rapidly flashing Rx LED.  When the LED flashed rapidly, the shield would not connect and I had to reset the card until the light flashed "normally".  You know, when there actually was traffic on the network?  It seems the chip itself can get lost and not establish a connection and there is no indication on the pins to tell the software something is wrong.  I'd normally call this a bug in the 5100 software, but I can't prove it. 

I hooked a wire to the Rx LED and ran it to a digital pin and counted the flashes in a period of time and reset the ethernet board if there was a faulty connection.  This way, by the time I got further into the code the board was working properly.  I also check the board from time to time during operation and reset as necessary.  The devices can now run for weeks at a time (between power failures) pretty reliably.

However, this may not be your problem. So watch the Rx LED and see if you have similar symptoms.  It'll flash in at a consistent rapid rate and never seem to follow the normal traffic pattern of your network.
Logged

Trying to keep my house under control http://www.desert-home.com/

Pages: [1] 2   Go Up
Jump to: