no no nessuna interfaccia troppo complessa... ne ho viste moltissime in web quindi credo venga supportato tranquillamente...
[spoiler=Espandi]
/*
Web server preso dall'esempio dell'ide e modificato da me
*/
#include <SPI.h>
#include <Ethernet.h>
#include <WString.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x3A, 0xA3 };
byte ip[] = { 192,168,1,107 };
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
int analogChannel = 5; //pin analogico dell LM35
int ledpinc = 7;
int ledpinb = 8; //pin del led
int ledpin = 9; //pin del led
float tempC = 0; //temperatura in gradi celsius
int ledstatus = 0; //stato del led
int ledstatusb = 0; //stato del led
int Clock = millis();
int IntervalloPing = 5000;//ogni 5 minuti controlla se c'è connessione
int TempoAttesa= 1000; //Attesa ping
void setup()
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
pinMode(analogChannel,INPUT); //input dell' LM35
pinMode(ledpin,OUTPUT); //output del led
pinMode(ledpinb,OUTPUT); //output del led
pinMode(ledpinc,OUTPUT);//output del led
Serial.begin(9600);
}
void loop()
{
EthernetClient client = server.available();
Clock = millis();
/*if (IntervalloPing > millis() - Clock)
{
client.println("POST /Ping");//invia il comando Ping;
client.println();
TempoAttesa = millis();
Serial.println("post");
}
if (TempoAttesa > millis() + 1000) { //impostato a 60 secondi
String readstring;
if (readstring.indexOf("Pong") == 6 ) {
digitalWrite(ledpinc,LOW);
} else {
digitalWrite(ledpinc,HIGH);
}
} */
//leggiamo la temperatura
tempC = (analogRead(analogChannel) * 4.88 * 100)/1024;
// listen for incoming clients
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
String readstring; //stringa per la lettura dal browser
while (client.connected()) {
if (client.available()) {
char c = client.read();
readstring.concat©; //aggiunge c alla stringa;
// 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) {
readstring.concat('\0');
//controllo su seriale
Serial.println("stringa: ");
//Serial.println(readstring);
//Serial.print("indexOf(led=1): ");
//Serial.println(readstring.indexOf("led=1"));
// Serial.print("indexOf(led=0): ");
//Serial.println(readstring.indexOf("led=0"));
if(readstring.indexOf("led=1") == 6){
digitalWrite(ledpin,HIGH);
ledstatus = 1;
Serial.println("LED ON"); //controllo
}
if(readstring.indexOf("led=0") == 6){
digitalWrite(ledpin,LOW);
ledstatus = 0;
Serial.println("LED OFF"); //controllo
}
if(readstring.indexOf("led=4") == 6){
digitalWrite(ledpinb,HIGH);
ledstatusb = 1;
Serial.println("LEDb ON"); //controllo
}
if(readstring.indexOf("led=3") == 6){
digitalWrite(ledpinb,LOW);
ledstatusb = 0;
Serial.println("LEDb OFF"); //controllo
}
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
//Creazione pagina web
client.println("<html><head>");
client.println("<title>Sinottico Allarme DISPAC</title>");
client.println("</head>");
client.println("<body bgcolor=""black"" text=""white"">");
client.println("<h1 align=""center"">Sinottico Allarme DISPAC</h1><hr />");
client.println("<br />");
client.print("Temperatura interna : ");
client.print((int)tempC);
client.println(" C");
client.println("<br /><br />");
client.println("<h3><a href=""/"">Aggiorna Sensore</a></h3>");
client.println("<br />");
client.println("<hr />");
client.println("<br />");
client.print("Comandi LED su pin ");
client.println(ledpin);
client.println("<br />");
client.print("Stato LED :");
if(ledstatus){
client.println("<font color=""green""> Allarme in corso</font>");
}else{
client.println("<font color=""red""> Centrale a riposo</font>");
}
client.println("<br />");
client.println("<h2><a href=""/?led=1"">TEST ALLARME</a> | <a href=""/?led=0"">RESET ALLARME</a></h2>" );
client.println("<br />");
client.println("<hr />");
client.println("<br />");
client.print("Comandi LED su pin ");
client.println(ledpinb);
client.println("<br />");
client.print("Stato LED :");
if(ledstatusb){
client.println("<font color=""green""> ON</font>");
}else{
client.println("<font color=""red""> OFF</font>");
}
client.println("<br />");
client.println("<h2><a href=""/?led=4"">ACCENDI</a> | <a href=""/?led=3"">SPEGNI</a></h2>");
client.println("</body></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(50);
// close the connection:
client.stop();
}
}