Go Down

Topic: (solved) Arduino Uno + Ethenet Shield = Broken ??? (Read 877 times) previous topic - next topic

xens

Jan 28, 2012, 04:52 pm Last Edit: Jan 29, 2012, 08:41 pm by xens Reason: 1
Hi there,

just received my Ethernet shield yesterday and I think it may be broken, here's my setup:

- Arduino UNO
- Ethernet Shield R3 (mac: 90-A2-DA-00-E4-4B
- laptop: 192.168.1.123/24 <- apache is running on it
- Arduino: 192.168.1.2/24

The shield is directly cabled to my laptop with a cross-over cable I can successfully ping the arduino from the PC.

I tried the examples that came with the Ethernet library but none on them worked so I used a "debug" program.

here it is:

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

byte mac[] = {  0x90, 0xA2, 0xDA, 0x00, 0xE4, 0x4B };
byte ip[] = { 192,168,1,2 };
byte subnet[] = { 255, 255, 255, 0 };
byte gateway[] = { 192,168,1,1 };
byte server[] = { 192,168,1,123 };

EthernetClient client;

void setup() {
 Ethernet.begin(mac, ip, subnet, gateway);
 Serial.begin(9600);

 delay(1000);

 if (!client.connect(server, 80))
   Serial.println("Cannot connect to IP !");
   
 else
    Serial.println("connected to IP !");
}

void loop()
{
 client.println("GET / HTTP/1.0");
 delay(5000);
}
#########

When I check the logs from the apache server I receive a lots of garbage before the "GET / HTTP/1.0" sentence.

here's the apache output:

error.log:
[Sat Jan 28 16:46:43 2012] [error] [client 192.168.1.2] request failed: error reading the headers

access.log:
192.168.1.2 - - [28/Jan/2012:16:47:49 +0100]
"Z\xfa[\x9c1\x04\xa1{M\x06#\x8be\xb0\x10\xe9i:\xfd_\x94vI\\\\Tu\xc8@\xa5\xfa\xbf52\xeeD\x06ig\xa0\xb5n\b@\xec\x10\xd9\xf8k\xd5\xcd<\xdc\xc6\xde\xd7\x0f\x13\xc4\x02\x9c\xeb\xd9dwM\x8b}\xd5\x94T\xf4\t\x94G\x02\x88\xa2=\x8a\x03\xc5\xc0,\xc4\xbe\xd1\x83\x92\xe2\xa5\xcb\x84|\xc7,\x859Ys\xbce\xc5\xc3w>\x02=\xda\x0f\x05\x01\x80\x93e\xecn;\xc5\x84\x9f\xdd\xcb\xef\xb3\xf1$\xf7\x85\x98=0*\x8a\xcd"
400 301 "-" "-"

The problem is the same if the arduino act as server, the client that connects to it also get the garbage and is unable to parse the request.

H.E.L.P ;)

Thanks

Romain

SurferTim

#1
Jan 28, 2012, 04:59 pm Last Edit: Jan 28, 2012, 05:09 pm by SurferTim Reason: 1
That code will cause challenges. There is an empty line required on the request, and you should read the response from the server.
Code: [Select]
void loop()
{
 client.println("GET / HTTP/1.0");
 delay(5000);
}


Search the forum for web client code by zoomkat. He has both client and server code working pretty good with V1.0.

Edit: If you continue to have problems with garbage on both serial and ethernet, maybe this subject will help:
http://arduino.cc/forum/index.php/topic,88392.0.html

You may as well go to that subject right away. zoomkat's client code is there too!

xens

Thanks SurferTim for the quick reply !

I tried with the zoomcat code and I have the same problem, here's the code I used

####
//zoomkat 12-08-11
//simple client test
//for use with IDE 1.0
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields

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

byte mac[] = {  0x90, 0xA2, 0xDA, 0x00, 0xE4, 0x4B };
byte ip[] = { 192,168,1,2 };
byte subnet[] = { 255, 255, 255, 0 };
byte gateway[] = { 192,168,1,1 };
byte myserver[] = { 192,168,1,123 };



EthernetClient client;
//////////////////////

void setup(){

  Ethernet.begin(mac, ip);
  //Ethernet.begin(mac, ip, subnet, gateway);
  Serial.begin(9600);
  Serial.println("Better client test 12/01/11"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  } 
}

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

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(myserver, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text
    client.println(); //end of get request
  }
  else {
    Serial.println("connection failed"); //error message if no client connect
    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(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor
  }

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

}
####

I still receive the garbage on my server AND on the serial line:

Better client test 12/01/11
Send an e in serial monitor to test
connected
¿??º8 «?¨X

I tried to deactivate the SPI interface

  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

But the problems remains !

Romain

xens

Ok I got it !

http://code.google.com/p/arduino/issues/detail?id=605&start=200

Thanks a lot

Romain  :smiley-mr-green:

Go Up