| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- //Ajouter de la formule de calcul des quantité :
- Q=Q+((Q/M)*Vc - Q)/2
- avec
- Q Quantité
- M nouvelle mesure
- Vc valeur cible
- /* Comment this out to disable prints and save space */
- //#define BLYNK_PRINT Serial
- //#include <ESP8266WiFi.h>
- #include <BlynkSimpleEsp8266.h>
- #include <TimeLib.h>
- #include <WidgetRTC.h>
- // You should get Auth Token in the Blynk App.
- // Go to the Project Settings (nut icon).
- char auth[] = "5I28lN8RWcLQLvaoRyv0RNuiuBVwy99K";
- // Your WiFi credentials.
- // Set password to "" for open networks.
- char ssid[] = "Livebox-7C2C";
- char pass[] = "566C61F61F9C925C9F3D7D79E6";
- WidgetRTC rtc;
- BlynkTimer timer;
- //************************************************************************
- // Variable Global perso
- //************************************************************************
- #define POMPE1 0
- #define POMPE2 1
- #define POMPE3 2
- #define POMPE4 3
- #define FACTEURML 635
- #define INTER24H 1
- #define INTER12H 2
- #define INTER6H 3
- int inter1, inter2, inter3, inter4;
- const int PINPOMPE1 = 16;
- const int PINPOMPE2 = 5;
- const int PINPOMPE3 = 4;
- const int PINPOMPE4 = 0;
- float ML1 = 0.0;
- float ML2 = 0.0;
- float ML3 = 0.0;
- float ML4 = 0.0;
- float nbMLTest = 2.0;
- bool AUTO1 = false;
- bool AUTO2 = false;
- bool AUTO3 = false;
- bool AUTO4 = false;
- #define H1 0*60
- #define H2 6*60
- #define H3 12*60
- #define H4 18*60
- //************************************************************************
- // Fonction
- //************************************************************************
- void Active1(float ml) {
- if (AUTO1) {
- char message[30];
- digitalWrite(PINPOMPE1, LOW);
- delay(FACTEURML * ml);
- digitalWrite(PINPOMPE1, HIGH);
- Serial.print("Distribue pompe1 : ");
- Serial.print(ml);
- Serial.println("ml");
- sprintf(message, "Distribution %.1fml de calcium", ml);
- //Blynk.notify(message);
- }
- }
- void Active2(float ml) {
- if (AUTO2) {
- char message[30];
- digitalWrite(PINPOMPE2, LOW);
- delay(FACTEURML * ml);
- digitalWrite(PINPOMPE2, HIGH);
- Serial.print("Distribue pompe2 : ");
- Serial.print(ml);
- Serial.println("ml");
- sprintf(message, "Distribution %.1fml de KH", ml);
- //Blynk.notify(message);
- }
- }
- void Active3(float ml) {
- if (AUTO3) {
- char message[30];
- digitalWrite(PINPOMPE3, LOW);
- delay(FACTEURML * ml);
- digitalWrite(PINPOMPE3, HIGH);
- Serial.print("Distribue pompe3 : ");
- Serial.print(ml);
- Serial.println("ml");
- sprintf(message, "Distribution %.1fml de Iode", ml);
- //Blynk.notify(message);
- }
- }
- void Active4(float ml) {
- if (AUTO4) {
- char message[30];
- digitalWrite(PINPOMPE4, LOW);
- delay(FACTEURML * ml);
- digitalWrite(PINPOMPE4, HIGH);
- Serial.print("Distribue pompe4 : ");
- Serial.print(ml);
- Serial.println("ml");
- sprintf(message, "Distribution %.1fml de Pompe4", ml);
- //Blynk.notify(message);
- }
- }
- void Ft_Timer() {
- int Hmin = hour() * 60 + minute();
- Serial.println(Hmin);
- switch (Hmin) {
- case ( H1):
- Active1(ML1);
- break;
- case ( H1 + 30 ):
- Active2(ML2);
- break;
- case ( H1 + 60 ):
- Active3(ML3);
- break;
- case ( H1 + 90 ):
- Active4(ML4);
- break;
- case H2:
- if (inter1 == INTER6H)
- Active1(ML1);
- break;
- case H2+30:
- if (inter2 == INTER6H)
- Active2(ML2);
- break;
- case H2+60:
- if (inter3 == INTER6H)
- Active3(ML3);
- break;
- case H2+90:
- if (inter4 == INTER6H)
- Active4(ML4);
- break;
- case H3:
- if (inter1 == INTER12H)
- Active1(ML1);
- break;
- case H3+30:
- if (inter2 == INTER12H)
- Active2(ML2);
- break;
- case H3+60:
- if (inter3 == INTER12H)
- Active3(ML3);
- break;
- case H3+90:
- if (inter4 == INTER12H)
- Active4(ML4);
- break;
- case H4:
- if (inter1 == INTER6H)
- Active1(ML1);
- break;
- case H4+30:
- if (inter2 == INTER6H)
- Active2(ML2);
- break;
- case H4+60:
- if (inter3 == INTER6H)
- Active3(ML3);
- break;
- case H4+90:
- if (inter4 == INTER6H)
- Active4(ML4);
- break;
- default:
- break;
- }
- }
- //************************************************************************
- // Fonction Blynk
- //************************************************************************
- BLYNK_CONNECTED() {
- Blynk.syncAll();
- rtc.begin();
- }
- //Quantité
- BLYNK_WRITE(V0) {
- float ml = param.asFloat();
- if (ml < 10) {
- inter1 = INTER24H;
- ML1 = ml;
- }
- else if (ml < 30) {
- inter1 = INTER12H;
- ML1 = ml / 2;
- }
- else {
- inter1 = INTER6H;
- ML1 = ml / 4;
- }
- }
- BLYNK_WRITE(V1) {
- float ml = param.asFloat();
- if (ml < 10) {
- inter2 = INTER24H;
- ML2 = ml;
- }
- else if (ml < 30) {
- inter2 = INTER12H;
- ML2 = ml / 2;
- }
- else {
- inter2 = INTER6H;
- ML2 = ml / 4;
- }
- }
- BLYNK_WRITE(V2) {
- float ml = param.asFloat();
- if (ml < 10) {
- inter3 = INTER24H;
- ML3 = ml;
- }
- else if (ml < 30) {
- inter3 = INTER12H;
- ML3 = ml / 2;
- }
- else {
- inter3 = INTER6H;
- ML3 = ml / 4;
- }
- }
- BLYNK_WRITE(V3) {
- float ml = param.asFloat();
- if (ml < 10) {
- inter4 = INTER24H;
- ML4 = ml;
- }
- else if (ml < 30) {
- inter4 = INTER12H;
- ML4 = ml / 2;
- }
- else {
- inter4 = INTER6H;
- ML4 = ml / 4;
- }
- }
- //ON/OFF Auto
- BLYNK_WRITE(V4) {
- if ( param.asInt()) {
- AUTO1 = true;
- }
- else
- AUTO1 = false;
- }
- BLYNK_WRITE(V5) {
- if ( param.asInt())
- AUTO2 = true;
- else
- AUTO2 = false;
- }
- BLYNK_WRITE(V6) {
- if ( param.asInt())
- AUTO3 = true;
- else
- AUTO3 = false;
- }
- BLYNK_WRITE(V7) {
- if ( param.asInt())
- AUTO4 = true;
- else
- AUTO4 = false;
- }
- //Forcé
- BLYNK_WRITE(V12) {
- if ( param.asInt())
- Active1(nbMLTest);
- }
- BLYNK_WRITE(V13) {
- if ( param.asInt())
- Active2(nbMLTest);
- }
- BLYNK_WRITE(V14) {
- if ( param.asInt())
- Active3(nbMLTest);
- }
- BLYNK_WRITE(V15) {
- if ( param.asInt())
- Active4(nbMLTest);
- }
- void setup()
- {
- // Debug console
- Serial.begin(9600);
- Serial.println("Start");
- //Pin Setup
- pinMode(PINPOMPE1, OUTPUT);
- pinMode(PINPOMPE2, OUTPUT);
- pinMode(PINPOMPE3, OUTPUT);
- pinMode(PINPOMPE4, OUTPUT);
- digitalWrite(PINPOMPE1, HIGH);
- digitalWrite(PINPOMPE2, HIGH);
- digitalWrite(PINPOMPE3, HIGH);
- digitalWrite(PINPOMPE4, HIGH);
- //Blynk.begin(auth, ssid, pass);
- // You can also specify server:
- //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
- Blynk.begin(auth, ssid, pass, IPAddress(192, 168, 1, 18), 8081);
- setSyncInterval(10 * 60); // interval de syncro de la RTC (10 min)
- timer.setInterval(60000L, Ft_Timer);
- }
- void loop()
- {
- Blynk.run();
- timer.run();
- }
|