Bonjour tous le monde. Je me suis adapté un petit bout de code trouvé sur internet pour me mettre au point une sorte de multiprise commandé par internet par le biais d'une page web hébergé par mon arduino.
Mais un souci ce pose, j'active ou désactive mes sorties par le biais d'un formulaire sur internet. Tout fonctionne très bien, cependant au bout d'un certains temps (1heures ou même plusieurs heures) aléatoire, toutes mes sorties repassent a l'état 0. De ou cela peut il provenir ?
Avec ma page web ouverte ou fermé (page hébergé sur l'arduino)
Voici mon code :
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
/*
Gestion Carte 4 Relais
avec un serveur Web Arduino
Materiel:
* Arduino UNO
* Arduino Ethernet shield
* Carte 4 Relais
*/
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //Adresse MAC
byte ip[] = { 192, 168, 0, 99 }; // Adresse IP
EthernetServer server(80); //Port du serveur
int ledPin1 = 3; // LED pin
int ledPin2 = 2; // LED pin
int ledPin3 = 5; // LED pin
String readString = String(30); //string for fetching data from address
boolean LEDON1 = false; //Pin status flag
boolean LEDON2 = false; //Pin status flag
boolean LEDON3 = false; //Pin status flag
void setup(){
//start Ethernet
Ethernet.begin(mac, ip);
//Configurer les 3 Pins de sorties
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
//Activer la liaison de données Serie
Serial.begin(9600); }
void loop(){
//Créer la connection Client
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() < 30) {
//store characters to string
readString += c; }
//output chars to serial port
Serial.print(c);
//if HTTP request has ended
if (c == '\n') {
//lets check if LED should be lighted
//Controle Prise 1
if(readString.indexOf("L=1")>0) {
//Pin mise a ON
digitalWrite(ledPin1, LOW); // Mettre la Pin a ON
LEDON1 = true;
}else{
//Pin mise a OFF
digitalWrite(ledPin1, HIGH); /// Mettre la Pin a OFF
LEDON1 = false; }
//Controle Prise 2
if(readString.indexOf("L1=2")>0) {
//Pin mise a ON
digitalWrite(ledPin2, LOW); // Mettre la Pin a ON
LEDON2 = true;
}else{
//Pin mise a OFF
digitalWrite(ledPin2, HIGH); // Mettre la Pin a OFF
LEDON2 = false; }
//Controle Prise 3
if(readString.indexOf("L2=3")>0) {
//Pin mise a ON
digitalWrite(ledPin3, LOW); // Mettre la Pin a ON
LEDON3 = true;
}else{
//Pin mise a OFF
digitalWrite(ledPin3, HIGH); // Mettre la Pin a OFF
LEDON3 = false; }
// now output HTML data starting with standart header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
//Controle Relais par checkbox
client.println("<h1>Gestion des prises</h1>");
client.println("<form method=get name=Prise><input type=CHECKBOX name=L value=1>Prise 1
");
client.println("
");
client.println("<input type=CHECKBOX name=L1 value=2>Prise 2
");
client.println("
");
client.println("<input type=CHECKBOX name=L2 value=3>Prise 3
<input type=submit value=submit></form>");
client.println("
");
//Afficher statut prise 1
client.print("<font size='5'>Prise 1: ");
if (LEDON1)
client.println("<size='5'>ON
");
else
client.println("<size='5'>OFF
");
client.println("</body></html>");
//Afficher statut prise 2
client.print("<font size='5'>Prise 2: ");
if (LEDON2)
client.println("<size='5'>ON
");
else
client.println("<size='5'>OFF
");
client.println("</body></html>");
//Afficher statut prise 3
client.print("<font size='5'>Prise 3: ");
if (LEDON3)
client.println("<size='5'>ON
");
else
client.println("<size='5'>OFF
");
client.println("</body></html>");
//Effacer la chaine pour lecture suivante
readString="";
//Arreter le client
client.stop();
}}}}}
Merci a tous de m'avoir lu, j'espere avoir été assez clair.
Bonne soirée.