Pages: [1]   Go Down
Author Topic: IP address of Ethernet shield  (Read 1011 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am totally new to Arduino and, of course, new to the Ethernet Shield. I decided to try and run the  Web Server tutorial code http://arduino.cc/en/Tutorial/WebServer  .

Obviously the code needs to be changed to reflect the MAC address of the shield and the IP of the shield. I expected to be able to simply plug in the shield (attached to the Mega) to my router and then log into the router to check out the “attached devices” page to find the IP and MAC addresses. I can see my computer, cell phone and  Tablet but not the Shield. Activity lights appear to indicate the Shield is properly attached but it does not show on the attached devices list.

What am I doing wrong?


Thanks.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 98
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am totally new to Arduino and, of course, new to the Ethernet Shield. I decided to try and run the  Web Server tutorial code http://arduino.cc/en/Tutorial/WebServer  .

Obviously the code needs to be changed to reflect the MAC address of the shield and the IP of the shield. I expected to be able to simply plug in the shield (attached to the Mega) to my router and then log into the router to check out the “attached devices” page to find the IP and MAC addresses. I can see my computer, cell phone and  Tablet but not the Shield. Activity lights appear to indicate the Shield is properly attached but it does not show on the attached devices list.

What am I doing wrong?
Thanks.
There should be no need to change the mac address, unless there is a clash

You MUST change the ip address to match your network:

change this line:

Code:
IPAddress ip(192,168,1, 177);

So that the first 3 numbers match your network and subnet....

so if a device on your network is on 192.168.0.xx

Change above line to :
Code:
IPAddress ip(192,168,0, 177);

if your device is on network 192.168.5.xx change the line to:

Code:
IPAddress ip(192,168,5, 177);


The reason you cannot see the device is because, whilst it may be connected, it is not  'within' the domain your router is looking at.

If you get stuck, then  post the addresses your computer/tablet show up at.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the information on the MAC address.

When I poll "attached devices" on my router page (192.168.1.1 ) with the Ethernet shield attached I see the following:

192.168.1.6 Epson (my wireless network printer)
192.168.1.110 My-PC (my computer hard wired)
192.168.3 Android_followed by numbers (my wireless ... obviously ...tablet)
192.168.1.253 unknown (my phone)

Notice there is not an IP for the shield. How can I find an IP when it does not seem to exist?
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9685
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Simple combined client (use serial monitor to test) and server (use browser to test) you can try.

Code:
//zoomkat 12-08-11, combined client and server
//simple button GET with iframe code
//for use with IDE 1.0
//open serial monitor and send an g to test client and
//see what the arduino client/server receives
//web page buttons make pin 4 high/low
//use the \ slash to escape the " in the html
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
IPAddress ip(192,168,1,102); // ip in lan
IPAddress gateway(192,168,1,1); // internet access via router
IPAddress subnet(255,255,255,0); //subnet mask
IPAddress myserver(208,104,2,86); // zoomkat web page
EthernetServer server(84); //server port
EthernetClient client;
String readString;

//////////////////////

void setup(){

  pinMode(4, OUTPUT); //pin selected to control
  Ethernet.begin(mac, ip, subnet, gateway);
  server.begin();
  Serial.begin(9600);
  Serial.println("server/client 1.0 test 12/08/11"); // keep track of what is loaded
  Serial.println("Send an g in serial monitor to test client"); // what to do to test client
}

void loop(){
  // check for serial input
  if (Serial.available() > 0)
  {
    byte inChar;
    inChar = Serial.read();
    if(inChar == 'g')
    {
      sendGET(); // call sendGET function
    }
  } 

  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string
          readString += c;
          //Serial.print(c);
        }

        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging

            //now output HTML data header
          if(readString.indexOf('?') >=0) { //don't send new page
            client.println("HTTP/1.1 204 Zoomkat");
            client.println();
            client.println(); 
          }
          else {
            client.println("HTTP/1.1 200 OK"); //send new page
            client.println("Content-Type: text/html");
            client.println();

            client.println("<HTML>");
            client.println("<HEAD>");
            client.println("<TITLE>Arduino GET test page</TITLE>");
            client.println("</HEAD>");
            client.println("<BODY>");

            client.println("<H1>Zoomkat's simple Arduino 1.0 button</H1>");

            client.println("<a href=\"/?on\" target=\"inlineframe\">ON</a>");
            client.println("<a href=\"/?off\" target=\"inlineframe\">OFF</a>");

            //client.println("<IFRAME name=inlineframe src=\"res://D:/WINDOWS/dnserror.htm\" width=1 height=1\">");
            client.println("<IFRAME name=inlineframe style=\"display:none\" >");         
            client.println("</IFRAME>");

            client.println("</BODY>");
            client.println("</HTML>");
          }

          delay(1);
          //stopping client
          client.stop();

          ///////////////////// control arduino pin
          if(readString.indexOf("on") >0)//checks for on
          {
            digitalWrite(4, HIGH);    // set pin 4 high
            Serial.println("Led On");
          }
          if(readString.indexOf("off") >0)//checks for off
          {
            digitalWrite(4, LOW);    // set pin 4 low
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}

//////////////////////////
void sendGET() //client function to send/receie GET request data.
{
  if (client.connect(myserver, 80)) {
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.0");
    client.println();
  }
  else {
    Serial.println("connection failed");
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read();
    Serial.print(c);
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop();

}
Logged

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

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Apparently I'm missing something very basic. Where are you getting 192.168.1.102 from? I assuming that's the IP of the Ethernet where are you getting 102?

Is it perhaps that the IP isn't assigned by the router until the code is running on the Ethernet shield? Is that what I am missing?
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 221
Posts: 13853
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

WHat type or router do you have?
Maybe it does only the DHCP addresses ?

Have you tried an IP scanner - http://www.radmin.com/products/ipscanner/ - ?

and - http://www.radmin.com/products/previousversions/portscanner.php - ?
« Last Edit: March 06, 2012, 04:06:22 pm by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, havn't tried any 3rd party IP scanners. I figured if I log into the router and I can't see the device then 3rd party software has no chance of finding it either.

It's a netgear router. I am not home or I would post the model number. It dynamically assignes an IP to any device attached to it(wireless or hardwired). It is possible, however, to make it choose a particular IP but only given the device name.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 148
Posts: 6112
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The dhcp address range is in the LAN settings on the Netgear routers. You can use a static ip assignment outside that range, or use the dhcp client on the shield to get an ip. Don't use any static ip address inside the dhcp range.

For dhcp assigned network settings:
Code:
if(Ethernet.begin(mac) == 0)
{
   Serial.println("No dhcp");
}
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9685
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Apparently I'm missing something very basic. Where are you getting 192.168.1.102 from? I assuming that's the IP of the Ethernet where are you getting 102?

Is it perhaps that the IP isn't assigned by the router until the code is running on the Ethernet shield? Is that what I am missing?

It is very basic. My router is using 192.168.1.1, my laptop is using 192.168.1.3, and another pc is using 192.168.1.101, so for the number in the arduino ip address I can use most any number between 0 and 255 except those in use. I just simply used 102 as it is easy to remember. You can use a number 0-255 as long as another device is not already using it.
Logged

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

Pages: [1]   Go Up
Jump to: