Salve a tutti come al solito confido nella vostra bontà e volontà di aiutarmi, circa un anno e mezzo fa ho modificato uno skecht per sostituire la centralina del telecomando con un sistema per aprire il cancello da smartphone. intanto vi dico che sto usando un arduino ethernet originale, nel progetto ho creato la possibilità di aprire un cancello automatico, chiudere un cancello automatico, accendere le luci esterne, aprire il cancelletto pedonale ed infine sapere la posizione del cancello realmente. il mio problema è che ogni due o tre giorni devo riavviare arduino perchè si pianta e non posso fare più nulla, allora devo riavviarlo fisicamente. ho provato varie soluzioni lette in rete ma senza nessun risultato, ho letto di provare il watch dog 8 secondi ma non ha funzionato, poi ho letto di metter i pin 4 e 10 in high ma senza avere risultati positivi, potete aiutarmi per favore?
posto il codice e magari può essere di aiuto a qualcun’ altro… grazie a tutti
#include <SPI.h>
#include <Ethernet.h>
boolean statop1 = true;
boolean statop2 = true;
boolean statop3 = true;
boolean statop4 = true;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 100}; // ip in lan
byte gateway[] = { 192, 168, 1, 254}; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
int val = 0;
//////////////////////
void setup() {
pinMode(10, OUTPUT);
pinMode(7, OUTPUT); //apertura cancello parcheggio
pinMode(6, OUTPUT); //chiusura cancello parcheggio
pinMode(5, OUTPUT); //accensione luci esterne
pinMode(4, OUTPUT); //apertura cancello pedonale
pinMode(3, INPUT); //posizione cancello
digitalWrite(10, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
readString = "";
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
}
void loop() {
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
val = digitalRead(3);
///////////////
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<!DOCTYPE html><html><head><TITLE>TELECOMANDO SMARTPHONE CANCELLO </TITLE></HEAD><BODY><H1>TELECOMANDO SMARTPHONE CANCELLO</></H1><hr>
<ul><li><p align=\"left\">CANCELLO PARCHEGGIO:<a href=\"/?light1on\">APERTURA</a></li></p>
<li><p align=\"left\">CANCELLO PARCHEGGIO:<a href=\"/?light2on\">CHIUSURA</a></li></p>
<li><p align=\"left\">LUCI ESTERNE:<a href=\"/?light3on\">ACCENSIONE</a></li></p>
<li><p align=\"left\">CANCELLO PEDONALE:<a href=\"/?light4on\">APERTURA</a></li></p>
<li><p align=\"left\">POSIZIONE CANCELLO </HTML>");
if (val == false)
client.print("<input type=\"3\" value=\"CHIUSO\">");
else
client.print("<input type=\"3\" value=\"APERTO\">");
delay(1);
//stopping client
client.stop();
if (readString.indexOf("?light1off") > 0) //checks for on
{
statop1 = true;
}
if (readString.indexOf("?light1on") > 0) //checks for off
{
statop1 = false;
}
if (readString.indexOf("?light2off") > 0) //checks for on
{
statop2 = true;
}
if (readString.indexOf("?light2on") > 0) //checks for off
{
statop2 = false;
}
if (readString.indexOf("?light3off") > 0) //checks for on
{
statop3 = true;
}
if (readString.indexOf("?light3on") > 0) //checks for off
{
statop3 = false;
}
if (readString.indexOf("?light4off") > 0) //checks for on
{
statop4 = true;
}
if (readString.indexOf("?light4on") > 0) //checks for off
{
statop4 = false;
}
if (statop1 == true)
{
digitalWrite(7, HIGH);
}
if (statop1 == false)
{
digitalWrite(7, LOW);
digitalRead(statop1 = true);
delay(500);
digitalWrite(7, HIGH);
}
if (statop2 == true)
{
digitalWrite(6, HIGH);
}
if (statop2 == false)
{
digitalWrite(6, LOW);
digitalRead(statop2 = true);
delay(500);
digitalWrite(6, HIGH);
}
if (statop3 == true)
{
digitalWrite(5, HIGH);
}
if (statop3 == false)
{
digitalWrite(5, LOW);
digitalRead(statop3 = true);
delay(500);
digitalWrite(5, HIGH);
}
if (statop4 == true)
{
digitalWrite(4, HIGH);
}
if (statop4 == false)
{
digitalWrite(4, LOW);
digitalRead(statop4 = true);
delay(500);
digitalWrite(4, HIGH);
}
delay(1);
client.flush();
client.stop();
//clearing string for next read
readString = "";
}
}
}
}
}