Go Down

Topic: Implementing the WebClient Sketch from the Arduino-0022 Examples (Read 2105 times) previous topic - next topic

impresario

I just got my Ethernet shield and am trying to get something to work. I am entering the shield's MAC address into the script. Not sure which IP address to enter. I tried my Router's IP (198.1.168.1), various addresses within the supported range (198.168.100 - 149) and even the external IP from the ISP. All I ever get on the monitor is "connecting ...", "connection failed" and "disconnecting."

Any ideas what I'm doing wrong?

zoomkat

Quote
Any ideas what I'm doing wrong?


In the forum it is generally needed for you to post the code that does not work for you to see if it has issues. If you have a w5100 based ethernet shield you could try the below simple client code. The "my Router's IP (198.1.168.1)" is most probably incorrect (198.168.1.1 is typical). Once you load your code into the arduino, you can log into your router to see if the arduino is recgnized by the router.

Code: [Select]

//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(;;);
  }
}

Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

impresario

Thank you for your advice on the use of the forum. As you can see I'm new at it.

you are right about the router IP address. I made a typo in the post, not the sketch. It is 192.168.1.1

I used your sketch and altered only the following:

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x50, 0xDD };
byte ip[] = { 192, 168, 1, 1 }; // Arduino IP address

I still get a connection failed message. I'm not suere where to look for an Arduino entry in my router info. The DHCP active IP table doesn't show the Arduino's MAC

zoomkat

Your arduino IP address has to be different from your router IP address. Just try the code I posted unchanged and see if it works. What brand of router do you have?
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

impresario

Wow. That worked.

I use a LinkSys WRT54G router. Can't find any reference to my Arduino in it


Thanks

AJB2K3

192.168.1.1 is often grabbed by the modem router.
try 192.168.1.100.

if this is an ip issue, download and install wireshark and look at the output.
Sorry for the noobish post but my knowledge is 10 years out of date!

impresario


Go Up