Ethernet shield going nuts?

Hi guys

I’m new with Arduino since a few weeks. I made a few ethernet projects, untill today i got some strange errors.
I’m using an original Arduino Mega and original Ethernet shield and 1 temperature sensor atm.

When printing the IP Address with Ethernet.localIP(), i see random IP addresses like 0.0.224.96, 66.66.0.0, …
For the moment i’m using a project from the Arduino website “Web Client Repeating” for debugging the problems.

When i use wireshark on my local webserver to check the http communication, i see a total a mix of words/syntax i’m sending in random order.
Responses from my webserver are random texts like this: “”(÷ww\aöduino\ynøx!on 1wsgkground-co¹b96e’ ï".
All my webserver is doin is sending a “Bad Request” because of the wrong HTTP-Request syntax.

I tried static ip configuration and DHCP, but results are the same.
I have no idea what could be wrong…
More thinking of the Ethernet Shield is on his way to heaven…

My current code is the following:

#include <SPI.h>
#include <Ethernet.h>
byte mac = {0x90, 0xA2, 0xDA, 0x0D, 0x22, 0xD6};
byte ip = {10,0,0,13};
EthernetClient client;
char server = “10.0.0.2”;
unsigned long lastConnectionTime = 0;
boolean lastConnected = false;
long postingInterval = 5000;
float temp;

void setup() {
Serial.begin(9600);
Ethernet.begin(mac);
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
}
void loop() {
// if there’s incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if there’s no net connection, but there was one last time
// through the loop, then stop the client:
if (!client.connected() && lastConnected) {
Serial.println();
Serial.println(“disconnecting.”);
client.stop();
}

// if you’re not connected, and ten seconds have passed since
// your last connection, then connect again and send data:
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
httpRequest();
Serial.println(Ethernet.localIP());
}
// store the state of the connection for next time through
// the loop:
lastConnected = client.connected();
}
void httpRequest() {
if (client.connect(server, 80)) {
Serial.println(“connecting…”);
client.println(“GET /arduino/index.php?action=storeTemp&value=20&location=kitchen HTTP/1.1”);
client.println(“Host: 10.0.0.2”);
client.println(“User-Agent: arduino-ethernet”);
client.println(“Connection: close”);
client.println();
// note the time that the connection was made:
lastConnectionTime = millis();
}
else {
// if you couldn’t make a connection:
Serial.println(“connection failed”);
Serial.println(“disconnecting.”);
client.stop();
}
}

You haven't assigned the local IP to the card.

majenko: You haven't assigned the local IP to the card.

As configured now, the board is doing DHCP. I see the requests coming to and from my DHCP server.

Forgot to mention: During the tests everything is going nuts, I CAN ping the configured ip address!

Does your ethernet shield have a microSD slot? Do you have a microSD card in the slot?

SurferTim: Does your ethernet shield have a microSD slot? Do you have a microSD card in the slot?

Yes, I was writing a logging interface to SD. Got everything working for that.

The card is still inserted atm.

As configured now, the board is doing DHCP. I see the requests coming to and from my DHCP server.

I took your code and hard coded 192.168.1.4 for the arduino ip address and { 208, 104, 2, 86 } for the server to connect to. The below is what is returned to the serial monitor. Looks like the arduino is trying to connect to itself.

My IP address: 192.168.1.4 connecting... 192.168.1.4 connecting... 192.168.1.4 connecting... 192.168.1.4

zoomkat:

As configured now, the board is doing DHCP. I see the requests coming to and from my DHCP server.

I took your code and hard coded 192.168.1.4 for the arduino ip address and { 208, 104, 2, 86 } for the server to connect to. The below is what is returned to the serial monitor. Looks like the arduino is trying to connect to itself.

My IP address: 192.168.1.4 connecting... 192.168.1.4 connecting... 192.168.1.4 connecting... 192.168.1.4

It's not the IP he is connecting to. Serial.println(Ethernet.localIP()); right after the http-request is there to debug. Output from there is a random LOCAL ip.

SurferTim: Does your ethernet shield have a microSD slot? Do you have a microSD card in the slot?

Tim

Thanx for the tip, i ejected the MicroSD card and everything is back normal. - No more IP changes from the ethernet shield - Correct HTTP headers - Readable responses from my webserver

Is this a known bug? I bought this shield to use the microSD slot AND ethernet capabilities....

You can use both together. I do. You just didn't initialize everything correctly. Here is the setup I use.

void setup() {
  Serial.begin(9600);

  // disable w5100 SPI while starting SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);

  Serial.print("Starting SD..");
  if(!SD.begin(4)) Serial.println("failed");
  else Serial.println("ok");
  // SD.begin() return with its SPI disabled, so nothing need to be done here.

  Serial.print("Starting ethernet..");
  if(!Ethernet.begin(mac)) Serial.println("failed");
  else Serial.println("ok");
  // Ethernet begin returns with its SPI enabled, so disable it.
  digitalWrite(10,HIGH);

  // rest of your setup
}

Now you can read and write to both devices without interference. :) You can use a static ip assignment. I just used that for the example.

SurferTim: You can use both together. I do. You just didn't initialize everything correctly. Here is the setup I use.

void setup() {
  Serial.begin(9600);

  // disable w5100 SPI while starting SD   pinMode(10,OUTPUT);   digitalWrite(10,HIGH);

  Serial.print("Starting SD..");   if(!SD.begin(4)) Serial.println("failed");   else Serial.println("ok");   // SD.begin() return with its SPI disabled, so nothing need to be done here.

  Serial.print("Starting ethernet..");   if(!Ethernet.begin(mac)) Serial.println("failed");   else Serial.println("ok");   // Ethernet begin returns with its SPI enabled, so disable it.   digitalWrite(10,HIGH);

  // rest of your setup }



Now you can read and write to both devices without interference. :)
You can use a static ip assignment. I just used that for the example.

Thank you very much! Problem solved!