I have never done anything with Arduino and Ethernet.
I have plugged in an ethernet shield and my network is on 192.168.2.x
The cable works fine issuing a DHCP address to my laptop.
But my arduino returns 0.0.0.0 in the setup routine (Ethernet.LocalIP()) and does not answer on the configured IP Address. I have chosen some random Mac Addresses incase of unknown conflict.
The Green LED on the Ethernet plug on the shield is lit. And the orange led is flickering so there is life. Also the power led on the ethernet board is lit.
I am using Arduino IDE 1.0.1
I am really not sure what to do?
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDD, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE };
IPAddress ip(192,168,2, 197);
EthernetServer server(80);
void setup()
{
Serial.begin(9600);
Serial.println("Ethernet Begin");
Ethernet.begin(mac, ip);
Serial.println("server");
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop()
{
/* add main program code here */
// Is there any client requests?
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// add a meta refresh tag, so the browser pulls again every 5 seconds:
client.println("<meta http-equiv=\"refresh\" content=\"5\">");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("
");
}
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
}
Any help appreciated.
Chris