Pages: [1]   Go Down
Author Topic: Implementing the WebClient Sketch from the Arduino-0022 Examples  (Read 1717 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

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

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:
//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

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

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
Logged

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

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?
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: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow. That worked.

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


Thanks
Logged

2nd star on the right
Offline Offline
Jr. Member
**
Karma: 0
Posts: 96
Everything I am is classified under the official secreats act!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Sorry for the noobish post but my knowledge is 10 years out of date!

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

Thank you everyone. A very helpful, useful forum!!
Logged

Pages: [1]   Go Up
Jump to: