I am attempting to build an Arduino based webserver. I am using an Arduino Uno with Ethernet Shield and version 0023 of the IDE. The basic gist of the application is this. Pass a pin value to the Arduino using the address ie: http://10.1.1.8/?pinD2=1 to set digital pin 2 high. The Arduino sees this incoming request, strips the pin and state and acts on them. The server also lists the current status of the analog pins. I know there may be problems with my code below as far as that functionality is concerned, but at this point I can't even get the Arduino to display a webpage. Every browser I've tried just gives me either a connection reset error or an unable to connect error. I tried various things but with no success.
I'm sort of new to the ethernet shield so any input is welcome.
Thanks!
Ben
#if ARDUINO > 18
#include <SPI.h>
#endif
#include <Ethernet.h>
#include <TextFinder.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 1, 1, 8 };
Server server(80);
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
Serial.println("Ready");
}
void loop()
{
Client client = server.available();
if(client) {
TextFinder finder(client);
while (client.connected()) {
if (client.available()) {
int digitalRequests = 0;
int analogRequests = 0;
if (finder.find("GET /")) {
while(finder.findUntil("pin", "\n\r")){
char type = client.read();
int pin = finder.getValue();
int val = finder.getValue();
if( type == 'D') {
Serial.print("Digital Pin ");
pinMode(pin, OUTPUT);
digitalWrite(pin, val);
digitalRequests++;
}
else if( type == 'A'){
Serial.print("Analog Pin ");
analogWrite(pin, val);
analogRequests++;
}
else {
Serial.print("Unexpected Type");
Serial.print(type);
}
Serial.print(pin);
Serial.print("=");
Serial.println(val);
}
}
Serial.println();
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print(digitalRequests);
client.print(" digital pin(s) written");
client.println("
");
client.print(analogRequests);
client.print(" analog pin(s) written");
client.println("
");
client.println("
");
for (int i = 0; i < 6; i++) {
client.print("analog input");
client.print(i);
client.print(" is ");
client.print(analogRead(i));
client.print("
");
}
break;
}
}
delay(1);
client.stop();
}
}