Bonjour à tous,
Je viens de débuter mon tout premier projet arduino et après avoir un peu galéré, j'arrive à peu de chose prêt au résultat escompter. Voici ma problématique sommaire :
Ma maison est équipée de deux climatisation air/air pouvant chacune être contrôlée par une télécommande IR. Problème, il n'est pas possible de gérer la température en fonction du jour et de l'heure de la journée comme le fait un thermostat standard.
En cherchant sur le net, j'ai trouvé ceci dont je me suis majoritairement servi:
Voici le code en question :
#include <String.h>
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include "IRremote.h"
#include <DHT.h>
#include <NTPClient.h>
#include <TimeLib.h>
/*
controllare un condizionatore via web
con sensori di temperatura e umidità
ARDUINO UNO - limitato
Mega o Leonardo
ETHERNET SHIELD
DHT22, IR led
*/
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // mac address
byte ip[] = { 192, 168, 1, 135 }; // ip arduino internet in
//byte gateway[] = { 192, 168, 1, 254 }; // internet access via router
//byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
IRsend irsend;
int khz = 38; //NB Change this default value as neccessary to the correct modulation frequency
// OFF - AC
unsigned OFF[] = {};
// ON Warm at 17°C FAN-min
unsigned WARM_low[] = {};
// ON Warm 20°C FAN-min
unsigned WARM_high[] = {};
// ON cool 25°C FAN-auto - AC
unsigned COOL[] = {};
boolean week = false;
#define DHTPIN 2 // PIN data of DHT22
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);
int irPin = 9; // pin IR led
String readString; //string
boolean COOL_ON = false; // flag status Cooling
boolean WARM_high_ON = false; // flag status Warming at 20°C
boolean WARM_low_ON = false; // flag status Warming at 18°C
EthernetUDP Udp;
unsigned int localPort = 8888; // local port to listen for UDP packets
NTPClient timeClient(Udp, "europe.pool.ntp.org", 3600, 60000);
void setup() {
Serial.begin(115200);
pinMode(irPin, OUTPUT);
dht.begin();
Serial.println("Démarrage du thermostat");
Ethernet.begin(mac, ip);
Serial.println(Ethernet.localIP());
Udp.begin(localPort);
timeClient.begin();
}
void loop() {
timeClient.update();
float t = dht.readTemperature(); // Value of Temp
float h = dht.readHumidity(); // Value of Humidity
EthernetClient client = server.available();
Serial.print("Il est : ");
Serial.println(timeClient.getFormattedTime());
Serial.print("Il fait : ");
Serial.print(t);
Serial.println("°C");
if (prez() == true){ //pendant les heures de présence
Serial.println("période de présence à la maison");
if (t < 19){ // si la température est inférieur à 19°C on chauffe à 20°C
irsend.sendRaw(WARM_high, sizeof(WARM_high) / sizeof(int), khz);
reset_status;
WARM_high_ON = true;
Serial.println("il fait moins de 19°C le chauffage est en route");
}
else if (t > 23){ // si la température est supérieur à 26°C on refroidit jusqu'à 25°C
irsend.sendRaw(COOL, sizeof(COOL) / sizeof(int), khz);
reset_status;
COOL_ON = true;
Serial.println("il fait plus de 26°C la climatisation est en route");
}
else {
irsend.sendRaw(OFF, sizeof(OFF) / sizeof(int), khz);
reset_status;
Serial.println("la température est idéale");
}
}
else {
Serial.println("période de repos");
if (t < 16){ // si la température est inférieur à 17°C on chauffe à 17°C
irsend.sendRaw(WARM_low, sizeof(WARM_low) / sizeof(int), khz);
reset_status;
WARM_low_ON = true;
Serial.println("il fait moins de 16°C le chauffage est en route");
}
else {
irsend.sendRaw(OFF, sizeof(OFF) / sizeof(int), khz);
reset_status;
Serial.println("la température est idéale");
}
}
// COSTRUZIONE PAGINA HTML
client.println("HTTP/1.1 200 OK.....");
client.println("Content-Type: text/html");
client.println();
// inizializzo pagina (da togliere se uso ajax)
client.print("<html><head><title>MoniCris AC</title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' ></head><body>");
//iniza il body
client.println("<div style='width:960px; height:1136px;'>"); //risoluzione per nokia 5800 640x360, iPhone4 960x640 pixel, iPhone5 1136x640
client.println("<h1>Home STATUS</h1><hr />");
//Scrive sul browser il valore del termistore
client.println("<p>TEMPERATURE = ");
client.print(t);
client.println(" *C
</p>");
//Scrive sul browser il valore della fotoresistenza
client.println("<p>HUMIDITY = ");
client.print(h);
client.println(" %
</p>");
client.println("<p>TIME = ");
client.println(timeClient.getFormattedTime());
client.println("
</p>");
// link per aggiornare pagina e valori
client.print("<h2>Refresh: <a href=''>CHECK</a></h2><hr />");
client.println("<h1>AC CONTROL</h1>");
//scrivo il AC status
client.print("<font size='5'>Status: ");
if (WARM_high_ON) {
client.println("<span style='color:green; font-weight:bold;'>WARM_high_ON</span></font>");
}
else if (WARM_low_ON) {
client.println("<span style='color:green; font-weight:bold;'>WARM_low_ON</span></font>");
}
else if (COOL_ON) {
client.println("<span style='color:green; font-weight:bold;'>COOL</span></font>");
}
else {
client.println("<span style='color:grey; font-weight:bold;'>OFF</span></font>");
}
client.print("<h2><a href='/?L=1'> WARM_high_ON </a> | <a href='/?L=0'> WARM_low_ON </a> | <a href='/?L=0'> OFF </a> | <a href='/?L=2'> COOL </a></h2>");
//semnătura ;)
client.println("<hr />");
client.print("<h4>MoniCris Home Project 2015</h4>");
client.println("<hr />");
// chiudo il div
client.println("</div>");
// chiudo pagina da togliere se uso ajax
client.println("</body></html>");
// pulisco la stringa per la successiva lettura
readString = "";
//fermo il client
client.stop();
delay(10000);
}
bool prez(){
//Heure de nuit, absence de la maison
if (timeClient.getHours() >= 23 || timeClient.getHours() <= 6){
return false;
}
else if (timeClient.getHours() <= 7) {
if (timeClient.getDay() == 1 || timeClient.getDay() == 7){
return false; //absence avant 7h00 les jours de we
}
else {
return true; // présence entre 7h00 les jours de semaine
}
}
//Gestion de la semaine
if (timeClient.getDay() > 1 && timeClient.getDay() < 7){
if ( timeClient.getHours() >= 7 && timeClient.getHours() <= 18){
return false; //absence de la journée entre 7h00 et 18h00
}
else {
return true; //présence du soir entre 18h et 22h59
}
return true; //présence les jours de we de 7h00 à 22h59
}
}
void reset_status()
{
COOL_ON = false;
WARM_low_ON = false;
WARM_high_ON = false;
}
Mes problèmes aujourd'hui sont qu'avec le montage réalisé dans sur ce site :
- j'ai besoin d'être à 1 ou 2m de la clim pour qu'elle reçoive le signal.
- j'ai besoin d'être à coté d'une prise ethernet pour synchroniser l'heure du arduino et pouvoir y accéder depuis une interface web
Mon idée serait d'utiliser un esp8266. Le problème est que mon programme consomme 24322 octets de stockage et 5557 octets de ram. Mes questions sont donc les suivantes :
- est il possible d'optimiser mon code pour qu'il tienne sur un esp8266 ?
- est il possible de contrôler les cartes wifi depuis un arduino brancher en ethernet ? Si oui comment ?
Question subsidiaire, j'observe un valeur erroné de la température avec mon dht22. Le capteur donne une température environ 2° plus élevée que la réalitée. Une idée d'où cela peut venir
