I got this sketch out of an arduino cookbook and tried it but the led is no power is coming out of pin 8. The code is supposed to allow you to press on or off using a computer on your network using your IP and when the on button is pushed the pin 8 is supposed to receive power but its not. I just got the arduino ethernet shield, so I am new to how it works. What I did was, type the sketch in the Arduino IDE and kept it set to Arduino UNO which is the type of board that the Ethernet shield is connected to and I had them both connected when I uploaded the sketch. Was this correct or was I supposed to switch the board type to Arduino Ethernet? Not sure, by the way here is the code:
/*
*WebServerPost sketch
*Turns pin 7 on and off using HTML form
*/
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {0x90, 0xA2, 0xDA, 0x00, 0xD7, 0xD8};
byte ip[] = {192,168,2,8};
const int MAX_PAGENAME_LEN=8;
char buffer[MAX_PAGENAME_LEN+1];
EthernetServer server(80);
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
delay(2000);
}
void loop()
{
EthernetClient client = server.available();
if (client) {
int type = 0;
while (client.connected()){
if (client.available()){
memset(buffer,0, sizeof(buffer));
if(client.find("/"))
if(client.readBytesUntil('/', buffer,sizeof(buffer))){
Serial.println(buffer);
if(strcmp(buffer, "POST") ==0){
client.find("\n\r");
while(client.findUntil("pinD", "\n\r")){
int pin = client.parseInt();
int val = client.parseInt();
pinMode(pin, OUTPUT);
digitalWrite(pin, val);
}
}
sendHeader(client, "Post example");
client.println("<h2>Click buttons to turn pin 8 on or off</h2>");
client.print(
"<form action='/' method='POST'> <p><input type='hidden' name='pinD8'");
client.println(" value='0'><input type='submit' value='OFF'/></form>");
client.print(
"<form action='/' method='POST'><p><input type='hidden' name='pinD8'");
client.print("value='1'><input type='submit' value='On'/></form>");
client.println("</body></html>");
client.stop();
}
break;
}
}
delay(1);
client.stop();
}
}
void sendHeader(EthernetClient client, char *title)
{
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("<html><head><title>");
client.print(title);
client.println("</title><body>");
}