PeristatiqueV3.ino 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. //Ajouter de la formule de calcul des quantité :
  2. Q=Q+((Q/M)*Vc - Q)/2
  3. avec
  4. Q Quantité
  5. M nouvelle mesure
  6. Vc valeur cible
  7. /* Comment this out to disable prints and save space */
  8. //#define BLYNK_PRINT Serial
  9. //#include <ESP8266WiFi.h>
  10. #include <BlynkSimpleEsp8266.h>
  11. #include <TimeLib.h>
  12. #include <WidgetRTC.h>
  13. // You should get Auth Token in the Blynk App.
  14. // Go to the Project Settings (nut icon).
  15. char auth[] = "5I28lN8RWcLQLvaoRyv0RNuiuBVwy99K";
  16. // Your WiFi credentials.
  17. // Set password to "" for open networks.
  18. char ssid[] = "Livebox-7C2C";
  19. char pass[] = "566C61F61F9C925C9F3D7D79E6";
  20. WidgetRTC rtc;
  21. BlynkTimer timer;
  22. //************************************************************************
  23. // Variable Global perso
  24. //************************************************************************
  25. #define POMPE1 0
  26. #define POMPE2 1
  27. #define POMPE3 2
  28. #define POMPE4 3
  29. #define FACTEURML 635
  30. #define INTER24H 1
  31. #define INTER12H 2
  32. #define INTER6H 3
  33. int inter1, inter2, inter3, inter4;
  34. const int PINPOMPE1 = 16;
  35. const int PINPOMPE2 = 5;
  36. const int PINPOMPE3 = 4;
  37. const int PINPOMPE4 = 0;
  38. float ML1 = 0.0;
  39. float ML2 = 0.0;
  40. float ML3 = 0.0;
  41. float ML4 = 0.0;
  42. float nbMLTest = 2.0;
  43. bool AUTO1 = false;
  44. bool AUTO2 = false;
  45. bool AUTO3 = false;
  46. bool AUTO4 = false;
  47. #define H1 0*60
  48. #define H2 6*60
  49. #define H3 12*60
  50. #define H4 18*60
  51. //************************************************************************
  52. // Fonction
  53. //************************************************************************
  54. void Active1(float ml) {
  55. if (AUTO1) {
  56. char message[30];
  57. digitalWrite(PINPOMPE1, LOW);
  58. delay(FACTEURML * ml);
  59. digitalWrite(PINPOMPE1, HIGH);
  60. Serial.print("Distribue pompe1 : ");
  61. Serial.print(ml);
  62. Serial.println("ml");
  63. sprintf(message, "Distribution %.1fml de calcium", ml);
  64. //Blynk.notify(message);
  65. }
  66. }
  67. void Active2(float ml) {
  68. if (AUTO2) {
  69. char message[30];
  70. digitalWrite(PINPOMPE2, LOW);
  71. delay(FACTEURML * ml);
  72. digitalWrite(PINPOMPE2, HIGH);
  73. Serial.print("Distribue pompe2 : ");
  74. Serial.print(ml);
  75. Serial.println("ml");
  76. sprintf(message, "Distribution %.1fml de KH", ml);
  77. //Blynk.notify(message);
  78. }
  79. }
  80. void Active3(float ml) {
  81. if (AUTO3) {
  82. char message[30];
  83. digitalWrite(PINPOMPE3, LOW);
  84. delay(FACTEURML * ml);
  85. digitalWrite(PINPOMPE3, HIGH);
  86. Serial.print("Distribue pompe3 : ");
  87. Serial.print(ml);
  88. Serial.println("ml");
  89. sprintf(message, "Distribution %.1fml de Iode", ml);
  90. //Blynk.notify(message);
  91. }
  92. }
  93. void Active4(float ml) {
  94. if (AUTO4) {
  95. char message[30];
  96. digitalWrite(PINPOMPE4, LOW);
  97. delay(FACTEURML * ml);
  98. digitalWrite(PINPOMPE4, HIGH);
  99. Serial.print("Distribue pompe4 : ");
  100. Serial.print(ml);
  101. Serial.println("ml");
  102. sprintf(message, "Distribution %.1fml de Pompe4", ml);
  103. //Blynk.notify(message);
  104. }
  105. }
  106. void Ft_Timer() {
  107. int Hmin = hour() * 60 + minute();
  108. Serial.println(Hmin);
  109. switch (Hmin) {
  110. case ( H1):
  111. Active1(ML1);
  112. break;
  113. case ( H1 + 30 ):
  114. Active2(ML2);
  115. break;
  116. case ( H1 + 60 ):
  117. Active3(ML3);
  118. break;
  119. case ( H1 + 90 ):
  120. Active4(ML4);
  121. break;
  122. case H2:
  123. if (inter1 == INTER6H)
  124. Active1(ML1);
  125. break;
  126. case H2+30:
  127. if (inter2 == INTER6H)
  128. Active2(ML2);
  129. break;
  130. case H2+60:
  131. if (inter3 == INTER6H)
  132. Active3(ML3);
  133. break;
  134. case H2+90:
  135. if (inter4 == INTER6H)
  136. Active4(ML4);
  137. break;
  138. case H3:
  139. if (inter1 == INTER12H)
  140. Active1(ML1);
  141. break;
  142. case H3+30:
  143. if (inter2 == INTER12H)
  144. Active2(ML2);
  145. break;
  146. case H3+60:
  147. if (inter3 == INTER12H)
  148. Active3(ML3);
  149. break;
  150. case H3+90:
  151. if (inter4 == INTER12H)
  152. Active4(ML4);
  153. break;
  154. case H4:
  155. if (inter1 == INTER6H)
  156. Active1(ML1);
  157. break;
  158. case H4+30:
  159. if (inter2 == INTER6H)
  160. Active2(ML2);
  161. break;
  162. case H4+60:
  163. if (inter3 == INTER6H)
  164. Active3(ML3);
  165. break;
  166. case H4+90:
  167. if (inter4 == INTER6H)
  168. Active4(ML4);
  169. break;
  170. default:
  171. break;
  172. }
  173. }
  174. //************************************************************************
  175. // Fonction Blynk
  176. //************************************************************************
  177. BLYNK_CONNECTED() {
  178. Blynk.syncAll();
  179. rtc.begin();
  180. }
  181. //Quantité
  182. BLYNK_WRITE(V0) {
  183. float ml = param.asFloat();
  184. if (ml < 10) {
  185. inter1 = INTER24H;
  186. ML1 = ml;
  187. }
  188. else if (ml < 30) {
  189. inter1 = INTER12H;
  190. ML1 = ml / 2;
  191. }
  192. else {
  193. inter1 = INTER6H;
  194. ML1 = ml / 4;
  195. }
  196. }
  197. BLYNK_WRITE(V1) {
  198. float ml = param.asFloat();
  199. if (ml < 10) {
  200. inter2 = INTER24H;
  201. ML2 = ml;
  202. }
  203. else if (ml < 30) {
  204. inter2 = INTER12H;
  205. ML2 = ml / 2;
  206. }
  207. else {
  208. inter2 = INTER6H;
  209. ML2 = ml / 4;
  210. }
  211. }
  212. BLYNK_WRITE(V2) {
  213. float ml = param.asFloat();
  214. if (ml < 10) {
  215. inter3 = INTER24H;
  216. ML3 = ml;
  217. }
  218. else if (ml < 30) {
  219. inter3 = INTER12H;
  220. ML3 = ml / 2;
  221. }
  222. else {
  223. inter3 = INTER6H;
  224. ML3 = ml / 4;
  225. }
  226. }
  227. BLYNK_WRITE(V3) {
  228. float ml = param.asFloat();
  229. if (ml < 10) {
  230. inter4 = INTER24H;
  231. ML4 = ml;
  232. }
  233. else if (ml < 30) {
  234. inter4 = INTER12H;
  235. ML4 = ml / 2;
  236. }
  237. else {
  238. inter4 = INTER6H;
  239. ML4 = ml / 4;
  240. }
  241. }
  242. //ON/OFF Auto
  243. BLYNK_WRITE(V4) {
  244. if ( param.asInt()) {
  245. AUTO1 = true;
  246. }
  247. else
  248. AUTO1 = false;
  249. }
  250. BLYNK_WRITE(V5) {
  251. if ( param.asInt())
  252. AUTO2 = true;
  253. else
  254. AUTO2 = false;
  255. }
  256. BLYNK_WRITE(V6) {
  257. if ( param.asInt())
  258. AUTO3 = true;
  259. else
  260. AUTO3 = false;
  261. }
  262. BLYNK_WRITE(V7) {
  263. if ( param.asInt())
  264. AUTO4 = true;
  265. else
  266. AUTO4 = false;
  267. }
  268. //Forcé
  269. BLYNK_WRITE(V12) {
  270. if ( param.asInt())
  271. Active1(nbMLTest);
  272. }
  273. BLYNK_WRITE(V13) {
  274. if ( param.asInt())
  275. Active2(nbMLTest);
  276. }
  277. BLYNK_WRITE(V14) {
  278. if ( param.asInt())
  279. Active3(nbMLTest);
  280. }
  281. BLYNK_WRITE(V15) {
  282. if ( param.asInt())
  283. Active4(nbMLTest);
  284. }
  285. void setup()
  286. {
  287. // Debug console
  288. Serial.begin(9600);
  289. Serial.println("Start");
  290. //Pin Setup
  291. pinMode(PINPOMPE1, OUTPUT);
  292. pinMode(PINPOMPE2, OUTPUT);
  293. pinMode(PINPOMPE3, OUTPUT);
  294. pinMode(PINPOMPE4, OUTPUT);
  295. digitalWrite(PINPOMPE1, HIGH);
  296. digitalWrite(PINPOMPE2, HIGH);
  297. digitalWrite(PINPOMPE3, HIGH);
  298. digitalWrite(PINPOMPE4, HIGH);
  299. //Blynk.begin(auth, ssid, pass);
  300. // You can also specify server:
  301. //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  302. Blynk.begin(auth, ssid, pass, IPAddress(192, 168, 1, 18), 8081);
  303. setSyncInterval(10 * 60); // interval de syncro de la RTC (10 min)
  304. timer.setInterval(60000L, Ft_Timer);
  305. }
  306. void loop()
  307. {
  308. Blynk.run();
  309. timer.run();
  310. }