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 = 2.0;
  37. bool AUTO1 = false;
  38. bool AUTO2 = false;
  39. bool AUTO3 = false;
  40. bool AUTO4 = false;
  41. #define H1 0*60
  42. #define H2 6*60
  43. #define H3 12*60
  44. #define H4 18*60
  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. Serial.println(Hmin);
  103. switch (Hmin) {
  104. case ( H1):
  105. Active1(ML1);
  106. break;
  107. case ( H1 + 30 ):
  108. Active2(ML2);
  109. break;
  110. case ( H1 + 60 ):
  111. Active3(ML3);
  112. break;
  113. case ( H1 + 90 ):
  114. Active4(ML4);
  115. break;
  116. case H2:
  117. if (inter1 == INTER6H)
  118. Active1(ML1);
  119. break;
  120. case H2+30:
  121. if (inter2 == INTER6H)
  122. Active2(ML2);
  123. break;
  124. case H2+60:
  125. if (inter3 == INTER6H)
  126. Active3(ML3);
  127. break;
  128. case H2+90:
  129. if (inter4 == INTER6H)
  130. Active4(ML4);
  131. break;
  132. case H3:
  133. if (inter1 == INTER12H)
  134. Active1(ML1);
  135. break;
  136. case H3+30:
  137. if (inter2 == INTER12H)
  138. Active2(ML2);
  139. break;
  140. case H3+60:
  141. if (inter3 == INTER12H)
  142. Active3(ML3);
  143. break;
  144. case H3+90:
  145. if (inter4 == INTER12H)
  146. Active4(ML4);
  147. break;
  148. case H4:
  149. if (inter1 == INTER6H)
  150. Active1(ML1);
  151. break;
  152. case H4+30:
  153. if (inter2 == INTER6H)
  154. Active2(ML2);
  155. break;
  156. case H4+60:
  157. if (inter3 == INTER6H)
  158. Active3(ML3);
  159. break;
  160. case H4+90:
  161. if (inter4 == INTER6H)
  162. Active4(ML4);
  163. break;
  164. default:
  165. break;
  166. }
  167. }
  168. //************************************************************************
  169. // Fonction Blynk
  170. //************************************************************************
  171. BLYNK_CONNECTED() {
  172. Blynk.syncAll();
  173. rtc.begin();
  174. }
  175. //Quantité
  176. BLYNK_WRITE(V0) {
  177. float ml = param.asFloat();
  178. if (ml < 10) {
  179. inter1 = INTER24H;
  180. ML1 = ml;
  181. }
  182. else if (ml < 30) {
  183. inter1 = INTER12H;
  184. ML1 = ml / 2;
  185. }
  186. else {
  187. inter1 = INTER6H;
  188. ML1 = ml / 4;
  189. }
  190. }
  191. BLYNK_WRITE(V1) {
  192. float ml = param.asFloat();
  193. if (ml < 10) {
  194. inter2 = INTER24H;
  195. ML2 = ml;
  196. }
  197. else if (ml < 30) {
  198. inter2 = INTER12H;
  199. ML2 = ml / 2;
  200. }
  201. else {
  202. inter2 = INTER6H;
  203. ML2 = ml / 4;
  204. }
  205. }
  206. BLYNK_WRITE(V2) {
  207. float ml = param.asFloat();
  208. if (ml < 10) {
  209. inter3 = INTER24H;
  210. ML3 = ml;
  211. }
  212. else if (ml < 30) {
  213. inter3 = INTER12H;
  214. ML3 = ml / 2;
  215. }
  216. else {
  217. inter3 = INTER6H;
  218. ML3 = ml / 4;
  219. }
  220. }
  221. BLYNK_WRITE(V3) {
  222. float ml = param.asFloat();
  223. if (ml < 10) {
  224. inter4 = INTER24H;
  225. ML4 = ml;
  226. }
  227. else if (ml < 30) {
  228. inter4 = INTER12H;
  229. ML4 = ml / 2;
  230. }
  231. else {
  232. inter4 = INTER6H;
  233. ML4 = ml / 4;
  234. }
  235. }
  236. //ON/OFF Auto
  237. BLYNK_WRITE(V4) {
  238. if ( param.asInt()) {
  239. AUTO1 = true;
  240. }
  241. else
  242. AUTO1 = false;
  243. }
  244. BLYNK_WRITE(V5) {
  245. if ( param.asInt())
  246. AUTO2 = true;
  247. else
  248. AUTO2 = false;
  249. }
  250. BLYNK_WRITE(V6) {
  251. if ( param.asInt())
  252. AUTO3 = true;
  253. else
  254. AUTO3 = false;
  255. }
  256. BLYNK_WRITE(V7) {
  257. if ( param.asInt())
  258. AUTO4 = true;
  259. else
  260. AUTO4 = false;
  261. }
  262. //Forcé
  263. BLYNK_WRITE(V12) {
  264. if ( param.asInt())
  265. Active1(nbMLTest);
  266. }
  267. BLYNK_WRITE(V13) {
  268. if ( param.asInt())
  269. Active2(nbMLTest);
  270. }
  271. BLYNK_WRITE(V14) {
  272. if ( param.asInt())
  273. Active3(nbMLTest);
  274. }
  275. BLYNK_WRITE(V15) {
  276. if ( param.asInt())
  277. Active4(nbMLTest);
  278. }
  279. void setup()
  280. {
  281. // Debug console
  282. Serial.begin(9600);
  283. Serial.println("Start");
  284. //Pin Setup
  285. pinMode(PINPOMPE1, OUTPUT);
  286. pinMode(PINPOMPE2, OUTPUT);
  287. pinMode(PINPOMPE3, OUTPUT);
  288. pinMode(PINPOMPE4, OUTPUT);
  289. digitalWrite(PINPOMPE1, HIGH);
  290. digitalWrite(PINPOMPE2, HIGH);
  291. digitalWrite(PINPOMPE3, HIGH);
  292. digitalWrite(PINPOMPE4, HIGH);
  293. //Blynk.begin(auth, ssid, pass);
  294. // You can also specify server:
  295. //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  296. Blynk.begin(auth, ssid, pass, IPAddress(192, 168, 1, 18), 8081);
  297. setSyncInterval(10 * 60); // interval de syncro de la RTC (10 min)
  298. timer.setInterval(60000L, Ft_Timer);
  299. }
  300. void loop()
  301. {
  302. Blynk.run();
  303. timer.run();
  304. }