Se a qualcuno interessasse ho trovato la soluzione.
Ho trasformato il mio HTML in PHP.. Arduino manda con il metodo get lo stato delle porte alla pagina PHP, che riceve e si comporta di conseguenza.
Arduino:
#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>
//Creao un array di byte per specificare il mac address
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//creo un array di byte per specificare l'indirizzo ip
byte ip[] = {192,168,49,115}; //modificate questo valore in base alla vostra rete
Servo myservo; // create servo object to control a servo
char Data_RX;
String msg = "";
int AccendiLuci, SpegniLuci, ApriCancello, ChiudiCancello, AccendiVentola, SpegniVentola,check=0,pos=0,l,c,v;
//creao un oggetto server che rimane in ascolto sulla porta
//specificata
EthernetServer ArduinoServer(80);
void setup()
{
//inizializza lo shield con il mac e l'ip
Ethernet.begin(mac, ip);
//inizializza l'oggetto server
ArduinoServer.begin();
//definisco i pin2 e pin3 come uscite
pinMode(2, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
//IMPORTANTE pulisco la variabile msg
msg = "";
EthernetClient pc_client = ArduinoServer.available();
//controllo se pc_client è true
if (pc_client != false)
{
pc_client.println("HTTP/1.1 200 OK");
//imposto il data type
pc_client.println("Content-Type: text/html");
pc_client.println();
//invio codice html
pc_client.print("<html>");
pc_client.print("<head><style type='text/css'>body { font-family: Georgia, serif;color: green; background: #FFFFCC; text-align: center;}</style>");
pc_client.print("</head><body>");
//controllo continuamente che il client sia connesso
while (pc_client.connected())
{
//Controllo se ci sono byte disponibili per la lettura
if (pc_client.available())
{
//leggo i byte disponibili
//provenienti dal client
Data_RX = pc_client.read();
//ricostruisco la stringa ricevuta concatenando i singoli byte
msg += Data_RX;
//Attendo che tutti i byte siano letti
//quando Data_RX contiene il carattere
//di nuova line capisco tutti i byte sono
//stati letti
if (Data_RX == '\n')
{
//cerco all'interno della stringa i parametri che mi interessano
AccendiLuci = msg.indexOf("ledon");
SpegniLuci = msg.indexOf("ledoff");
ApriCancello = msg.indexOf("gateon");
ChiudiCancello = msg.indexOf("gateoff");
AccendiVentola = msg.indexOf("funon");
SpegniVentola = msg.indexOf("funoff");
check=msg.indexOf("check");
//Piloto l'uscita e invio lo stato al browser
if (AccendiLuci >= 0)
{
digitalWrite(7, HIGH);
pc_client.print("<p>LUCI ACCESE</p>");
l=1;
}
if (SpegniLuci >= 0)
{
digitalWrite(7, LOW);
pc_client.print("<p>LUCI SPENTE</p>");
l=0;
}
if(ApriCancello>=0)
{
pc_client.print("<p>CANCELLO APERTO</p>");
c=1;
for(pos = 0; pos < 100; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
if(ChiudiCancello>=0)
{
pc_client.print("<p>CANCELLO CHIUSO</p>");
c=0;
for(pos = 100; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
if(AccendiVentola>=0)
{
digitalWrite(8,HIGH);
pc_client.print("<p>VENTOLA ACCESA</p>");
v=1;
}
if(SpegniVentola>=0)
{
digitalWrite(8,LOW);
pc_client.print("<p>VENTOLA SPENTA</p>");
v=0;
}
if(check>=0)
{
pc_client.print("<meta HTTP-EQUIV='refresh' CONTENT='1; URL=http://127.0.0.1/domotica/pannellocmd.php?l=");
pc_client.print(l,DEC);
pc_client.print("&c=");
pc_client.print(c,DEC);
pc_client.print("&v=");
pc_client.print(v,DEC);
pc_client.print("'>");
}
//aspetto 1 ms affinche la risposta giunga al browser del client
delay(1);
//esco dal ciclo while una volta completato l'invio della risposta
break;
}
}
}
pc_client.print("</body></html>");
//chiudo la connessione
pc_client.stop();
}
//digitalWrite(7, HIGH);
//delay(2000);
}
PHP:
<html>
<head>
<title>Inserire i fogli di stile in un documento</title>
<style type="text/css">
body
{
font-family: Georgia, serif;
color: green;
background: #FFFFCC;
}
</style>
<script type="text/javascript">
function premutoLuci()
{
var elem = document.getElementById('TastoLuci');
var cmd=document.getElementById('LinkLuci');
if(elem.src.indexOf("off.png")>=0)
{
elem.src="on.png";
cmd.href='http://192.168.49.115/ledon';
}
else if(elem.src.indexOf("on.png")>=0)
{
elem.src="off.png";
cmd.href='http://192.168.49.115/ledoff';
}
}
function premutoCancello()
{
var elemC = document.getElementById('TastoCancello');
var cmdC=document.getElementById('LinkCancello');
if(elemC.src.indexOf("off.png")>=0)
{
elemC.src="on.png";
cmdC.href='http://192.168.49.115/gateon';
}
else if(elemC.src.indexOf("on.png")>=0)
{
elemC.src="off.png";
cmdC.href='http://192.168.49.115/gateoff';
}
}
function premutoVentola()
{
var elemV = document.getElementById('TastoVentola');
var cmdV=document.getElementById('LinkVentola');
if(elemV.src.indexOf("off.png")>=0)
{
elemV.src="on.png";
cmdV.href='http://192.168.49.115/funon';
}
else if(elemV.src.indexOf("on.png")>=0)
{
elemV.src="off.png";
cmdV.href='http://192.168.49.115/funoff';
}
}
</script>
<?php
$l = $_GET['l'];
$c = $_GET['c'];
$v = $_GET['v'];
//echo "variabili get inviate ".$v,$l,$c;
?>
</head>
<body bgcolor='black'>
<h2 align='center'>PANNELLO DI CONTROLLO CASA PISCO
<h6 align='center'>© Creato da Piscopiello Italo || v. 10.0.0 Beta
<table align='center'width='250' height='200' border='0' cellspacing='0'>
<tr>
<td COLSPAN='2' align='center'>
<img src='logo.png' >
</td>
<tr>
<td COLSPAN='2' height='30'></td>
<tr>
<td width='100' height='20' ><h5>LUCI </td>
<td align='right'>
<a target='luci' onClick='premutoLuci();' id='LinkLuci' href=''>
<?php
if($l==0)
echo "<img src='off.png' id='TastoLuci' >";
else if ($l==1)
echo "<img src='on.png' id='TastoLuci' >";
?>
</td></a>
<tr>
<td width='100'><h5>CANCELLO </td>
<td align='right'>
<a target='cancello' onclick='premutoCancello();' id='LinkCancello' href=''>
<?php
if($c==0)
echo "<img src='off.png' id='TastoCancello'>";
else if($c==1)
echo "<img src='on.png' id='TastoCancello'>";
?>
</td>
</a>
<tr>
<td width='100'><h5>VENTOLA </td>
<td align='right'>
<a target='ventola' onclick='premutoVentola();' id='LinkVentola' href=''>
<?php
if($v==0)
echo "<img src='off.png' id='TastoVentola'>";
else if ($v==1)
echo "<img src='on.png' id='TastoVentola'>";
?>
</td>
</a>
</table>
</body>
</html>
Grazie comunque a tutti per le risposte..
Ciao
Italo