#include <DHT.h>
#include <ds18b20p.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Udp.h>
#include <Stdio.h>
#include <LiquidCrystal.h>
#include <Ultrasonic.h>
//ASSIGNEMENT PIN/////////////////////////////////////
int LED_RESEAU = 11; //LED RESEAU
int LED_TRAVAIL = 12; //LED TRAVAIL
int TEMP1_PIN = 30; //TEMPERATURE 1 -- DIGITAL
int TEMP2_PIN = 34; //TEMPERATURE 2 -- DIGITAL
int TEMP3_PIN = 38; //TEMPERATURE EAU -- DIGITAL
int TEMP4_PIN = A2; //TEMPERATURE INTERNE
int TEMP5_PIN = 26; //TEMPERATURE EXTERNE
int HYDRO1_PIN = 22; //HYGRO 1 -- DIGITAL
int LUM_PIN = A0; //LUMIERE -- ANALOGIQUE
int CO2_PIN = A1; //CO2
Ultrasonic ultrasonic(8,9);
LiquidCrystal lcd(7,6,10, 5, 4, 3, 2);
int rel0 = 23; // EXTRACTION
int rel1 = 25; // BRUMISATEUR
int rel2 = 27; // BRASSAGE
int rel3 = 29; // CO2
int rel4 = 31; // POMPE EAU
int rel5 = 33; // POMPE AIR
int rel6 = 35; // EXTRACTION LAMPE
int rel7 = 37; // EXTRACTION MODULE
//VARIABLES DIVERS
int cmd;
float val1;
float val2;
int isInitialised = 0;
int tentativeHttp;
byte remoteIp[4]; // holds received packet's originating IP
unsigned int remotePort; // holds received packet's originating port
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
float isJour1;
//VARIABLES CONSTANTES
float co2;
float temp1;
float temp2;
float temp3; // EAU
float temp4; // INTERNE
float temp5; // EXTERNE
float hygro1;
float nivEau;
//VARIRABLES MINI MAXI
float temp1_min = 18;
float temp1_max = 29;
float temp2_min = 18;
float temp2_max = 29;
float temp3_min = 0; // EAU
float temp3_max = 100; // EAU
float temp4_min = 0; // INTERNE
float temp4_max = 35; // INTERNE
float co2_min = 900;
float co2_max = 2000;
float hygro1_min = 40;
float hygro1_max = 80;
//VARIRABLES INTERVAL
long interval_refresh = 30000;
long currentMillis_refresh;
long previousMillis_refresh;
long timerBrassage = 900000;
long currentMillis_timerBrassage;
long previousMillis_timerBrassage;
long timerPompeEau = 900000;
long currentMillis_timerPompeEau;
long previousMillis_timerPompeEau;
long timerPompeAir = 900000;
long currentMillis_timerPompeAir;
long previousMillis_timerPompeAir;
long timerExtraction = 1800000;
long currentMillis_timerExtraction;
long previousMillis_timerExtraction;
//VARIAVLES ETATS DES RELAIS PAR DEFAUT
int etatRel0 = LOW;
int etatRel1 = LOW;
int etatRel2 = LOW;
int etatRel3 = LOW;
int etatRel4 = LOW;
int etatRel5 = LOW;
int etatRel6 = LOW;
int etatRel7 = LOW;
//VARIABLE DU MODE (AUTO ou MANUEL)
int mode = 0; // 0 = AUTO 1 = MANUEL
//CAPTEUR HUMIDITE
#define DHTTYPE DHT11
DHT dht1(HYDRO1_PIN, DHTTYPE);
//CAPTEUR TEMPERATURE
DS18B20P ds18b20p_temp1;
DS18B20P ds18b20p_temp2;
DS18B20P ds18b20p_temp3;
DS18B20P ds18b20p_temp5;
//VARIRABLES ETHERNET ( MAC, IP LOCAL, GATEWAY, SUBNET, SERVEUR DISTANT
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {
192,168,1,39 };
byte gateway[] = {
192,168,1,254 };
byte subnet[] = {
255,255,255,0 };
byte server[] = {
188,***,***,*** };
unsigned int localPort = 8080; // local port to listen on
void(* resetFunc) (void) = 0;
void setup(){
//ON DEMARRE LE PORT SERIE + LCD + MESSAGE
lcd.begin(20,4);
Serial.begin(9600);
lcd.setCursor(0, 0);
lcd.print("- Demarrage module");
Serial.println("- Demarrage module");
delay(1000);
lcd.setCursor(0, 1);
lcd.print("- Ethernet 15");
Ethernet.begin(mac, ip, gateway, subnet);
delay(500);
Udp.begin(localPort);
Serial.println("Connection Ethernet...");
for (int i=0;i<=15;i++){
lcd.setCursor(11, 1);
lcd.print(15-i);
lcd.print(" ");
delay(1000);
}
//ON OUVRE LA CONNECTION ETHERNET
lcd.setCursor(0, 2);
lcd.print("- Relais ON");
//ON ASSIGNE LES PINS ET ETATS
pinMode(LED_RESEAU, OUTPUT);
digitalWrite(LED_RESEAU, HIGH);
pinMode(LED_TRAVAIL, OUTPUT);
digitalWrite(LED_TRAVAIL, HIGH);
pinMode(rel0, OUTPUT);
digitalWrite(rel0, etatRel0); //RELAIS n°1
pinMode(rel1, OUTPUT);
digitalWrite(rel1, etatRel1); //RELAIS n°2
pinMode(rel2, OUTPUT);
digitalWrite(rel2, etatRel2); //RELAIS n°3
pinMode(rel3, OUTPUT);
digitalWrite(rel3, etatRel3); //RELAIS n°4
pinMode(rel4, OUTPUT);
digitalWrite(rel4, etatRel4); //RELAIS n°5
pinMode(rel5, OUTPUT);
digitalWrite(rel5, etatRel5); //RELAIS n°6
pinMode(rel6, OUTPUT);
digitalWrite(rel6, etatRel6); //RELAIS n°7
pinMode(rel7, OUTPUT);
digitalWrite(rel7, etatRel7); //RELAIS n°8
delay(1000);
lcd.setCursor(0, 3);
lcd.print("- Capteurs ON");
//ON DEMARRE LES CAPTEURS D HUMIDITE
dht1.begin(); //HYGRO 1
//ON DEMARRE LES CAPTEURS DE TEMPERATURE
ds18b20p_temp1.begin( TEMP1_PIN ); // TEMP 1
ds18b20p_temp2.begin( TEMP2_PIN ); // TEMP 2
ds18b20p_temp3.begin( TEMP3_PIN ); // TEMP EAU
ds18b20p_temp5.begin( TEMP5_PIN ); // TEMP EXTERNE
delay(1000);
if(sendCMD("cmd=init") == true){
isInitialised = 1;
}else{
tentativeHttp = 1;
lcd.setCursor(11, 1);
lcd.print("ERREUR");
}
delay(1500);
}