PowerTGS440

Blynk-Relay-Expander Starter v1.1

Aug 29th, 2021
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 50.01 KB | None | 0 0
  1. /****************************************************************************************************************************
  2.  
  3. Home MainCenter (ESP8266) by Tomasz Majcher
  4.  
  5.  
  6. *****************************************************************************************************************************/
  7. //
  8. //
  9. //
  10. //
  11. // ------------------------------------------------------------------------------------------------------------------- //
  12. // H I S T O R Y   V E R S I O N   L O G
  13. //
  14. //  v0.01 add function    : SerialInit()
  15. //  v0.02 add function    : WiFiInit()
  16. //  v0.03 add function    : WiFiStatus()
  17. //  v0.04 add function    : WiFiReconect()
  18. //  v0.05 add function    : NTPInit()
  19. //  v0.06 add function    : Show_NTP()
  20. //  v0.07 add structure   : MyClock
  21. //  v0.07 add function    : MyClock_Update()
  22. //  v0.08 add             : day of week (PL/EN) (need rebuild library NTPClient_Generic by Tomasz Majcher) !!!
  23. //  v0.09 add             : month (PL/EN)
  24. //  v0.10 update          : Show_NTP()
  25. //  v0.11 add             : Task Scheluder
  26. //  v0.12 add library     : TFT_SPI
  27. //  v0.13 add function    : TFT -> Stars
  28. //  v0.14 add library     : PCF8564 for relays
  29. //  v0.15 add function    : ExpanderInit()
  30. //  v0.16 add             : define RELAYS pin on EXPANDER
  31. //  v0.17 add function    : RelayOn(byte nr), RelayOff(byte nr) if send 0 turn on all, turn off all
  32. //  v0.18 add             : add safe mode for Relay (check wrong Relay)
  33. //  v0.19 add library     : blynk library <BlynkSimpleEsp8266.h>
  34. //  v0.20                 : conecting button (blynk) to relays
  35. //  v0.21 add RTC         : rtc module (minimum ntp update)
  36. //  v0.22 add function    : bulb image (on/off)
  37. //
  38. // ------------------------------------------------------------------------------------------------------------------- //
  39. // --- WiFi Setup ---------------------------------------------------------------------------------------------------- //
  40. // ------------------------------------------------------------------------------------------------------------------- //
  41.  
  42. #include <ESP8266WiFi.h>                // Library for WiFi Network (biblioteka do obsługi sieci WiFi)
  43. #include <WiFiUdp.h>                    // Library for NTP Server (biblioteka do obsługi serwera NTP)
  44.  
  45. char ssid[] = "XXXXXX";                 // your network SSID (nazwa twojej sieci WiFi)
  46. char pass[] = "XXXXXXXXXXX";            // your network password (hasło dostępu do sieci WiFi)
  47.  
  48. WiFiUDP ntpUDP;
  49.  
  50. unsigned long previousMillis = 0;       // for WiFiReconect
  51. unsigned long interval = 30000;         // for WiFiReconect
  52.  
  53. // ------------------------------------------------------------------------------------------------------------------- //
  54. // --- NTP server ---------------------------------------------------------------------------------------------------- //
  55. // ------------------------------------------------------------------------------------------------------------------- //
  56.  
  57. #define NTP_DBG_PORT                Serial                            // where Debug NTP ---> Serial
  58. #define _NTP_LOGLEVEL_              0                                 // 0 = no NTP debug
  59.  
  60. #include <NTPClient_Generic.h>                                        // Library for NTP Server
  61.  
  62. char timeServer[] = "pl.pool.ntp.org";                                // Time Server (Europe/Poland)
  63.  
  64. #define TIME_ZONE_OFFSET_HRS            (2)                           // Time Zone (Europe/Warsaw)
  65. #define NTP_UPDATE_INTERVAL_MS          60000L                        // Ntp Update (60 seconds)
  66.  
  67. NTPClient timeClient(ntpUDP, timeServer, (3600 * TIME_ZONE_OFFSET_HRS), NTP_UPDATE_INTERVAL_MS);
  68.  
  69. // ------------------------------------------------------------------------------------------------------------------- //
  70. // --- B L Y N K ----------------------------------------------------------------------------------------------------- //
  71. // ------------------------------------------------------------------------------------------------------------------- //
  72.  
  73. #include <BlynkSimpleEsp8266.h>  
  74.  
  75. #define VPIN_BUTTON_1  V1  
  76. #define VPIN_BUTTON_2  V2  
  77. #define VPIN_BUTTON_3  V3  
  78. #define VPIN_BUTTON_4  V4  
  79. #define VPIN_BUTTON_5  V5  
  80. #define VPIN_BUTTON_6  V6  
  81. #define VPIN_BUTTON_7  V7  
  82. #define VPIN_BUTTON_8  V8
  83.  
  84. #define AUTH "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"    // You should get Auth Token in the Blynk App.  
  85.  
  86. BlynkTimer timer;  
  87.  
  88. int toggleState_1 = 1; //Define integer to remember the toggle state for relay 1  
  89. int toggleState_2 = 1; //Define integer to remember the toggle state for relay 2  
  90. int toggleState_3 = 1; //Define integer to remember the toggle state for relay 3  
  91. int toggleState_4 = 1; //Define integer to remember the toggle state for relay 4  
  92. int toggleState_5 = 1; //Define integer to remember the toggle state for relay 5  
  93. int toggleState_6 = 1; //Define integer to remember the toggle state for relay 6  
  94. int toggleState_7 = 1; //Define integer to remember the toggle state for relay 7  
  95. int toggleState_8 = 1; //Define integer to remember the toggle state for relay 8  
  96.  
  97. // ------------------------------------------------------------------------------------------------------------------- //
  98. // --- E X P A N D E R  ---------------------------------------------------------------------------------------------- //
  99. // ------------------------------------------------------------------------------------------------------------------- //
  100.  
  101. #include <pcf8574_esp.h>
  102. #include <Wire.h>
  103.  
  104.  
  105. TwoWire rWire;                               // wire SCL D2 (GPIO4), SCA D1 (GPIO5)
  106. PCF857x expander(0x20, &rWire);              // expander on 0x20
  107.  
  108. // ------------------------------------------------------------------------------------------------------------------- //
  109. // --- R E L A Y S  -------------------------------------------------------------------------------------------------- //
  110. // ------------------------------------------------------------------------------------------------------------------- //
  111.  
  112. #define RELAY0    0                             // reserved (to manage from 1 to 8)
  113. #define RELAY1    0                             // RELAY 1 on pin 0 (EXPANDER)
  114. #define RELAY2    1                             // RELAY 2 on pin 1 (EXPANDER)
  115. #define RELAY3    2                             // RELAY 3 on pin 2 (EXPANDER)
  116. #define RELAY4    3                             // RELAY 4 on pin 3 (EXPANDER)
  117. #define RELAY5    4                             // RELAY 5 on pin 4 (EXPANDER)
  118. #define RELAY6    5                             // RELAY 6 on pin 5 (EXPANDER)
  119. #define RELAY7    6                             // RELAY 7 on pin 6 (EXPANDER)
  120. #define RELAY8    7                             // RELAY 8 on pin 7 (EXPANDER)
  121.  
  122. #define RelayMin    1                           // define first RELAY (to debug)
  123. #define RelayMax    8                           // define last RELAY (to debug)
  124.  
  125. const byte RELAY[9] = { RELAY0, RELAY1, RELAY2, RELAY3, RELAY4, RELAY5, RELAY6, RELAY7, RELAY8 };
  126.  
  127. /*
  128.     How to use ?
  129.  
  130.     RelayOn(0);    turn on all relay (set to LOW)    
  131.     RelayOff(0);   turn off all relay (set to HIGH)    
  132.     RelayOn(1);    turn on relay nr. 1 (set to LOW)
  133.     RelayOn(3);    turn on relay nr. 3 (set to LOW)    
  134.     RelayOff(3);   turn off relay nr. 1 (set to HIGH)    
  135.     RelayOff(1);   turn off relay nr. 3 (set to HIGH)
  136. */
  137.  
  138. // ------------------------------------------------------------------------------------------------------------------- //
  139. // --- T F T   ------------------------------------------------------------------------------------------------------- //
  140. // ------------------------------------------------------------------------------------------------------------------- //
  141.  
  142. // PINS TFT -> NodeMCU ESP8266
  143.  
  144. // SDI pin to     :   D7
  145. // SCK pin to     :   D5
  146. // CS pin to      :   D3
  147. // DC pin to      :   D4
  148. // RST pin to     :   RST
  149.  
  150. // ------------------------------------------------------------------------------------------------------------------- //
  151. #include "SPI.h"
  152. #include "TFT_eSPI.h"
  153.  
  154. TFT_eSPI tft = TFT_eSPI();
  155.  
  156. #define x_min 0
  157. #define y_min 0
  158. #define x_max 320
  159. #define y_max 240
  160. #define frame 5
  161.  
  162.  
  163. #include "bulb.h"         // zarowki
  164.  
  165. // ------------------------------------------------------------------------------------------------------------------- //
  166. // --- R T C --- D S 1 3 0 2 ----------------------------------------------------------------------------------------- //
  167. // ------------------------------------------------------------------------------------------------------------------- //
  168.  
  169. #include <virtuabotixRTC.h>
  170.  
  171. virtuabotixRTC myRTC(D0, D6, D8);         // stwórz obiekt myRTC i zdefiniuj PIN
  172.  
  173. // ------------------------------------------------------------------------------------------------------------------- //
  174. // --- T A S K ------------------------------------------------------------------------------------------------------- //
  175. // ------------------------------------------------------------------------------------------------------------------- //
  176.  
  177. #include <TaskScheduler.h>                                       // scheluder
  178.  
  179. // ------------------------------------------------------------------------------------------------------------------- //
  180. // --- P R O T O T Y P Y --------------------------------------------------------------------------------------------- //
  181. // ------------------------------------------------------------------------------------------------------------------- //
  182.  
  183. void Task0Callback();                                                     // funkcja dla task_0    
  184. void Task1Callback();                                                     // funkcja dla task_1    
  185. void Task2Callback();                                                     // funkcja dla task_2    
  186. void Task3Callback();                                                     // funkcja dla task_3    
  187.  
  188. // ------------------------------------------------------------------------------------------------------------------- //
  189. // --- Z A D A N I A   S C H E L U D E R ' A ------------------------------------------------------------------------- //
  190. // ------------------------------------------------------------------------------------------------------------------- //
  191.                                                                                                    
  192. Task task_0( 3600000, TASK_FOREVER, &Task0Callback);                       // task_0 - co 1 godzinę  
  193. Task task_1(   60000,  TASK_FOREVER, &Task1Callback);                      // task_1 - co 1 minutę  
  194. Task task_2(    1000,  TASK_FOREVER, &Task2Callback);                      // task_2 - co 1 sekundę  
  195. Task task_3(   90000,  TASK_FOREVER, &Task3Callback);                      // task_3 - co 90 sekund
  196.                                                                                                    
  197. Scheduler runner;    
  198.  
  199. // ------------------------------------------------------------------------------------------------------------------- //
  200. // --- L A N G U A G E   S E T U P ----------------------------------------------------------------------------------- //
  201. // ------------------------------------------------------------------------------------------------------------------- //
  202.  
  203. #define LANGUAGE 0                                            // 0 (Polish), 1 (English)
  204.                                                                
  205. #if LANGUAGE == 0                                             // if POLISH Language                                            
  206.     #define POLISH 1
  207.     #define ENGLISH 0
  208. #endif
  209.    
  210. #if LANGUAGE == 1                                             // if ENGLISH Language
  211.     #define POLISH 0                                        
  212.     #define ENGLISH 1    
  213. #endif
  214.  
  215. // ------------------------------------------------------------------------------------------------------------------- //
  216. // --- S E R I A L   S E T U P --------------------------------------------------------------------------------------- //
  217. // ------------------------------------------------------------------------------------------------------------------- //
  218.  
  219. #define SERIAL true
  220. #define SerialSpeed 57600
  221.  
  222. // ------------------------------------------------------------------------------------------------------------------- //
  223. //                             *** STRUKTURA DNI TYGODNIA / STRUCT DAY OF WEEK ***                                     //
  224. // ------------------------------------------------------------------------------------------------------------------- //
  225.  
  226. const char PL_Day_0 [] = "Fake";
  227. const char PL_Day_1 [] = "Niedziela";
  228. const char PL_Day_2 [] = "Poniedzialek";
  229. const char PL_Day_3 [] = "Wtorek";
  230. const char PL_Day_4 [] = "Sroda";
  231. const char PL_Day_5 [] = "Czwartek";
  232. const char PL_Day_6 [] = "Piatek";
  233. const char PL_Day_7 [] = "Sobota";
  234.  
  235. const char EN_Day_0 [] = "Fake";
  236. const char EN_Day_1 [] = "Sunday";
  237. const char EN_Day_2 [] = "Monday";
  238. const char EN_Day_3 [] = "Tuesday";
  239. const char EN_Day_4 [] = "Wednesday";
  240. const char EN_Day_5 [] = "Thursday";
  241. const char EN_Day_6 [] = "Friday";
  242. const char EN_Day_7 [] = "Saturday";
  243.  
  244. const char * const PL_DAY[] = { PL_Day_0, PL_Day_1, PL_Day_2, PL_Day_3, PL_Day_4, PL_Day_5, PL_Day_6, PL_Day_7 };   // in POLISH
  245. const char * const EN_DAY[] = { EN_Day_0, EN_Day_1, EN_Day_2, EN_Day_3, EN_Day_4, EN_Day_5, EN_Day_6, EN_Day_7 };   // in ENGLISH
  246.  
  247. // ------------------------------------------------------------------------------------------------------------------- //
  248. //                                     *** STRUKTURA MIESIĄCE / STRUCT MONTH ***                                       //
  249. // ------------------------------------------------------------------------------------------------------------------- //
  250.  
  251. const char PL_MONTH_00  [] = "Fake";
  252. const char PL_MONTH_01  [] = "Styczen";
  253. const char PL_MONTH_02  [] = "Luty";
  254. const char PL_MONTH_03  [] = "Marzec";
  255. const char PL_MONTH_04  [] = "Kwiecien";
  256. const char PL_MONTH_05  [] = "Maj";
  257. const char PL_MONTH_06  [] = "Czerwiec";
  258. const char PL_MONTH_07  [] = "Lipiec";
  259. const char PL_MONTH_08  [] = "Sierpien";
  260. const char PL_MONTH_09  [] = "Wrzesien";
  261. const char PL_MONTH_10  [] = "Pazdziernik";
  262. const char PL_MONTH_11  [] = "Listopad";
  263. const char PL_MONTH_12  [] = "Grudzien";
  264.  
  265. const char EN_MONTH_00  [] = "Fake";
  266. const char EN_MONTH_01  [] = "January";
  267. const char EN_MONTH_02  [] = "February";
  268. const char EN_MONTH_03  [] = "March";
  269. const char EN_MONTH_04  [] = "April";
  270. const char EN_MONTH_05  [] = "May";
  271. const char EN_MONTH_06  [] = "June";
  272. const char EN_MONTH_07  [] = "July";
  273. const char EN_MONTH_08  [] = "August";
  274. const char EN_MONTH_09  [] = "September";
  275. const char EN_MONTH_10  [] = "October";
  276. const char EN_MONTH_11  [] = "November";
  277. const char EN_MONTH_12  [] = "December";
  278.  
  279. const char * const PL_MONTH[] = { PL_MONTH_00,
  280.                                   PL_MONTH_01, PL_MONTH_02, PL_MONTH_03,
  281.                                   PL_MONTH_04, PL_MONTH_05, PL_MONTH_06,
  282.                                   PL_MONTH_07, PL_MONTH_08, PL_MONTH_09,
  283.                                   PL_MONTH_10, PL_MONTH_11, PL_MONTH_12
  284.                                  };
  285.  
  286. const char * const EN_MONTH[] = { EN_MONTH_00,
  287.                                   EN_MONTH_01, EN_MONTH_02, EN_MONTH_03,
  288.                                   EN_MONTH_04, EN_MONTH_05, EN_MONTH_06,
  289.                                   EN_MONTH_07, EN_MONTH_08, EN_MONTH_09,
  290.                                   EN_MONTH_10, EN_MONTH_11, EN_MONTH_12
  291.                                 };
  292.  
  293. // ------------------------------------------------------------------------------------------------------------------- //
  294. // --- M Y N T P   S T R U C T --------------------------------------------------------------------------------------- //
  295. // ------------------------------------------------------------------------------------------------------------------- //
  296.  
  297. struct TIMEDATA
  298. {
  299.     // *** L O C   T I M E   &   D A T A *** ///
  300.  
  301.     int       iLOCYear;
  302.     int       iLOCMonth;    
  303.     int       iLOCWeekDay;                                  // Day of week (need re-build library by Tomasz Majcher)
  304.     int       iLOCDay;
  305.     int       iLOCHours;    
  306.     int       iLOCMinutes;    
  307.     int       iLOCSeconds;    
  308.  
  309.     char      cHour[3];
  310.     char      cMinutes[3];
  311.     char      cSeconds[3];
  312.  
  313.     // *** E X T R A   S T R I N G   *** ///
  314.  
  315.     String    sPL_DayOfWeek;                                // Day of week (need re-build library by Tomasz Majcher)
  316.     String    sEN_DayOfWeek;                                // Day of week (need re-build library by Tomasz Majcher)
  317.     String    sPL_Month;
  318.     String    sEN_Month;
  319.    
  320. }
  321. MyClock;
  322.  
  323. // ------------------------------------------------------------------------------------------------------------------- //
  324. // --- S E R I A L    I N I T ---------------------------------------------------------------------------------------- //
  325. // ------------------------------------------------------------------------------------------------------------------- //
  326.  
  327. void SerialInit()
  328. {
  329.     #if SERIAL
  330.         Serial.begin(SerialSpeed);                            // init Serial and set speed
  331.         while (!Serial);                                      // wait if not ready
  332.         Serial.printf("\n\n");                                // next line please
  333.     #endif    
  334. }
  335.  
  336. // ------------------------------------------------------------------------------------------------------------------- //
  337. // --- D R A W   L I N E --------------------------------------------------------------------------------------------- //
  338. // ------------------------------------------------------------------------------------------------------------------- //
  339.  
  340. void DrawLine(byte l, char s)
  341. {
  342.     #if SERIAL
  343.         Serial.printf("\n");
  344.         for (byte i=0; i<l; i++) Serial.print(s);        
  345.     #endif
  346. }
  347.  
  348. // ------------------------------------------------------------------------------------------------------------------- //
  349. // --- W i F i   I N I T --------------------------------------------------------------------------------------------- //
  350. // ------------------------------------------------------------------------------------------------------------------- //
  351.  
  352. void WiFiInit()
  353. {
  354.     WiFi.mode(WIFI_STA);
  355.     WiFi.begin(ssid, pass);
  356.  
  357.     #if SERIAL    
  358.         #if ENGLISH
  359.             Serial.printf("\n[ESP] [WiFI] Connecting to WiFi ..");
  360.         #endif
  361.         #if POLISH
  362.             Serial.printf("\n[ESP] [WiFI] Łącze z siecią WiFi ..");
  363.         #endif        
  364.     #endif
  365.      
  366.     while (WiFi.status() != WL_CONNECTED)
  367.     {
  368.         Serial.print('.');
  369.         delay(200);
  370.     }
  371.  
  372.     //statWiFi();
  373.          
  374.     WiFi.setAutoReconnect(true);
  375.     WiFi.persistent(true);
  376. }
  377.  
  378. // ------------------------------------------------------------------------------------------------------------------- //
  379. // --- WiFiStat ------------------------------------------------------------------------------------------------------ //
  380. // ------------------------------------------------------------------------------------------------------------------- //
  381.  
  382. void WiFiStat()
  383. {
  384.     switch (WiFi.status())
  385.     {
  386.         case WL_NO_SSID_AVAIL:
  387.                               #if SERIAL
  388.                                   #if ENGLISH
  389.                                       Serial.printf("\n[ESP] [WiFI] Configured SSID cannot be reached");
  390.                                   #endif
  391.                                   #if POLISH
  392.                                       Serial.printf("\n[ESP] [WiFI] Nie można osiągnąć skonfigurowanego identyfikatora SSID");
  393.                                   #endif                                  
  394.                               #endif        
  395.                               break;
  396.                              
  397.         case WL_CONNECTED:
  398.                               #if SERIAL
  399.                                   #if ENGLISH
  400.                                       Serial.printf("\n[ESP] [WiFI] Connection successfully established");
  401.                                       Serial.printf("\n[ESP] [WiFI] Your IP : %s", WiFi.localIP().toString().c_str());
  402.                                       Serial.printf("\n[ESP] [WiFI] Received Signal Strength Indication : %d", WiFi.RSSI());
  403.                                   #endif
  404.                                   #if POLISH
  405.                                       Serial.printf("\n[ESP] [WiFI] Pomyślnie nawiązano połączenie");
  406.                                       Serial.printf("\n[ESP] [WiFI] Twój adres IP : %s", WiFi.localIP().toString().c_str());
  407.                                       Serial.printf("\n[ESP] [WiFI] Wskazanie siły odbieranego sygnału : %d", WiFi.RSSI());
  408.                                   #endif                                
  409.                               #endif
  410.                               break;
  411.                              
  412.         case WL_CONNECT_FAILED:
  413.                               #if SERIAL
  414.                                   #if ENGLISH
  415.                                       Serial.printf("\n[ESP] [WiFI] Connection failed");
  416.                                   #endif
  417.                                   #if POLISH
  418.                                       Serial.printf("\n[ESP] [WiFI] Połączenie nieudane");
  419.                                   #endif                                  
  420.                               #endif
  421.                               break;
  422.       }      
  423. }
  424.  
  425. // ------------------------------------------------------------------------------------------------------------------- //
  426. // --- reconect Wi-Fi ------------------------------------------------------------------------------------------------ //
  427. // ------------------------------------------------------------------------------------------------------------------- //
  428.  
  429. void WiFiReconect()
  430. {
  431.     unsigned long currentMillis = millis();
  432.      
  433.     if ((WiFi.status() != WL_CONNECTED) && (currentMillis - previousMillis >=interval))     // if no WiFi connect now
  434.     {
  435.         #if SERIAL
  436.             #if ENGLISH
  437.                 Serial.printf("\n[ESP] [WiFI] Reconnecting to WiFi...");
  438.             #endif
  439.             #if POLISH
  440.                 Serial.printf("\n[ESP] [WiFI] Ponowne łączenie z Wi-Fi...");
  441.             #endif
  442.         #endif
  443.          
  444.         WiFi.disconnect();
  445.         WiFi.begin(ssid, pass);
  446.          
  447.         WiFiStat();                                       // show WiFi Status
  448.          
  449.         previousMillis = currentMillis;
  450.     }
  451. }
  452.  
  453. // ------------------------------------------------------------------------------------------------------------------- //
  454. // --- R T C U P A T E------------------------------------------------------------------------------------------------ //
  455. // ------------------------------------------------------------------------------------------------------------------- //
  456.  
  457. void myRTC_Update()
  458. {
  459.     if ( WiFi.status() == WL_CONNECTED )                  // if WiFi is OK
  460.     {
  461.       timeClient.update();
  462.       myRTC.setDS1302Time(timeClient.getSeconds(), timeClient.getMinutes(), timeClient.getHours(), timeClient.getWeek(), timeClient.getDay(), timeClient.getMonth(), timeClient.getYear());
  463.       myRTC.updateTime();
  464.  
  465.       #if SERIAL
  466.           #if ENGLISH
  467.               Serial.printf("\n\n[ESP] [RTC] RTC module updated ");              
  468.           #endif
  469.           #if POLISH
  470.               Serial.printf("\n\n[ESP] [RTC] czas został zaktualizowany i zsynchronizowany ");              
  471.           #endif
  472.       #endif
  473.     }
  474.    
  475. }
  476.  
  477. // ------------------------------------------------------------------------------------------------------------------- //
  478. // ---N T P   I N I T ------------------------------------------------------------------------------------------------ //
  479. // ------------------------------------------------------------------------------------------------------------------- //
  480.  
  481. int NTPInit()
  482. {
  483.     timeClient.update();
  484.  
  485.     if (timeClient.updated())
  486.     {  
  487.         #if SERIAL
  488.             DrawLine(60,'*');
  489.             #if ENGLISH
  490.                 Serial.printf("\n[ESP] [NTP] Time Update :-)");
  491.                 Serial.printf("\n[ESP] [NTP] Using NTP Server : %s", timeClient.getPoolServerName().c_str());
  492.             #endif
  493.             #if POLISH
  494.                 Serial.printf("\n[ESP] [NTP] Czas został zaktualizowany :-)");
  495.                 Serial.printf("\n[ESP] [NTP] Używasz Serwera NTP : %s", timeClient.getPoolServerName().c_str());
  496.             #endif
  497.         #endif        
  498.         return 1;                     // return 1 if time is update
  499.     }
  500.     else
  501.     {
  502.         #if SERIAL
  503.             #if ENGLISH
  504.                 Serial.printf("\n[ESP] [NTP] Time in not Update !!!");
  505.             #endif
  506.             #if POLISH
  507.                 Serial.printf("\n[ESP] [NTP] Czas nie został zaktualizowany !!!");
  508.             #endif
  509.         #endif
  510.  
  511.         return 0;                     // return 0 if time is not update
  512.     }
  513. }
  514.  
  515. // ------------------------------------------------------------------------------------------------------------------- //
  516. // --- S H O W   N T P ----------------------------------------------------------------------------------------------- //
  517. // ------------------------------------------------------------------------------------------------------------------- //
  518.  
  519. void Show_NTP()
  520. {
  521.     myRTC.updateTime();
  522.     #if SERIAL
  523.         DrawLine(60,'*');
  524.         #if POLISH
  525.             //Serial.printf("\n[ESP] [TIME] UTC Czas : %s", timeClient.getFormattedUTCTime().c_str());
  526.             //Serial.printf("\n[ESP] [TIME] UTC Data : %d/%d/%d", timeClient.getUTCDay(),timeClient.getUTCMonth(),timeClient.getUTCYear());
  527.             //Serial.printf("\n[ESP] [TIME] LOC Czas : %s", timeClient.getFormattedTime().c_str());
  528.             //Serial.printf("\n[ESP] [TIME] LOC Data : %d/%d/%d", timeClient.getDay(),timeClient.getMonth(),timeClient.getYear());
  529.             //Serial.printf("\n[ESP] [TIME] EXT Data : %s %d %s %d", MyClock.sPL_DayOfWeek.c_str(), timeClient.getDay(), MyClock.sPL_Month, timeClient.getYear());
  530.             Serial.printf("\n[ESP] [TIME] RTC Czas : %d:%d:%d", myRTC.hours, myRTC.minutes, myRTC.seconds);
  531.             Serial.printf("\n[ESP] [TIME] RTC Data : %d/%d/%d", myRTC.dayofmonth, myRTC.month, myRTC.year);          
  532.         #endif
  533.         #if ENGLISH
  534.             //Serial.printf("\n[ESP] [TIME] UTC Time : %s", timeClient.getFormattedUTCTime().c_str());
  535.             //Serial.printf("\n[ESP] [TIME] UTC Data : %d/%d/%d", timeClient.getUTCDay(),timeClient.getUTCMonth(),timeClient.getUTCYear());
  536.             //Serial.printf("\n[ESP] [TIME] LOC Time : %s", timeClient.getFormattedTime().c_str());
  537.             //Serial.printf("\n[ESP] [TIME] LOC Data : %d/%d/%d", timeClient.getDay(),timeClient.getMonth(),timeClient.getYear());
  538.             //Serial.printf("\n[ESP] [TIME] EXT Data : %s %d %s %d", MyClock.sEN_DayOfWeek, timeClient.getDay(), MyClock.sEN_Month, timeClient.getYear());
  539.             Serial.printf("\n[ESP] [TIME] RTC Time : %d:%d:%d", myRTC.hours, myRTC.minutes, myRTC.seconds);
  540.             Serial.printf("\n[ESP] [TIME] RTC Data : %d/%d/%d", myRTC.dayofmonth, myRTC.month, myRTC.year);  
  541.         #endif
  542.     #endif
  543. }
  544.  
  545. // ------------------------------------------------------------------------------------------------------------------- //
  546. // --- U P D A T E   M Y N T P   S T R U C T U R E ------------------------------------------------------------------- //
  547. // ------------------------------------------------------------------------------------------------------------------- //
  548.  
  549. void MyClock_Update()
  550. {    
  551.     // *** L O C   T I M E   &   D A T A *** ///
  552.  
  553.     MyClock.iLOCYear      = myRTC.year;
  554.     MyClock.iLOCMonth     = myRTC.month;    
  555.     MyClock.iLOCWeekDay   = myRTC.dayofweek;
  556.     MyClock.iLOCDay       = myRTC.dayofmonth;
  557.     MyClock.iLOCHours     = myRTC.hours;    
  558.     MyClock.iLOCMinutes   = myRTC.minutes;    
  559.     MyClock.iLOCSeconds   = myRTC.seconds;
  560.  
  561.     // *** E X T R A   C H A R *** ///
  562.  
  563.     if( MyClock.iLOCHours < 10 )
  564.     {
  565.         strcpy (MyClock.cHour, "0");                                          // 0H:MM:SS
  566.         strcat (MyClock.cHour, String(MyClock.iLOCHours).c_str());            // 01:MM:SS
  567.     }
  568.     else
  569.     if( MyClock.iLOCHours > 9 )
  570.     {
  571.         strcpy (MyClock.cHour, String(MyClock.iLOCHours).c_str());             // 01:MM:SS
  572.     }
  573.  
  574.     if( MyClock.iLOCMinutes < 10 )
  575.     {
  576.         strcpy (MyClock.cMinutes, "0");                                       // HH:0M:SS
  577.         strcat (MyClock.cMinutes, String(MyClock.iLOCMinutes).c_str());       // 01:M0:SS
  578.     }
  579.     else
  580.     if( MyClock.iLOCMinutes > 9 )
  581.     {
  582.         strcpy (MyClock.cMinutes, String(MyClock.iLOCMinutes).c_str());       // HH:10:SS
  583.     }
  584.  
  585.     if( MyClock.iLOCSeconds < 10 )
  586.     {
  587.         strcpy (MyClock.cSeconds, "0");                                       // HH:MM:0S
  588.         strcat (MyClock.cSeconds, String(MyClock.iLOCSeconds).c_str());       // HH:MH:S0
  589.     }
  590.     else
  591.     if( MyClock.iLOCSeconds > 9 )
  592.     {
  593.         strcpy (MyClock.cSeconds, String(MyClock.iLOCSeconds).c_str());        // HH:MM:10
  594.     }
  595.  
  596.     // *** E X T R A   S T R I N G   *** ///
  597.  
  598.     MyClock.sPL_DayOfWeek       = PL_DAY[MyClock.iLOCWeekDay];      // day of week (dzień tygodnia) POLISH (need Re-Build Library NTP by Tomasz Majcher)
  599.     MyClock.sEN_DayOfWeek       = EN_DAY[MyClock.iLOCWeekDay];      // day of week (dzień tygodnia) ENGLISH(need Re-Build Library NTP by Tomasz Majcher)    
  600.     MyClock.sPL_Month           = PL_MONTH[MyClock.iLOCMonth];      // month (miesiąc) in POLISH
  601.     MyClock.sEN_Month           = EN_MONTH[MyClock.iLOCMonth];      // month (miesiąć) in ENGLISH
  602. }
  603.  
  604. // ------------------------------------------------------------------------------------------------------------------- //
  605. // --- T A S K   S E T U P ------------------------------------------------------------------------------------------- //
  606. // ------------------------------------------------------------------------------------------------------------------- //
  607.  
  608. void TaskInit()
  609. {
  610.     runner.init();                                       // inicjalizuj scheluder
  611.                                                                                  
  612.     runner.addTask(task_0);                              // dodaj zadanie do scheluder
  613.     task_0.enable();                                     // włącz zadanie do scheluder
  614.     runner.addTask(task_1);                              // dodaj zadanie do scheluder
  615.     task_1.enable();                                     // włącz zadanie do scheluder
  616.     runner.addTask(task_2);                              // dodaj zadanie do scheluder
  617.     task_2.enable();                                     // włącz zadanie do scheluder
  618.     runner.addTask(task_3);                              // dodaj zadanie do scheluder
  619.     task_3.enable();                                     // włącz zadanie do scheluder
  620. }
  621.  
  622. // ------------------------------------------------------------------------------------------------------------------- //
  623. // --- T A S K   C A L L B A C K ------------------------------------------------------------------------------------- //
  624. // ------------------------------------------------------------------------------------------------------------------- //
  625.  
  626. void Task0Callback()    // run with interval 60 minutes
  627. {
  628.     myRTC_Update();
  629. }
  630.  
  631. // ------------------------------------------------------------------------------------------------------------------- //
  632. // --- T A S K   C A L L B A C K ------------------------------------------------------------------------------------- //
  633. // ------------------------------------------------------------------------------------------------------------------- //
  634.  
  635. void Task1Callback()    // run with interval 60 seconds
  636. {
  637.     myRTC.updateTime();
  638.     #if SERIAL
  639.         Serial.printf("\n\n[ESP] [TASK1] Inside Task1Callback() ");
  640.         DrawLine(60,'*');
  641.         Serial.printf("\n[ESP] [TASK1] [Memory Free]     : %u [kB]", ESP.getFreeHeap());      
  642.         Serial.printf("\n[ESP] [TASK1] [CPU frequency]   : %u [MHz]",ESP.getCpuFreqMHz());  
  643.         Serial.printf("\n[ESP] [TASK1] [WiFi IP]         : "); Serial.print(WiFi.localIP() );
  644.         Serial.printf("\n[ESP] [TASK1] RTC Time : %d:%d:%d", myRTC.hours, myRTC.minutes, myRTC.seconds);
  645.         Serial.printf("\n[ESP] [TASK1] RTC Time : %s:%s:%s", MyClock.cHour, MyClock.cMinutes, MyClock.cSeconds);
  646.         Serial.printf("\n[ESP] [TASK1] RTC Data : %s %d/%d/%d", MyClock.sPL_DayOfWeek, myRTC.dayofmonth, myRTC.month, myRTC.year);  
  647.         Serial.printf("\n[ESP] [TASK1] RTC Data : %s %d %s %d", MyClock.sPL_DayOfWeek, myRTC.dayofmonth, MyClock.sPL_Month, myRTC.year);  
  648.     #endif  
  649. }
  650.  
  651. // ------------------------------------------------------------------------------------------------------------------- //
  652. // --- T A S K   C A L L B A C K ------------------------------------------------------------------------------------- //
  653. // ------------------------------------------------------------------------------------------------------------------- //
  654.  
  655. void Task2Callback()    // run with interval 1 seconds
  656. {
  657.     MyClock_Update();                                               // copy Time & Data to structure MyClock from RTC  
  658.    
  659. }
  660.  
  661. // ------------------------------------------------------------------------------------------------------------------- //
  662. // --- T A S K   C A L L B A C K ------------------------------------------------------------------------------------- //
  663. // ------------------------------------------------------------------------------------------------------------------- //
  664.  
  665. void Task3Callback()    // run with interval 90 seconds
  666. {
  667.     #if SERIAL
  668.         Serial.printf("\n\n[ESP] [TASK3] Inside Task3Callback() ");      
  669.        
  670.     #endif
  671. }
  672.  
  673. // ------------------------------------------------------------------------------------------------------------------- //
  674. // --- S E T U P --- T F T --- I N I T ------------------------------------------------------------------------------- //
  675. // ------------------------------------------------------------------------------------------------------------------- //
  676.  
  677. void TFTInit()
  678. {
  679.     tft.begin();
  680.     tft.setRotation(1);  
  681.     tft.fillScreen(TFT_BLACK);
  682.     tft.setSwapBytes(true);
  683.  
  684.     for(byte i = 1; i <=8; i ++) Bulb(i, 0);      // wyłącz wszystkie żarówki
  685. }
  686.  
  687. // ------------------------------------------------------------------------------------------------------------------- //
  688. // --- E X P A N D E R   I N I T ------------------------------------------------------------------------------------- //
  689. // ------------------------------------------------------------------------------------------------------------------- //
  690.  
  691. void ExpanderInit()
  692. {
  693.     rWire.begin(5, 4);
  694.     rWire.setClock(100000L);
  695.     expander.begin();
  696.     RelayOff(0);                               //  all Relay OFF (send 0)
  697. }
  698.  
  699. // ------------------------------------------------------------------------------------------------------------------- //
  700. // --- M A I N   S E T U P ------------------------------------------------------------------------------------------- //
  701. // ------------------------------------------------------------------------------------------------------------------- //
  702.  
  703. void setup()
  704. {
  705.     SerialInit();                                         // check and init serial monitor
  706.     WiFiInit();                                           // start WiFi Connection
  707.     WiFiStat();                                           // show WiFi Status
  708.     WiFiReconect();                                       // check WiFi Connection and conect if loss !!!
  709.  
  710.     timeClient.begin();                                   // start timeClient
  711.  
  712.     DrawLine(60,'*');                                     // Draw 60x separator *
  713.    
  714.     if ( WiFi.status() == WL_CONNECTED )                  // if WiFi is OK
  715.     {
  716.         while(!NTPInit());                                // init NTP server                        
  717.         myRTC_Update();                                   // update RTC module
  718.         MyClock_Update();                                   // copy Time & Data to structure MyClock        
  719.         Show_NTP();                                       // show NTP time & data
  720.     }
  721.  
  722.     ExpanderInit();                                       // ExpanderInit
  723.    
  724.     TFTInit();                                            // Init TFT Display
  725.     TaskInit();                                           // Init Task Scheluder
  726.  
  727.     timer.setInterval(3000L, checkBlynkStatus); // check if Blynk server is connected every 3 seconds  
  728.     Blynk.config(AUTH);
  729. }
  730.  
  731. // ------------------------------------------------------------------------------------------------------------------- //
  732. // --- M A I N   L O O P --------------------------------------------------------------------------------------------- //
  733. // ------------------------------------------------------------------------------------------------------------------- //
  734.  
  735. void loop()
  736. {
  737.     runner.execute();                                     // scheluder  
  738.     Blynk.run();                                          // Blynk
  739. }
  740.  
  741. // ------------------------------------------------------------------------------------------------------------------- //
  742. //
  743. //
  744. //    ***   T F T   f u n c t i o n s ***
  745. //
  746. //
  747. // ------------------------------------------------------------------------------------------------------------------- //
  748. // --- T F T   B U L B   O N / O F F --------------------------------------------------------------------------------- //
  749. // ------------------------------------------------------------------------------------------------------------------- //
  750.  
  751. void Bulb(byte nr, byte state)
  752. {
  753.     switch(nr)
  754.     {
  755.         case 1 :  {
  756.                       if (!state)  tft.pushImage(5, 10, bulb_off_Width, bulb_off_Height, bulb_off);
  757.                       else         tft.pushImage(5, 10, bulb_off_Width, bulb_off_Height, bulb_on);
  758.                       break;
  759.                   }
  760.         case 2 :  {
  761.                       if (!state)  tft.pushImage(45, 10, bulb_off_Width, bulb_off_Height, bulb_off);
  762.                       else         tft.pushImage(45, 10, bulb_off_Width, bulb_off_Height, bulb_on);
  763.                       break;
  764.                   }
  765.         case 3 :  {
  766.                       if (!state)  tft.pushImage(85, 10, bulb_off_Width, bulb_off_Height, bulb_off);
  767.                       else         tft.pushImage(85, 10, bulb_off_Width, bulb_off_Height, bulb_on);
  768.                       break;
  769.                   }
  770.         case 4 :  {
  771.                       if (!state)  tft.pushImage(125, 10, bulb_off_Width, bulb_off_Height, bulb_off);
  772.                       else         tft.pushImage(125, 10, bulb_off_Width, bulb_off_Height, bulb_on);
  773.                       break;
  774.                   }
  775.         case 5 :  {
  776.                       if (!state)  tft.pushImage(165, 10, bulb_off_Width, bulb_off_Height, bulb_off);
  777.                       else         tft.pushImage(165, 10, bulb_off_Width, bulb_off_Height, bulb_on);
  778.                       break;
  779.                   }
  780.         case 6 :  {
  781.                       if (!state)  tft.pushImage(205, 10, bulb_off_Width, bulb_off_Height, bulb_off);
  782.                       else         tft.pushImage(205, 10, bulb_off_Width, bulb_off_Height, bulb_on);
  783.                       break;
  784.                   }
  785.         case 7 :  {
  786.                       if (!state)  tft.pushImage(245, 10, bulb_off_Width, bulb_off_Height, bulb_off);
  787.                       else         tft.pushImage(245, 10, bulb_off_Width, bulb_off_Height, bulb_on);
  788.                       break;
  789.                   }
  790.         case 8 :  {
  791.                       if (!state)  tft.pushImage(285, 10, bulb_off_Width, bulb_off_Height, bulb_off);
  792.                       else         tft.pushImage(285, 10, bulb_off_Width, bulb_off_Height, bulb_on);
  793.                       break;
  794.                   }
  795.     }
  796. }
  797.  
  798. // ------------------------------------------------------------------------------------------------------------------- //
  799. //
  800. //
  801. //    ***   R E L A Y S   ***
  802. //
  803. //
  804. // ------------------------------------------------------------------------------------------------------------------- //
  805. // --- Relay to OFF -------------------------------------------------------------------------------------------------- //
  806. // ------------------------------------------------------------------------------------------------------------------- //
  807.  
  808. void RelayOff(byte nr)
  809. {
  810.     if (!nr)     // if nr = 0 all relay set to OFF (RelayMin, RelayMax)
  811.     {
  812.         for (byte i = RelayMin; i <= RelayMax; i++) expander.write(RELAY[i], HIGH);      
  813.  
  814.         #if SERIAL
  815.             DrawLine(60,'-');                                                      // draw line
  816.             #if POLISH
  817.                 Serial.printf("\n[ESP] [RELAY] Wyłączono wszystkie przekaźniki");
  818.             #endif                
  819.             #if ENGLISH
  820.                 Serial.printf("\n[ESP] [RELAY] Turn off all relay");
  821.             #endif
  822.         #endif
  823.     }
  824.     else
  825.     {
  826.         if ( nr >= RelayMin && nr <= RelayMax )                                   // only value (1-8)
  827.         {
  828.             if ( !expander.read(RELAY[nr]) )                                      // if Relay is ON
  829.             {
  830.                 expander.write(RELAY[nr], HIGH);                                  // turn off Relay
  831.                 Bulb(nr, 0);
  832.                
  833.                 #if SERIAL
  834.                     DrawLine(60,'-');                                             // draw line
  835.                     #if POLISH
  836.                         Serial.printf("\n[ESP] [RELAY] Wyłączono przekaźnik nr. %d", nr);
  837.                     #endif                        
  838.                     #if ENGLISH
  839.                         Serial.printf("\n[ESP] [RELAY] Turn off relay no. %d", nr);
  840.                     #endif
  841.                 #endif
  842.             }
  843.             else                                                                  // relay is off, re-off
  844.             {
  845.                 #if SERIAL
  846.                     DrawLine(60,'-');
  847.                     #if POLISH
  848.                         Serial.printf("\n[ESP] [RELAY] Wykryto próbę ponownego wyłączenia przekaźnika nr. %d", nr);
  849.                     #endif
  850.                     #if ENGLISH
  851.                         Serial.printf("\n[ESP] [RELAY] An attempt to re-engage the relay has been detected no. %d", nr);
  852.                     #endif
  853.                 #endif
  854.             }
  855.         }
  856.         else                    // ERROR !!! Relay does not exist (jeśli taki przekaźnik nie istnieje)
  857.         {
  858.             #if SERIAL
  859.                 DrawLine(60,'-');                                                
  860.                 #if POLISH
  861.                     Serial.printf("\n[ESP] [RELAY] Nie ma takiego przekaźnika, nr. %d", nr);
  862.                 #endif                
  863.                 #if ENGLISH
  864.                     Serial.printf("\n[ESP] [RELAY] There is no such relay, no. %d", nr);
  865.                 #endif
  866.             #endif
  867.         }
  868.     }
  869. }
  870.  
  871. // ------------------------------------------------------------------------------------------------------------------- //
  872. // --- Relay to OFF -------------------------------------------------------------------------------------------------- //
  873. // ------------------------------------------------------------------------------------------------------------------- //
  874.  
  875. void RelayOn(byte nr)
  876. {
  877.     if (!nr)     // if nr = 0 all relay set to ON (RelayMin, RelayMax)
  878.     {
  879.         for (byte i = RelayMin; i <= RelayMax; i++) expander.write(RELAY[i], LOW);    
  880.  
  881.         #if SERIAL
  882.             DrawLine(60,'-');                                                      // draw line
  883.             #if POLISH
  884.                 Serial.printf("\n[ESP] [RELAY] Włączono wszystkie przekaźniki");
  885.             #endif                
  886.             #if ENGLISH
  887.                 Serial.printf("\n[ESP] [RELAY] Turn on all relay");
  888.             #endif
  889.          #endif
  890.     }
  891.     else
  892.     {
  893.         if ( nr >= RelayMin && nr <= RelayMax )                                   // only value (1-8)
  894.         {
  895.             if ( expander.read(RELAY[nr]) )                                       // if Relay is OFF
  896.             {
  897.                 expander.write(RELAY[nr], LOW);                                   // turn on Relay
  898.                 Bulb(nr, 1);
  899.                
  900.                 #if SERIAL
  901.                     DrawLine(60,'-');                                             // draw line
  902.                     #if POLISH
  903.                         Serial.printf("\n[ESP] [RELAY] Włączono przekaźnik nr. %d", nr);
  904.                     #endif                        
  905.                     #if ENGLISH
  906.                         Serial.printf("\n[ESP] [RELAY] Turn on relay no. %d", nr);
  907.                     #endif
  908.                 #endif
  909.             }
  910.             else                                                                  // relay is on, re-on
  911.             {
  912.                 #if SERIAL
  913.                     DrawLine(60,'-');
  914.                     #if POLISH
  915.                         Serial.printf("\n[ESP] [RELAY] Wykryto próbę ponownego włączenia przekaźnika nr. %d", nr);
  916.                     #endif
  917.                     #if ENGLISH
  918.                         Serial.printf("\n[ESP] [RELAY] An attempt to re-engage the relay has been detected no. %d", nr);
  919.                     #endif
  920.                 #endif
  921.             }
  922.         }
  923.         else
  924.         {
  925.             #if SERIAL
  926.                 DrawLine(60,'-');                                                      // draw line
  927.                 #if POLISH
  928.                     Serial.printf("\n[ESP] [RELAY] Nie ma takiego przekaźnika, nr. %d", nr);
  929.                 #endif                
  930.                 #if ENGLISH
  931.                     Serial.printf("\n[ESP] [RELAY] There is no such relay, no. %d", nr);
  932.                 #endif  
  933.             #endif
  934.         }
  935.     }
  936. }
  937.  
  938. // ------------------------------------------------------------------------------------------------------------------- //
  939. //
  940. //
  941. // B L Y N K   S E C T I O N
  942. //
  943. //
  944. // ------------------------------------------------------------------------------------------------------------------- //
  945. // BLYNK_CONNECTED
  946. // ------------------------------------------------------------------------------------------------------------------- //
  947.  
  948. BLYNK_CONNECTED()
  949. {  
  950.     Blynk.syncVirtual(VPIN_BUTTON_1);  
  951.     Blynk.syncVirtual(VPIN_BUTTON_2);  
  952.     Blynk.syncVirtual(VPIN_BUTTON_3);  
  953.     Blynk.syncVirtual(VPIN_BUTTON_4);  
  954.     Blynk.syncVirtual(VPIN_BUTTON_5);  
  955.     Blynk.syncVirtual(VPIN_BUTTON_6);  
  956.     Blynk.syncVirtual(VPIN_BUTTON_7);  
  957.     Blynk.syncVirtual(VPIN_BUTTON_8);
  958. }  
  959.  
  960. // ------------------------------------------------------------------------------------------------------------------- //
  961. // BLYNK BUTTON 1
  962. // ------------------------------------------------------------------------------------------------------------------- //
  963.  
  964. BLYNK_WRITE(VPIN_BUTTON_1)
  965. {    
  966.   toggleState_1 = param.asInt();  
  967.  
  968.   if(toggleState_1)
  969.   {
  970.       RelayOn(1);
  971.   }
  972.   else
  973.   {
  974.       RelayOff(1);
  975.   }
  976. }  
  977.  
  978. // ------------------------------------------------------------------------------------------------------------------- //
  979. // BLYNK BUTTON 2
  980. // ------------------------------------------------------------------------------------------------------------------- //
  981.  
  982. BLYNK_WRITE(VPIN_BUTTON_2)
  983. {  
  984.   toggleState_2 = param.asInt();
  985.    
  986.   if(toggleState_2)
  987.   {
  988.       RelayOn(2);
  989.   }
  990.   else
  991.   {
  992.       RelayOff(2);
  993.   }
  994. }
  995.  
  996. // ------------------------------------------------------------------------------------------------------------------- //
  997. // BLYNK BUTTON 3
  998. // ------------------------------------------------------------------------------------------------------------------- //
  999.  
  1000. BLYNK_WRITE(VPIN_BUTTON_3)
  1001. {  
  1002.   toggleState_3 = param.asInt();
  1003.    
  1004.   if(toggleState_3)
  1005.   {
  1006.       RelayOn(3);
  1007.   }
  1008.   else
  1009.   {
  1010.       RelayOff(3);
  1011.   }
  1012. }  
  1013.  
  1014. // ------------------------------------------------------------------------------------------------------------------- //
  1015. // BLYNK BUTTON 4
  1016. // ------------------------------------------------------------------------------------------------------------------- //
  1017.  
  1018. BLYNK_WRITE(VPIN_BUTTON_4)
  1019. {  
  1020.   toggleState_4 = param.asInt();
  1021.    
  1022.   if(toggleState_4)
  1023.   {
  1024.       RelayOn(4);
  1025.   }
  1026.   else
  1027.   {
  1028.       RelayOff(4);
  1029.   }
  1030. }  
  1031.  
  1032. // ------------------------------------------------------------------------------------------------------------------- //
  1033. // BLYNK BUTTON 5
  1034. // ------------------------------------------------------------------------------------------------------------------- //
  1035.  
  1036. BLYNK_WRITE(VPIN_BUTTON_5)
  1037. {  
  1038.   toggleState_5 = param.asInt();
  1039.  
  1040.   if(toggleState_5)
  1041.   {
  1042.       RelayOn(5);
  1043.   }
  1044.   else
  1045.   {
  1046.       RelayOff(5);
  1047.   }
  1048. }  
  1049.  
  1050. // ------------------------------------------------------------------------------------------------------------------- //
  1051. // BLYNK BUTTON 6
  1052. // ------------------------------------------------------------------------------------------------------------------- //
  1053.  
  1054. BLYNK_WRITE(VPIN_BUTTON_6)
  1055. {  
  1056.   toggleState_6 = param.asInt();
  1057.  
  1058.   if(toggleState_6)
  1059.   {
  1060.       RelayOn(6);
  1061.   }
  1062.   else
  1063.   {
  1064.       RelayOff(6);
  1065.   }
  1066. }  
  1067.  
  1068. // ------------------------------------------------------------------------------------------------------------------- //
  1069. // BLYNK BUTTON 7
  1070. // ------------------------------------------------------------------------------------------------------------------- //
  1071. BLYNK_WRITE(VPIN_BUTTON_7)
  1072. {  
  1073.   toggleState_7 = param.asInt();
  1074.  
  1075.   if(toggleState_7)
  1076.   {
  1077.       RelayOn(7);
  1078.   }
  1079.   else
  1080.   {
  1081.       RelayOff(7);
  1082.   }
  1083. }  
  1084.  
  1085. // ------------------------------------------------------------------------------------------------------------------- //
  1086. // BLYNK BUTTON 8
  1087. // ------------------------------------------------------------------------------------------------------------------- //
  1088.  
  1089. BLYNK_WRITE(VPIN_BUTTON_8)
  1090. {  
  1091.   toggleState_8 = param.asInt();
  1092.    
  1093.   if(toggleState_8)
  1094.   {
  1095.       RelayOn(8);
  1096.   }
  1097.   else
  1098.   {
  1099.       RelayOff(8);
  1100.   }
  1101. }  
  1102.  
  1103. void checkBlynkStatus()
  1104. {
  1105.    
  1106. }  
Advertisement
Add Comment
Please, Sign In to add comment