Hi there , after hundreds of google searches a cant find a simple straight forward answer to my problem.
I am making a home automation controller , have written al the code for that and all is good, then i thought it would be great to have controll over internet so i now have a freetronics etherten board it has the wiznet chip etc so practically an arduino board with an arduino ethernet shield all in one.
I have successfully been able to do a few of the examples in the ethernet librarys.
I want the arduino to be the server etc , i dont want to have it interfacing with this that and the next thing.
I have included the code of basically the server example below but with a button , could someone please show me how to change the code so when that button is pressed in the browser, maybe changes the state of an led conected to pin 4 of the arduino.
Then i think i would be able to figure the rest out.
Any help will be greatly apreciated.
cheers , corey
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,1, 177 };
Server server(80);
void setup()
{
Ethernet.begin(mac, ip);
server.begin();
}
void loop()
{
// listen for incoming clients
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
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();
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(analogRead(analogChannel));
client.println("
");
}
client.print(""); // this is the button i want to change the state of led
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();
}
}