Pages: [1] 2   Go Down
Author Topic: Ethernet Shield Interface - IP  (Read 4990 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi folks,

I'm using Ethernet Library included with Arduino-0022 and am having trouble with specification of the IP for the Ethernet Interface. The Arduino Ethernet Shield is the updated microSD version. Platform is MEGA

The problem is that I'm not able to correctly specify an IP with 0 as the 3rd octet. When I specify 192.168.1.xyz there is no problem, whatever number I use for xyz is configured correctly when I upload the sketch.

When I specify 192,168.0.xyz, the number used as xyz is configured as 0.

So for example in the code below 192.168. 0.10

Is configured as 192.168.0.0

Here are the relevant portions of  the code:

“”””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
#include <Ethernet.h>

#define SLAVE 0x01

const byte gateway[] = { 192, 168, 0, 1 };
const byte mac[] = { 0xDE, 0xAD, 0xBE, 0xf6, 0x33, 0x66 };
const byte ip[] = { 192, 168, 0,10}; // Arduino has this IP

“”””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
This is what I get back in serial monitor:
“””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””

Avail. mem: 77.87%

Configuring Ethernet interface: IP: 192.168.0.0.
Server started on port 502
ACK error 1
ACK error 1
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
I'm not able to ping 192.168. 0.10

I'm not aware what the ACK errors refer to.

Everything works fine when the the 3rd octet is 1, but the network I'm tying in to uses 0.

I've tried and retried and keep getting 0 for the 4th octet. Any suggestions much appreciated.


Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46291
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
const byte ip[] = { 192, 168, 0,10}; // Arduino has this IP
My first thought is to question this comment. You are using this array to assign an IP address to the Arduino. 0 in an octet has special significance.

What IP address does your PC have on your home network? I'm guessing it does not have a 0 in the 3rd octet.
Logged

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

The network is being set up for an environmental monitoring project at a remote location (solar powered, wireless-cellular based). The router has address 192.168.0.1. The six other devices all have 0 for the 3rd octet. A computer is not part of the network, which consists of devices such as webcams and monitoring-related microprocessors. We are adding the Arduino to the network. Thanks for your interest.
Logged

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

I've never had the problem you're describing, but I couldn't use the 'const' keyword and had to make the ip addresses regular variables due to some compiler error I couldn't decipher.  So, just a thought, try:

byte ip[] = { 192, 168, 0,10}; // Arduino has this IP

I am using a zero in the same position as you and it is working fine.  I'm using addresses 192.168.0.200 and up from there.  Also, I'm still on development environment 21.
Logged

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

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

192.168.0.X was pretty standard for home routers a few years back (or sometimes 10.X.X.X), its only comparatively recently they standardised on 192.168.1.X.    
Logged


Colorado
Offline Offline
Full Member
***
Karma: 1
Posts: 220
Arduino 0022 and Ubuntu 11.10 64bit.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please show entire sketch
Logged

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

I appear to be having the same issue.  I am using the example code strait out of the ethernet library with 21 release on a mac.  I expected it to just work, but it's obviously not that simple.  My router is a motorola surfboard 'SBG900' default IP of 192.168.100.1 but my computer sees the router in the config page as 192.168.0.1.  I have tried both these numbers and neither can connect, even when i switch the ip to match.  It always hangs for a few minutes and then fails.  

The gateway code is added to the library example from a page in the book 'programming interactivity' but that book's examples don't work either.  I've been trying to pool info from forums and examples and stuff, try different cobinations, nothing seems to get me going.

I've already aborted my plan to get an xport direct working, I couldn't get it to configure after a few weeks of tinkering so i ordered the ethernet shield... i heard it was easier but it's still got me hitting my head on the desk. Any suggestions? I'm lost.

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

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x2D, 0x80 }; // shield MAC ID from sticker
byte ip[] = { 192,168,0,177 };  // arduino
byte gateway[] = { 192,168,0,1 }; // router
byte server[] = { 173,194,33,104 }; // Google

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
Client client(server, 80);

void setup() {
  // start the Ethernet connection:
  Ethernet.begin(mac, ip, gateway);
  // start the serial library:
  Serial.begin(9600);
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect()) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.0");
    client.println();
  }
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    for(;;)
      ;
  }
}

Logged

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

I should clarify that with the addition of the webduino library I can get it working as a server (at least locally) just not as a client.
Logged

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

Below is some simple client code I use for testing purposes. If this works then you may be encountering issues accessing large commercial web sites just using an IP address.

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: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried your code and it failed.  I think i have my problem narrowed down a little though.  I am able to run a server locally inside my lan network, and i can set an address as a client and ping it locally... It looks to me that nothing is passing through the router to the outside.  I'm not very good at networks/computers, i'm more electrical/mechanical minded... but I THINK it may be my router.

i'm thinking that i'm either not setting the IP/gateway correctly, or my router is rejecting it based on it's settings.  My next step is to reset the router to default settings and re-configure it, if that doesn't work I may have to 'buy and return' a lynksys router from best buy and test that.  

One thing i'm not understanding is that your code doesn't even bother with the 'gateway' declaration. Is that not needed to get past the router? I've been confused about what numbers go where. Several tutorials say you need 'gateway' and to get numbers from whatismyipaddress.com or from ifconfig in terminal... all of that confuses me and i'm not sure what numbers go in which variables. The other half of the tutorials just leave out the gateway all together and seem to work just as well for most people.
Logged

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

When in doubt, add the gateway and subnet lines. Once you have uploaded your code to the arduino, have you logged into your router to see if it is connected? If your router has an IP address of 192.168.0.1, then in my code you probably should change the asigned IP to something like 192.168.0.102. Using a subnet of 255, 255, 0, 0 might solve the possible issue of the third octet being a 1 or a 0. You don't mention your router brand, but I use a netgear 614 wireless (~$40 at walmart) and it seems to work fairly well. You might try pulling the power plug on your router and see if it sees the arduino on reboot.
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: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 smiley
My router is a motorola surfboard 'SBG900'.  I just played around with a bunch of settings and got it to work!

I had to set up a static dhcp lease with my arduino's mac and IP, which i had tried multiple times before with my other attempts.  I think what finally got it working is clicking the bypass firewall checkbox in that setup area, which i had not done before.

Now that it connects, i can finally start learning how to use it.  Thanks so much for the help!
Logged

netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello I also had trouble connecting via the router. When I reprogram the Arduino while connected to the router it works fine!

But when I program the Arduino without connection to the router it works localy with a cross cable bit when i plugged it into the router with a straight cable it will not work!

Any idea?

greetings Andre
Logged

netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok perhaps of topic but I connected the Arduino to a lan socket on the laptop. The laptop itself is connected via the wireless interface of the laptop to the router.

Question is it possible to use the lan connection and connect it to the wireless interface so I can reach the router wireless?

Arduino IP 192.168.1.177
Laptop Lan IP 192.168.1.83
Laptop Wreless IP 192.168.1.79

Router default gateway 192.168.1.245

I hope this is not a silly question!
Logged

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

Quote
Question is it possible to use the lan connection and connect it to the wireless interface so I can reach the router wireless?

It may be possible, but it will depend on the capabilities of the operating system on your computer. With windows, you would probably need to use ICS (internet connection sharing) to do what you want to do.
« Last Edit: January 16, 2011, 09:00:04 pm by zoomkat » Logged

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

Pages: [1] 2   Go Up
Jump to: