Ciao a tutti, ho un piccolo problema con il mio progetto.
In pratica , sto utilizzando una ethernet shield, nella pagina html , utilizzo 2 ceckbox e un bottone di invio , che mi permette di eccitare un rele o 2 relè.
Tutto ok, ma se faccio eccitare i relè, chiudo il browser , e lo riapro accedendo di nuovo nella scheda i rele tornano allo stato iniziale.
Qualche soluzione in merito?
vi posto il mio codice sotto
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; //physical mac address
byte ip[] = { 192, 168, 0, 177}; // ip in lan
byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
int ledPin = 9;
int ledPin2 = 8;
String readString;
boolean LEDON = false;
boolean LEDON2= false;
void setup(){
Ethernet.begin(mac, ip, gateway, subnet);
pinMode(ledPin, OUTPUT);
pinMode(ledPin2,OUTPUT);
Serial.begin(9600);
}
void loop(){
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
readString.concat(c);
if (c == '\n' && currentLineIsBlank) {
Serial.print(readString);
if(readString.indexOf("L=1") > 0) {
digitalWrite(ledPin, HIGH);
LEDON = true;
}else{
digitalWrite(ledPin, LOW);
LEDON = false;
}
if(readString.indexOf("L=2") > 0) {
digitalWrite(ledPin2, HIGH);
LEDON2 = true;
}else{
digitalWrite(ledPin2, LOW);
LEDON2 = false;
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("<html><head><title>ARDUINO Controllo Led via WEB</title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' ></head><body>");
client.println("<h1>LED CONTROL by internet connection</h1>");
client.println("<hr />");
client.println("<h1>LED control</h1>");
client.println("<form method=get name=LED><input type=checkbox name=L value=1>LED
<form method=get name=LED2><input type=checkbox name=L value=2>LED2
<input type=submit value=submit></form>");
client.println("
");
client.print("<span>LED status: </span>");
if (LEDON) {
client.println("<span style='color:green'>ON</span>");
}
else
{
client.println("<span style='color:red'>OFF</span>");
}
client.println("
");
client.print("<span>LED2 status: </span>");
if (LEDON2) {
client.println("<span style='color:green'>ON</span>");
}
else
{
client.println("<span style='color:red'>OFF</span>");
}
client.println("</body></html>");
readString="";
//stopping client
client.stop();
}
}
}
}
}