PeristatiqueV2.ino 6.4 KB

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