j'ai fait un programme sur arduino yun pour lire une valeur dans un fichier XML qui est disponible sur un de mes composant domotique.
tout fonctionne bien sauf qu'au bout de 8 jours environ le l'arduino se fige. j'ai toujours acces a la partie administration web mais le programme ne tourne plus.
#include <Bridge.h>//On démarre la librarie Bridge pour communiquer entre Linino et atmega32u4
#include <YunServer.h>//On démarre la librarie YunServer qui démarre le serveur coté linino
#include <YunClient.h>//On démarre la librarie YunClient qui démarre le serveur web coté linino
#include <HttpClient.h>
#include <TextFinder.h>
#include<string.h>
YunServer server;
IPAddress server2(xx,xxx,xxx,xxx);
YunClient client;
const char* pass = "Authorization: Basic xxxxxxxxxxxxxx";
char etat[4];
TextFinder finder( client );
// Pin mapping
const int out1 = 12; // relais
const int sw1 = 2; // bouton
const int sw2 = 3; // bouton
const int sw3 = 4; // bouton
const int sw4 = 5; // bouton
const int sw5 = 6; // bouton
const int sw6 = 8; // bouton
int etat_sw1; // bouton
int etat_sw2; // bouton
int etat_sw3; // bouton
int etat_sw4; // bouton
int etat_sw5; // bouton
int etat_sw6; // bouton
/*-------------------------------------------------------------------------------------
SETUP
-------------------------------------------------------------------------------------*/
void setup() {
Bridge.begin();
Serial.begin(115200);
delay(10);
pinMode(out1, OUTPUT);//on définit le port 13 en sortie
pinMode(sw1, INPUT_PULLUP);//on définit le port 13 en sortie
pinMode(sw2, INPUT_PULLUP);//on définit le port 13 en sortie
pinMode(sw3, INPUT_PULLUP);//on définit le port 13 en sortie
pinMode(sw4, INPUT_PULLUP);//on définit le port 13 en sortie
pinMode(sw5, INPUT_PULLUP);//on définit le port 13 en sortie
pinMode(sw6, INPUT_PULLUP);//on définit le port 13 en sortie
server.listenOnLocalhost(); //On n'accepte que les connexions venant du meme réseau
server.begin();//On lance le seveur
Serial.println ("Hello");
Console.println("Hello");
}
/*-------------------------------------------------------------------------------------
LOOP
-------------------------------------------------------------------------------------*/
void loop() {
xml();
action_xml();
delay(200);
}
/*-------------------------------------------------------------------------------------
ETAT XML
-------------------------------------------------------------------------------------*/
void xml() {
if (client.connect(server2, 50)) { // Connexion au serveur web
//fonction permettant d'effectuer une requete HTTP
Serial.println(" connecting… ");
Console.println("connecting...");
// if (client.connect(server2, 50)) { // Connexion au serveur web
client.println(F("GET /cgi-bin/status.xml HTTP/1.0")); // Demande de flux.xml en HTTP 1.0
//client.println(F("Host: svweb.local")); // Virtual Host
client.println(F("Accept: */*")); // */
// A cause d'un bug de l'ide arduino tout /* d'où avoir son */ associé même dans une chaîne de char
client.println();
client.println();
Serial.println("xml ok");
// Console.println("xml ok");
// On cherche l'attribut temp
if(finder.find("13") ){//vidage ecumeur
finder.getString("<state>","</state>",etat,(4));
//On affiche cette valeur à des fins de débuggage
Serial.print(" Etat " );
Console.println("Etat ");
Serial.println(etat);
}
else{
Serial.print(" Pas de donnees ");
Console.println("Pas de données");
}
}
else {
//si la connection échoue
Serial.println(" connection failed ");
Serial.println(" disconnecting. ");
Console.println(" connection failed ");
Console.println(" disconnecting. ");
client.stop();
}
}
/*-------------------------------------------------------------------------------------
ACTION XML
-------------------------------------------------------------------------------------*/
void action_xml()
{
scanf("%s", etat);//pas de &
if((strcmp(etat,"AON") == 0) || (strcmp(etat,"ON") == 0))
{
// Serial.println("ok");
digitalWrite(out1, HIGH); // Allume la LED
// delay(1000); // Attend une seconde
}
else if((strcmp(etat,"AOF") == 0) || (strcmp(etat,"OFF") == 0))
{
// Serial.println("no");
digitalWrite(out1, LOW); // Éteint la LED
// delay(1000); // Attend une seconde
}
delay(100); // On fait cela toutes les 50 millisecondes
} /code]
Ce qui est incompréhensible c'est que ce fonctionne environ 8 jours avant de planter.