PowerTGS440

ESP8266 WiktoriaHomeCenter v1.0.8

Oct 10th, 2021
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 196.82 KB | None | 0 0
  1. //****************************************************************************************************************************
  2. //
  3. //  ESP8266 Wiktoria Home Monitoring System v1.0.8
  4. //  
  5. //  by Tomasz Majcher
  6. //  mail : [email protected]
  7. //
  8. //  
  9. //*****************************************************************************************************************************/
  10.  
  11. #define   FS_NO_GLOBALS
  12. #include  <FS.h>
  13.  
  14. // ------------------------------------------------------------------------------------------------------------------- //
  15. // --- WiFi Setup ---------------------------------------------------------------------------------------------------- //
  16. // ------------------------------------------------------------------------------------------------------------------- //
  17.  
  18. #include <ESP8266WiFi.h>                // Library for WiFi Network (biblioteka do obsługi sieci WiFi)
  19. #include <WiFiUdp.h>                    // Library for NTP Server (biblioteka do obsługi serwera NTP)
  20.  
  21. char ssid[] = "xxxxxx";                 // your network SSID (nazwa twojej sieci WiFi)
  22. char pass[] = "xxxxxxxxxxx";            // your network password (hasło dostępu do sieci WiFi)
  23.  
  24. WiFiUDP ntpUDP;
  25.  
  26. unsigned long previousMillis = 0;       // for WiFiReconect
  27. unsigned long interval = 30000;         // for WiFiReconect
  28.  
  29. // ------------------------------------------------------------------------------------------------------------------- //
  30. // --- NTP server ---------------------------------------------------------------------------------------------------- //
  31. // ------------------------------------------------------------------------------------------------------------------- //
  32.  
  33. #define NTP_DBG_PORT                Serial                            // where Debug NTP ---> Serial
  34. #define _NTP_LOGLEVEL_              0                                 // 0 = no NTP debug
  35.  
  36. #include <NTPClient_Generic.h>                                        // Library for NTP Server
  37.  
  38. char timeServer[] = "pl.pool.ntp.org";                                // Time Server (Europe/Poland)
  39.  
  40. #define TIME_ZONE_OFFSET_HRS            (2)                           // Time Zone (Europe/Warsaw)
  41. #define NTP_UPDATE_INTERVAL_MS          60000L                        // Ntp Update (60 seconds)
  42.  
  43. NTPClient timeClient(ntpUDP, timeServer, (3600 * TIME_ZONE_OFFSET_HRS), NTP_UPDATE_INTERVAL_MS);
  44.  
  45. bool FtimeUpdate = false;
  46.  
  47. // ------------------------------------------------------------------------------------------------------------------- //
  48. // --- B L Y N K ----------------------------------------------------------------------------------------------------- //
  49. // ------------------------------------------------------------------------------------------------------------------- //
  50.  
  51. #include <BlynkSimpleEsp8266.h>  
  52.  
  53. #define VPIN_BUTTON_1  V1  
  54. #define VPIN_BUTTON_2  V2  
  55. #define VPIN_BUTTON_3  V3  
  56. #define VPIN_BUTTON_4  V4  
  57. #define VPIN_BUTTON_5  V5  
  58. #define VPIN_BUTTON_6  V6  
  59. #define VPIN_BUTTON_7  V7  
  60. #define VPIN_BUTTON_8  V8
  61.  
  62. #define AUTH "xxx-qYWwXdG6Kq-btpnM-95DPmU"    // You should get Auth Token in the Blynk App.  
  63.  
  64. BlynkTimer timer;  
  65.  
  66. int toggleState_1 = 1; //Define integer to remember the toggle state for relay 1  
  67. int toggleState_2 = 1; //Define integer to remember the toggle state for relay 2  
  68. int toggleState_3 = 1; //Define integer to remember the toggle state for relay 3  
  69. int toggleState_4 = 1; //Define integer to remember the toggle state for relay 4  
  70. int toggleState_5 = 1; //Define integer to remember the toggle state for relay 5  
  71. int toggleState_6 = 1; //Define integer to remember the toggle state for relay 6  
  72. int toggleState_7 = 1; //Define integer to remember the toggle state for relay 7  
  73. int toggleState_8 = 1; //Define integer to remember the toggle state for relay 8  
  74.  
  75. // ------------------------------------------------------------------------------------------------------------------- //
  76. // --- E X P A N D E R  ---------------------------------------------------------------------------------------------- //
  77. // ------------------------------------------------------------------------------------------------------------------- //
  78.  
  79. #include <pcf8574_esp.h>
  80. #include <Wire.h>
  81.  
  82. /*  
  83.     Wire.h already defines "Wire" which the PCF8574-class would use by default,
  84.     but for the sakes of an example let's define our own instance of it and use that instead!
  85.  
  86.     Also, since I2C is emulated on the ESP8266 let's redefine what pins to use as SDA and SCL
  87.     and instead swap them around!
  88.     DO NOT FORGET TO WIRE ACCORDINGLY, SDA GOES TO GPIO5, SCL TO GPIO4 (ON NODEMCU GPIO5 IS D1 AND GPIO4 IS D2)
  89. */
  90.  
  91. TwoWire rWire;                               // wire SCL D2 (GPIO4), SCA D1 (GPIO5)
  92. PCF857x expander(0x20, &rWire);              // expander on 0x20
  93.  
  94. // ------------------------------------------------------------------------------------------------------------------- //
  95. // --- R E L A Y S  -------------------------------------------------------------------------------------------------- //
  96. // ------------------------------------------------------------------------------------------------------------------- //
  97.  
  98. #define RELAY0    0                             // reserved (to manage from 1 to 8)
  99. #define RELAY1    0                             // RELAY 1 on pin 0 (EXPANDER)
  100. #define RELAY2    1                             // RELAY 2 on pin 1 (EXPANDER)
  101. #define RELAY3    2                             // RELAY 3 on pin 2 (EXPANDER)
  102. #define RELAY4    3                             // RELAY 4 on pin 3 (EXPANDER)
  103. #define RELAY5    4                             // RELAY 5 on pin 4 (EXPANDER)
  104. #define RELAY6    5                             // RELAY 6 on pin 5 (EXPANDER)
  105. #define RELAY7    6                             // RELAY 7 on pin 6 (EXPANDER)
  106. #define RELAY8    7                             // RELAY 8 on pin 7 (EXPANDER)
  107.  
  108. #define RelayMin    1                           // define first RELAY (to debug)
  109. #define RelayMax    8                           // define last RELAY (to debug)
  110.  
  111. const byte RELAY[9] = { RELAY0, RELAY1, RELAY2, RELAY3, RELAY4, RELAY5, RELAY6, RELAY7, RELAY8 };
  112.  
  113. /*
  114.     How to use ?
  115.  
  116.     RelayOn(0);    turn on all relay (set to LOW)    
  117.     RelayOff(0);   turn off all relay (set to HIGH)    
  118.     RelayOn(1);    turn on relay nr. 1 (set to LOW)
  119.     RelayOn(3);    turn on relay nr. 3 (set to LOW)    
  120.     RelayOff(3);   turn off relay nr. 1 (set to HIGH)    
  121.     RelayOff(1);   turn off relay nr. 3 (set to HIGH)
  122. */
  123.  
  124. // ------------------------------------------------------------------------------------------------------------------- //
  125. // --- T F T   ------------------------------------------------------------------------------------------------------- //
  126. // ------------------------------------------------------------------------------------------------------------------- //
  127.  
  128. // PINS TFT -> NodeMCU ESP8266
  129.  
  130. // SDI pin to     :   D7
  131. // SCK pin to     :   D5
  132. // CS pin to      :   D3
  133. // DC pin to      :   D4
  134. // RST pin to     :   RST
  135.  
  136. // ------------------------------------------------------------------------------------------------------------------- //
  137. #include "SPI.h"
  138. #include "TFT_eSPI.h"
  139.  
  140. TFT_eSPI tft = TFT_eSPI();
  141.  
  142. #define x_min 0
  143. #define y_min 0
  144. #define x_max 320
  145. #define y_max 240
  146. #define frame 5
  147.  
  148. #define clock_font 6
  149.  
  150. #define clock_color_day     TFT_LIGHTGREY
  151. #define clock_color_night   TFT_DARKGREY
  152.  
  153. int clock_color = clock_color_night;
  154.  
  155. #include "bulb.h"         // zarowki
  156.  
  157.  
  158. bool F_display_clock  = true;       // flaga -> pokaz zegar
  159. bool F_display_temp   = false;      // flaga -> pokaz pogodę i temperaturę
  160. bool F_display_moon   = false;      // flaga -> pokaż fazę księżyca i godziny wschodu i  zachodu
  161. bool F_display_sun    = false;      // flaga -> pokaz słońce i godziny wschodu i zachodu
  162. bool F_refresh_all    = false;      // flaga -> odswiez zegar po powrocie do trybu: display_clock
  163.  
  164. // ------------------------------------------------------------------------------------------------------------------- //
  165. // --- J P E G   D E C O D E R---------------------------------------------------------------------------------------- //
  166. // ------------------------------------------------------------------------------------------------------------------- //
  167.  
  168. #include <JPEGDecoder.h>
  169.  
  170. // --- digits size 112 ----------------------------------------------------------------------------------------------- //
  171.  
  172. const char digit0 [] = "/digits/n0_112.jpg";
  173. const char digit1 [] = "/digits/n1_112.jpg";
  174. const char digit2 [] = "/digits/n2_112.jpg";
  175. const char digit3 [] = "/digits/n3_112.jpg";
  176. const char digit4 [] = "/digits/n4_112.jpg";
  177. const char digit5 [] = "/digits/n5_112.jpg";
  178. const char digit6 [] = "/digits/n6_112.jpg";
  179. const char digit7 [] = "/digits/n7_112.jpg";
  180. const char digit8 [] = "/digits/n8_112.jpg";
  181. const char digit9 [] = "/digits/n9_112.jpg";
  182.  
  183. const char * const digit112[] = {digit0, digit1, digit2, digit3, digit4, digit5, digit6, digit7, digit8, digit9};
  184.  
  185. // ------------------------------------------------------------------------------------------------------------------- //
  186. // --- R T C --- D S 1 3 0 2 ----------------------------------------------------------------------------------------- //
  187. // ------------------------------------------------------------------------------------------------------------------- //
  188.  
  189. #include <virtuabotixRTC.h>
  190.  
  191. virtuabotixRTC myRTC(D0, D6, D8);         // stwórz obiekt myRTC i zdefiniuj PIN myRTC (clock, data, RST)
  192.  
  193. // ------------------------------------------------------------------------------------------------------------------- //
  194. // --- T A S K ------------------------------------------------------------------------------------------------------- //
  195. // ------------------------------------------------------------------------------------------------------------------- //
  196.  
  197. #include <TaskScheduler.h>                                       // scheluder
  198.  
  199.  
  200. // ------------------------------------------------------------------------------------------------------------------- //
  201. // --- JSON PARSER---------------------------------------------------------------------------------------------------- //
  202. // ------------------------------------------------------------------------------------------------------------------- //
  203.  
  204. #define   ARDUINOJSON_DECODE_UNICODE 1
  205. #include  <ArduinoJson.h>
  206. #include <ESP8266HTTPClient.h>
  207. #include <WiFiClient.h>
  208.  
  209. WiFiClient client;
  210.  
  211. String PogodaToken  = "xxxxx";                    // token serwera pogodowego http://api.weatherapi.com
  212. String PogodaMiasto = "Lubin";
  213.  
  214. // ------------------------------------------------------------------------------------------------------------------- //
  215. // --- GLOBAL --- DLA TFT -------------------------------------------------------------------------------------------- //
  216. // ------------------------------------------------------------------------------------------------------------------- //
  217. // wystąpiły problemy przy wyświetlaniu napisów z tablicy CHAR na razie utworzone zostają w takim razie pomocnicze     //
  218. // zmienne typu STRING do przechowywania : faza księżyca, czas wschodu księżyca, czas zachodu księżyca                 //
  219. // czas wschodu słońca, czas zachodu słońca                                                                            //
  220. // ------------------------------------------------------------------------------------------------------------------- //
  221.  
  222. #include "notes.h"
  223. // 437305 (41) / 43116 (52)
  224.  
  225. String moon_phase;
  226. String moonrise;
  227. String moonset;
  228. String sunrise;
  229. String sunset;
  230. String super_msg = "ESP8266 Wiki Center";
  231.  
  232. // ------------------------------------------------------------------------------------------------------------------- //
  233. // --- P R O T O T Y P Y --------------------------------------------------------------------------------------------- //
  234. // ------------------------------------------------------------------------------------------------------------------- //
  235.  
  236. void Task0Callback();                                                     // funkcja dla task_0    
  237. void Task1Callback();                                                     // funkcja dla task_1    
  238. void Task2Callback();                                                     // funkcja dla task_2    
  239. void Task3Callback();                                                     // funkcja dla task_3    
  240. void Task4Callback();                                                     // funkcja dla task_4    
  241. void Task5Callback();                                                     // funkcja dla task_5    
  242. void Task6Callback();                                                     // funckja dla task_6
  243.  
  244. void SerialInit();
  245. void DrawLine(byte l, char s);
  246. void WiFiInit() ;
  247. void WiFiStat();
  248. void WiFiReconect();
  249. void myRTC_Update();
  250. int NTPInit();
  251. void Show_NTP();
  252. void MyClock_Update();
  253. void TaskInit();
  254. void TFTInit();
  255. void ExpanderInit();
  256. void Bulb(byte nr, byte state);
  257.  
  258. void RelayOff(byte nr);
  259. void RelayOn(byte nr);
  260.  
  261. BLYNK_WRITE(VPIN_BUTTON_1);
  262. BLYNK_WRITE(VPIN_BUTTON_2);
  263. BLYNK_WRITE(VPIN_BUTTON_3);
  264. BLYNK_WRITE(VPIN_BUTTON_4);
  265. BLYNK_WRITE(VPIN_BUTTON_5);
  266. BLYNK_WRITE(VPIN_BUTTON_6);
  267. BLYNK_WRITE(VPIN_BUTTON_7);
  268. BLYNK_WRITE(VPIN_BUTTON_8);
  269.  
  270.  
  271. void WeatherUpdate();
  272. void AstronomyUpdate();
  273. void AirUpdate();
  274.  
  275. void TFT_WeatherDisplay();
  276. void TFT_MoonDisplay();
  277. void TFT_WeatherIconShow();
  278.  
  279. void drawJpeg(const char *filename, int xpos, int ypos);           // Otwiera plik obrazu i uruchamia dekoder JPEG
  280. void jpegRender(int xpos, int ypos);                               // Dekoduj i renderuj obraz JPEG na ekranie TFT
  281. void jpegInfo();                                                   // Wydrukuj informacje odkodowane z obrazu JPEG
  282. void createArray(const char *filename);                            // Otwórz plik JPEG i wyślij go do portu szeregowego w formacie zgodnym z tablicą C
  283.  
  284. // ------------------------------------------------------------------------------------------------------------------- //
  285. // --- Z A D A N I A   S C H E L U D E R ' A ------------------------------------------------------------------------- //
  286. // ------------------------------------------------------------------------------------------------------------------- //
  287.                                                                                                    
  288. Task task_0(  360000,  TASK_FOREVER, &Task0Callback);                       // task_0 - co 1 godzinę  
  289. Task task_1(   60000,  TASK_FOREVER, &Task1Callback);                       // task_1 - co 1 minutę
  290. Task task_2(    1000,  TASK_FOREVER, &Task2Callback);                       // task_2 - co 1 sekundę  
  291. Task task_3(   90000,  TASK_FOREVER, &Task3Callback);                       // task_3 - co 90 sekund
  292. Task task_4(  360000,  TASK_FOREVER, &Task4Callback);                       // task_4 - co 10 minut
  293. Task task_5( 7200000,  TASK_FOREVER, &Task5Callback);                       // task_5 - co 120 minut
  294. Task task_6( 8400000,  TASK_FOREVER, &Task5Callback);                       // task_5 - co 140 minut
  295.                                                                                                    
  296. Scheduler runner;    
  297.  
  298. // ------------------------------------------------------------------------------------------------------------------- //
  299. // --- L A N G U A G E   S E T U P ----------------------------------------------------------------------------------- //
  300. // ------------------------------------------------------------------------------------------------------------------- //
  301.  
  302. #define LANGUAGE 1                                            // 0 (Polish), 1 (English)
  303.                                                                
  304. #if LANGUAGE == 0                                             // if POLISH Language                                            
  305.     #define POLISH 1
  306.     #define ENGLISH 0
  307. #endif
  308.    
  309. #if LANGUAGE == 1                                             // if ENGLISH Language
  310.     #define POLISH 0                                        
  311.     #define ENGLISH 1    
  312. #endif
  313.  
  314. // ------------------------------------------------------------------------------------------------------------------- //
  315. // --- S E R I A L   S E T U P --------------------------------------------------------------------------------------- //
  316. // ------------------------------------------------------------------------------------------------------------------- //
  317.  
  318.  
  319. #define SERIAL true
  320. #define SerialSpeed 57600
  321.  
  322. void _p(boolean nl, const char *format, va_list args )
  323. {
  324.     char buf[128];          // resulting string limited to 128 chars
  325.     vsnprintf(buf, sizeof(buf), format, args);
  326.     #if SERIAL
  327.         Serial.print(buf);
  328.     #endif
  329. }
  330.  
  331. void _p(boolean nl,const __FlashStringHelper *format, va_list args )
  332. {
  333.     char buf[128]; // resulting string limited to 128 chars
  334.     #ifdef __AVR__
  335.         vsnprintf_P(buf, sizeof(buf), (const char *)format, args);      // progmem dla AVR
  336.     #else
  337.         vsnprintf(buf, sizeof(buf), (const char *)format, args);        // progmem dla pozostałych modułóœ
  338.     #endif
  339.  
  340.     #if SERIAL
  341.         Serial.print(buf);
  342.     #endif
  343. }
  344.  
  345. void PRINT(const char *format, ... )
  346. {
  347.     va_list args;
  348.     va_start (args, format );
  349.     _p(1,format,args);
  350.     va_end(args);
  351. }
  352.  
  353. void PRINT(const __FlashStringHelper *format, ... )
  354. {
  355.     va_list args;
  356.     va_start(args, format );
  357.     _p(1,format,args);
  358.     va_end(args);
  359. }
  360.  
  361. void p(const char *format, ... )
  362. {
  363.     va_list args;
  364.     va_start(args, format );
  365.     _p(0,format,args);
  366.     va_end(args);
  367. }
  368.  
  369. void p(const __FlashStringHelper *format, ... )
  370. {
  371.     va_list args;
  372.     va_start(args, format );
  373.     _p(0,format,args);
  374.     va_end(args);
  375. }
  376.  
  377. // ------------------------------------------------------------------------------------------------------------------- //
  378. //                             *** STRUKTURA DNI TYGODNIA / STRUCT DAY OF WEEK ***                                     //
  379. // ------------------------------------------------------------------------------------------------------------------- //
  380.  
  381. const char PL_Day_0 [] PROGMEM = "Fake";
  382. const char PL_Day_1 [] PROGMEM = "Niedziela";
  383. const char PL_Day_2 [] PROGMEM = "Poniedzialek";
  384. const char PL_Day_3 [] PROGMEM = "Wtorek";
  385. const char PL_Day_4 [] PROGMEM = "Sroda";
  386. const char PL_Day_5 [] PROGMEM = "Czwartek";
  387. const char PL_Day_6 [] PROGMEM = "Piatek";
  388. const char PL_Day_7 [] PROGMEM = "Sobota";
  389.  
  390. const char EN_Day_0 [] PROGMEM = "Fake";
  391. const char EN_Day_1 [] PROGMEM = "Sunday";
  392. const char EN_Day_2 [] PROGMEM = "Monday";
  393. const char EN_Day_3 [] PROGMEM = "Tuesday";
  394. const char EN_Day_4 [] PROGMEM = "Wednesday";
  395. const char EN_Day_5 [] PROGMEM = "Thursday";
  396. const char EN_Day_6 [] PROGMEM = "Friday";
  397. const char EN_Day_7 [] PROGMEM = "Saturday";
  398.  
  399. const char * const PL_DAY[] PROGMEM = { 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
  400. const char * const EN_DAY[] PROGMEM = { 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
  401.  
  402. // ------------------------------------------------------------------------------------------------------------------- //
  403. //                                     *** STRUKTURA MIESIĄCE / STRUCT MONTH ***                                       //
  404. // ------------------------------------------------------------------------------------------------------------------- //
  405.  
  406. const char PL_MONTH_00  [] PROGMEM = "Fake";
  407. const char PL_MONTH_01  [] PROGMEM = "Styczen";
  408. const char PL_MONTH_02  [] PROGMEM = "Luty";
  409. const char PL_MONTH_03  [] PROGMEM = "Marzec";
  410. const char PL_MONTH_04  [] PROGMEM = "Kwiecien";
  411. const char PL_MONTH_05  [] PROGMEM = "Maj";
  412. const char PL_MONTH_06  [] PROGMEM = "Czerwiec";
  413. const char PL_MONTH_07  [] PROGMEM = "Lipiec";
  414. const char PL_MONTH_08  [] PROGMEM = "Sierpien";
  415. const char PL_MONTH_09  [] PROGMEM = "Wrzesien";
  416. const char PL_MONTH_10  [] PROGMEM = "Pazdziernik";
  417. const char PL_MONTH_11  [] PROGMEM = "Listopad";
  418. const char PL_MONTH_12  [] PROGMEM = "Grudzien";
  419.  
  420. const char EN_MONTH_00  [] PROGMEM = "Fake";
  421. const char EN_MONTH_01  [] PROGMEM = "January";
  422. const char EN_MONTH_02  [] PROGMEM = "February";
  423. const char EN_MONTH_03  [] PROGMEM = "March";
  424. const char EN_MONTH_04  [] PROGMEM = "April";
  425. const char EN_MONTH_05  [] PROGMEM = "May";
  426. const char EN_MONTH_06  [] PROGMEM = "June";
  427. const char EN_MONTH_07  [] PROGMEM = "July";
  428. const char EN_MONTH_08  [] PROGMEM = "August";
  429. const char EN_MONTH_09  [] PROGMEM = "September";
  430. const char EN_MONTH_10  [] PROGMEM = "October";
  431. const char EN_MONTH_11  [] PROGMEM = "November";
  432. const char EN_MONTH_12  [] PROGMEM = "December";
  433.  
  434. const char * const PL_MONTH[] PROGMEM = { PL_MONTH_00,
  435.                                   PL_MONTH_01, PL_MONTH_02, PL_MONTH_03,
  436.                                   PL_MONTH_04, PL_MONTH_05, PL_MONTH_06,
  437.                                   PL_MONTH_07, PL_MONTH_08, PL_MONTH_09,
  438.                                   PL_MONTH_10, PL_MONTH_11, PL_MONTH_12
  439.                                  };
  440.  
  441. const char * const EN_MONTH[] PROGMEM = { EN_MONTH_00,
  442.                                   EN_MONTH_01, EN_MONTH_02, EN_MONTH_03,
  443.                                   EN_MONTH_04, EN_MONTH_05, EN_MONTH_06,
  444.                                   EN_MONTH_07, EN_MONTH_08, EN_MONTH_09,
  445.                                   EN_MONTH_10, EN_MONTH_11, EN_MONTH_12
  446.                                 };
  447.  
  448. // ------------------------------------------------------------------------------------------------------------------- //
  449. // --- M Y N T P   S T R U C T --------------------------------------------------------------------------------------- //
  450. // ------------------------------------------------------------------------------------------------------------------- //
  451.  
  452. struct TIMEDATA
  453. {
  454.     // *** L O C   T I M E   &   D A T A *** ///
  455.  
  456.     int       iLOCYear;
  457.     int       iLOCMonth;    
  458.     int       iLOCWeekDay;                                  // Day of week (need re-build library by Tomasz Majcher)
  459.     int       iLOCDay;
  460.     int       iLOCHours;    
  461.     int       iLOCMinutes;    
  462.     int       iLOCSeconds;    
  463.  
  464.     char      cHour[3];
  465.     char      cMinutes[3];
  466.     char      cSeconds[3];
  467.  
  468.     // *** E X T R A   S T R I N G   *** ///
  469.  
  470.     String    sPL_DayOfWeek;                                // Day of week (need re-build library by Tomasz Majcher)
  471.     String    sEN_DayOfWeek;                                // Day of week (need re-build library by Tomasz Majcher)
  472.     String    sPL_Month;
  473.     String    sEN_Month;
  474.    
  475. }
  476. MyClock;
  477.  
  478. // ------------------------------------------------------------------------------------------------------------------- //
  479. // --- W E A T H E R ------------------------------------------------------------------------------------------------- //
  480. // ------------------------------------------------------------------------------------------------------------------- //
  481.  
  482. struct Weather
  483. {
  484.     char      city[30];                 // ok - miasto
  485.     char      country[30];              // ok - kraj
  486.     char      tz_id[30];                // ok - kontynent/stolica
  487.     double    lat = 0;                  // ok - szerokość geograficzna
  488.     double    lon = 0;                  // ok - długość geograficzna
  489.     int       localtime_epoch = 0;      // ok - czas lokalny - format epoch (1629046610)
  490.     char      localtime[30];            // ok - czas lokalny - format string (2021-08-15 18:56)
  491.     char      last_updated[30];         // ok - czas ostatniej aktualizacji - format string (2021-08-15 18:45)
  492.     double    temp_c = 0;               // ok - temperatura w st.C
  493.     double    feelslike_c = 0;          // ok - temperatura odczuwalna w st.C
  494.     double    temp_f = 0;               // ok - temperatura w st.F
  495.     double    feelslike_f = 0;          // ok - temperatura odczuwalna w st.F
  496.     char      condition_en[50];         // ok - kondycja pogody np. Sunny, Cloud, etc
  497.     char      condition_pl[50];         // ok - kondycja pogody np. Słonecznie, Pochmurnie, etc
  498.     char      icon[100];                // ok - adres grafiki //cdn.weatherapi.com/weather/64x64/day/113.png
  499.     int       code = 0;                 // ok - kod czegoś, 1000
  500.     double    wind_mph = 0;             // ok - prędkość wiatru w milach/h
  501.     double    wind_kph = 0;             // ok - prędkość wiatru w km/h
  502.     int       wind_degree = 0;          // ok - kierunek wiatru w stopniach
  503.     char      wind_dir[10];             // ok - kierunek wiatru np. NNE
  504.     int       pressure_mb = 0;          // ok - cisnienie atmosferyczne
  505.     double    pressure_in = 0;          // ok - huj wie co to !!!
  506.     double    precip_mm = 0;            // ok - opady [mm]
  507.     double    precip_in = 0;            // ok - huj wie co to !!!
  508.     int       humidity = 0;             // ok - wilgotnosc powietrza
  509.     int       cloud = 0;                // zachmurzenie
  510.     double    vis_km = 0;               // widzialność w km
  511.     double    vis_miles = 0;            // widzialność w milach
  512.     double    uv = 0;                   // index UV
  513.     double    gust_mph = 0;             // * porywy wiatru w milach
  514.     double    gust_kph = 0;             // * porywy wiatru w kilometrach
  515. };
  516.  
  517. struct  Weather *ptrWeather;            // wskaźnik do struktury Weather
  518. bool F_ptrWeather = false;              // flaga dla wskaźnika alokacji pamięci dla strukury
  519. bool F_WeatherUpdate = false;
  520.  
  521. // ------------------------------------------------------------------------------------------------------------ //
  522. // ---        S T R U C T   A S T R O N O M Y                                                               --- //    
  523. // ------------------------------------------------------------------------------------------------------------ //
  524.  
  525. struct Astronomy
  526. {
  527.     char      city[30];                 // ok - miasto
  528.     char      country[30];              // ok - kraj    
  529.     char      tz_id[30];                // ok - kontynent/stolica
  530.     double    lat = 0;                  // ok - szerokość geograficzna
  531.     double    lon = 0;                  // ok - długość geograficzna
  532.     int       localtime_epoch = 0;      // ok - czas lokalny - format epoch (1629046610)
  533.     char      localtime[30];            // ok - czas lokalny - format string (2021-08-15 18:56)
  534.     char      sunrise[20];              // wschód słońca
  535.     char      sunset[20];               // zachód słońca
  536.     char      moonrise[20];             // wschód księżyca
  537.     char      moonset[20];              // zachód księżyca
  538.     char      moon_phase[30];           // faza księżyca
  539.     int       moon_illumination = 0;    // iluminacja
  540. };
  541.  
  542.  // ------------------------------------------------------------------------------------------------------------ //
  543.  
  544. struct  Astronomy *ptrAstronomy;         // wskaźnik do struktury Weather
  545. bool    F_ptrAstronomy = false;          // flaga (false jesli struktura Astronomy nie została utworzona)
  546. bool    F_AstronomyUpdate = false;
  547.  
  548. // ------------------------------------------------------------------------------------------------------------ //
  549. // ---        S T R U C T   A I R                                                                           --- //    
  550. // ------------------------------------------------------------------------------------------------------------ //
  551.  
  552. struct Air
  553. {
  554.     double  co      = 0;                     // Carbon Monoxide (μg/m3)    -   Tlenek węgla (μg / m3)
  555.     double  o3      = 0;                     // Ozone (μg/m3)              -   Ozon (μg / m3)
  556.     double  no2     = 0;                     // Nitrogen dioxide (μg/m3)   -   Dwutlenek azotu (μg / m3)
  557.     double  so2     = 0;                     // Sulphur dioxide (μg/m3)    -   Dwutlenek siarki (μg / m3)
  558.     double  pm25    = 0;                     // PM2.5 (μg/m3)              -   aerozole atmosferyczne o średnicy nie większej niż 2,5 μm
  559.     double  pm10    = 0;                     // PM10 (μg/m3)               -   mieszanina zawieszonych w powietrzu cząsteczek o średnicy nie większej niż 10 μm
  560.     int     defra   = 0;                     // Air Quality Index          -   index jakości powietrza    
  561.     int     epa     = 0;                     // Air Quality Index          -   index jakosci powietrza (standard EPA)
  562.     char    description[50];                 // Air Quality descriptin     -   opis jakości powietrza (standard EPA)
  563. };
  564.  
  565. // ------------------------------------------------------------------------------------------------------------ //
  566.  
  567. struct  Air *ptrAir;                // wskaźnik do struktury Air
  568. bool    F_ptrAir = false;           // flaga (false jesli struktura Air nie została utworzona)
  569. bool    F_AirUpdate = false;        // flaga błędu
  570.  
  571. // ------------------------------------------------------------------------------------------------------------ //
  572.  
  573. void SuperMsgCreate()
  574. {
  575.      super_msg = GetSuperMsg(myRTC.month, myRTC.dayofmonth);    
  576. }
  577.  
  578. // ------------------------------------------------------------------------------------------------------------------- //
  579. // --- S E R I A L    I N I T ---------------------------------------------------------------------------------------- //
  580. // ------------------------------------------------------------------------------------------------------------------- //
  581.  
  582. void SerialInit()
  583. {
  584.     #if SERIAL
  585.         Serial.begin(SerialSpeed);                            // init Serial and set speed
  586.         while (!Serial);                                      // wait if not ready
  587.         PRINT(F("\n\n"));                                     // next line please
  588.     #endif    
  589. }
  590.  
  591. // ------------------------------------------------------------------------------------------------------------------- //
  592. // --- D R A W   L I N E --------------------------------------------------------------------------------------------- //
  593. // ------------------------------------------------------------------------------------------------------------------- //
  594.  
  595. void DrawLine(byte l, char s)
  596. {
  597.     #if SERIAL
  598.         PRINT(F("\n"));
  599.         for (byte i=0; i<l; i++) Serial.print(s);        
  600.     #endif
  601. }
  602.  
  603. // ------------------------------------------------------------------------------------------------------------------- //
  604. // --- W i F i   I N I T --------------------------------------------------------------------------------------------- //
  605. // ------------------------------------------------------------------------------------------------------------------- //
  606.  
  607. void WiFiInit()
  608. {
  609.     WiFi.mode(WIFI_STA);
  610.     WiFi.begin(ssid, pass);
  611.  
  612.     #if SERIAL    
  613.         #if ENGLISH
  614.             PRINT(F("\n[ESP] [WiFI] Connecting to WiFi .."));
  615.         #endif
  616.         #if POLISH
  617.             PRINT(F("\n[ESP] [WiFI] Łącze z siecią WiFi .."));
  618.         #endif        
  619.     #endif
  620.  
  621.     // --------------------------------------------------------------------------------------- //
  622.     // --- TFT MONITOR ----------------------------------------------------------------------- //
  623.     // --------------------------------------------------------------------------------------- //
  624.    
  625.     tft.fillScreen(TFT_BLACK);    
  626.     drawJpeg("/wifi.jpeg", 40, 5);            
  627.    
  628.     tft.setTextSize(1);              
  629.     tft.setTextColor(TFT_DARKGREY);                                
  630.  
  631.     #if ENGLISH
  632.         tft.drawString("Connecting to WiFi",50,10,4);    
  633.     #endif
  634.     #if POLISH
  635.         tft.drawString("Lacze z siecia WiFi",50,10,4);    
  636.     #endif
  637.  
  638.     // --------------------------------------------------------------------------------------- //
  639.     // --- Connect to WIFI ------------------------------------------------------------------- //
  640.     // --------------------------------------------------------------------------------------- //
  641.  
  642.     int x = 0;
  643.     int colorWIFI = TFT_LIGHTGREY;
  644.          
  645.     while (WiFi.status() != WL_CONNECTED)
  646.     {
  647.         tft.fillRect(20+x,230,7,7,colorWIFI);    
  648.  
  649.         if (x < 280)
  650.         {
  651.             x = x + 20;            
  652.         }
  653.         else
  654.         {
  655.             x = 0;
  656.             if (colorWIFI == 54938) colorWIFI = TFT_DARKGREY;
  657.             else
  658.             if (colorWIFI == 31727) colorWIFI = TFT_LIGHTGREY;
  659.         }
  660.         delay(10);        
  661.     }
  662.  
  663.     WiFiStat();
  664.          
  665.     WiFi.setAutoReconnect(true);
  666.     WiFi.persistent(true);
  667.     tft.fillScreen(TFT_BLACK);    
  668. }
  669.  
  670. // ------------------------------------------------------------------------------------------------------------------- //
  671. // --- WiFiStat ------------------------------------------------------------------------------------------------------ //
  672. // ------------------------------------------------------------------------------------------------------------------- //
  673.  
  674. void WiFiStat()
  675. {
  676.     switch (WiFi.status())
  677.     {
  678.         case WL_NO_SSID_AVAIL:
  679.                               #if SERIAL
  680.                                   #if ENGLISH
  681.                                       PRINT(F("\n[ESP] [WiFI] Configured SSID cannot be reached"));
  682.                                   #endif
  683.                                   #if POLISH
  684.                                       PRINT(F("\n[ESP] [WiFI] Nie można osiągnąć skonfigurowanego identyfikatora SSID"));
  685.                                   #endif                                  
  686.                               #endif        
  687.                               break;
  688.                              
  689.         case WL_CONNECTED:
  690.                               #if SERIAL
  691.                                   #if ENGLISH
  692.                                       PRINT(F("\n[ESP] [WiFI] Connection successfully established"));
  693.                                       PRINT(F("\n[ESP] [WiFI] Your IP : %s"), WiFi.localIP().toString().c_str());
  694.                                       PRINT(F("\n[ESP] [WiFI] Received Signal Strength Indication : %d"), WiFi.RSSI());
  695.                                   #endif
  696.                                   #if POLISH
  697.                                       PRINT(F("\n[ESP] [WiFI] Pomyślnie nawiązano połączenie"));
  698.                                       PRINT(F("\n[ESP] [WiFI] Twój adres IP : %s"), WiFi.localIP().toString().c_str());
  699.                                       PRINT(F("\n[ESP] [WiFI] Wskazanie siły odbieranego sygnału : %d"), WiFi.RSSI());
  700.                                   #endif                                
  701.                               #endif
  702.                               break;
  703.                              
  704.         case WL_CONNECT_FAILED:
  705.                               #if SERIAL
  706.                                   #if ENGLISH
  707.                                       PRINT(F("\n[ESP] [WiFI] Connection failed"));
  708.                                   #endif
  709.                                   #if POLISH
  710.                                       PRINT(F("\n[ESP] [WiFI] Połączenie nieudane"));
  711.                                   #endif                                  
  712.                               #endif
  713.                               break;
  714.       }      
  715. }
  716.  
  717. // ------------------------------------------------------------------------------------------------------------------- //
  718. // --- reconect Wi-Fi ------------------------------------------------------------------------------------------------ //
  719. // ------------------------------------------------------------------------------------------------------------------- //
  720.  
  721. void WiFiReconect()
  722. {
  723.     unsigned long currentMillis = millis();
  724.      
  725.     if ((WiFi.status() != WL_CONNECTED) && (currentMillis - previousMillis >=interval))     // if no WiFi connect now
  726.     {
  727.         #if SERIAL
  728.             #if ENGLISH
  729.                 PRINT(F("\n[ESP] [WiFI] Reconnecting to WiFi..."));
  730.             #endif
  731.             #if POLISH
  732.                 PRINT(F("\n[ESP] [WiFI] Ponowne łączenie z Wi-Fi..."));
  733.             #endif
  734.         #endif
  735.          
  736.         WiFi.disconnect();
  737.         WiFi.begin(ssid, pass);
  738.          
  739.         WiFiStat();                                       // show WiFi Status
  740.          
  741.         previousMillis = currentMillis;
  742.     }
  743. }
  744.  
  745. // ------------------------------------------------------------------------------------------------------------------- //
  746. // --- R T C U P A T E------------------------------------------------------------------------------------------------ //
  747. // ------------------------------------------------------------------------------------------------------------------- //
  748.  
  749. void myRTC_Update()
  750. {
  751.     if ( WiFi.status() == WL_CONNECTED )                  // if WiFi is OK
  752.     {
  753.       timeClient.update();
  754.       myRTC.setDS1302Time(timeClient.getSeconds(), timeClient.getMinutes(), timeClient.getHours(), timeClient.getWeek(), timeClient.getDay(), timeClient.getMonth(), timeClient.getYear());
  755.       myRTC.updateTime();
  756.  
  757.       #if SERIAL
  758.           #if ENGLISH
  759.               PRINT(F("\n\n[ESP] [RTC] RTC module updated "));              
  760.           #endif
  761.           #if POLISH
  762.               PRINT(F("\n\n[ESP] [RTC] czas został zaktualizowany i zsynchronizowany "));              
  763.           #endif
  764.       #endif
  765.     }
  766.    
  767. }
  768.  
  769. // ------------------------------------------------------------------------------------------------------------------- //
  770. // ---N T P   I N I T ------------------------------------------------------------------------------------------------ //
  771. // ------------------------------------------------------------------------------------------------------------------- //
  772.  
  773. int NTPInit()
  774. {
  775.     timeClient.update();
  776.  
  777.     if (timeClient.updated())
  778.     {  
  779.         #if SERIAL
  780.             DrawLine(60,'*');
  781.             #if ENGLISH
  782.                 PRINT(F("\n[ESP] [NTP] Time Update :-)"));
  783.                 PRINT(F("\n[ESP] [NTP] Using NTP Server : %s"), timeClient.getPoolServerName().c_str());
  784.             #endif
  785.             #if POLISH
  786.                 PRINT(F("\n[ESP] [NTP] Czas został zaktualizowany :-)"));
  787.                 PRINT(F("\n[ESP] [NTP] Używasz Serwera NTP : %s"), timeClient.getPoolServerName().c_str());
  788.             #endif
  789.         #endif        
  790.         return 1;                     // return 1 if time is update
  791.     }
  792.     else
  793.     {
  794.         #if SERIAL
  795.             #if ENGLISH
  796.                 PRINT(F("\n[ESP] [NTP] Time in not Update !!!"));
  797.             #endif
  798.             #if POLISH
  799.                 PRINT(F("\n[ESP] [NTP] Czas nie został zaktualizowany !!!"));
  800.             #endif
  801.         #endif
  802.  
  803.         return 0;                     // return 0 if time is not update
  804.     }
  805. }
  806.  
  807. // ------------------------------------------------------------------------------------------------------------------- //
  808. // --- S H O W   N T P ----------------------------------------------------------------------------------------------- //
  809. // ------------------------------------------------------------------------------------------------------------------- //
  810.  
  811. void Show_NTP()
  812. {
  813.     myRTC.updateTime();    
  814.     #if SERIAL
  815.         DrawLine(60,'*');
  816.         #if POLISH
  817.             //Serial.printf("\n[ESP] [TIME] UTC Czas : %s", timeClient.getFormattedUTCTime().c_str());
  818.             //Serial.printf("\n[ESP] [TIME] UTC Data : %d/%d/%d", timeClient.getUTCDay(),timeClient.getUTCMonth(),timeClient.getUTCYear());
  819.             //Serial.printf("\n[ESP] [TIME] LOC Czas : %s", timeClient.getFormattedTime().c_str());
  820.             //Serial.printf("\n[ESP] [TIME] LOC Data : %d/%d/%d", timeClient.getDay(),timeClient.getMonth(),timeClient.getYear());
  821.             //Serial.printf("\n[ESP] [TIME] EXT Data : %s %d %s %d", MyClock.sPL_DayOfWeek.c_str(), timeClient.getDay(), MyClock.sPL_Month, timeClient.getYear());
  822.             //Serial.printf("\n[ESP] [TIME] RTC Czas : %d:%d:%d", myRTC.hours, myRTC.minutes, myRTC.seconds);
  823.             //Serial.printf("\n[ESP] [TIME] RTC Data : %d/%d/%d", myRTC.dayofmonth, myRTC.month, myRTC.year);  
  824.             PRINT(F("\n[ESP] [TIME] RTC Czas : %d:%d:%d"), myRTC.hours, myRTC.minutes, myRTC.seconds);
  825.             PRINT(F("\n[ESP] [TIME] RTC Data : %d/%d/%d"), myRTC.dayofmonth, myRTC.month, myRTC.year);          
  826.  
  827.             // Szkic używa 464633 bajtów (44%) pamięci programu. Maksimum to 1044464 bajtów.
  828.             // Zmienne globalne używają 42860 bajtów (52%) pamięci dynamicznej, pozostawiając 39060 bajtów dla zmiennych lokalnych. Maksimum to 81920 bajtów.
  829.             // bez makra F dla printf
  830.             // Szkic używa 464749 bajtów (44%) pamięci programu. Maksimum to 1044464 bajtów.
  831.             // Zmienne globalne używają 42784 bajtów (52%) pamięci dynamicznej, pozostawiając 39136 bajtów dla zmiennych lokalnych. Maksimum to 81920 bajtów.
  832.             // z makrem F dla printf
  833.         #endif
  834.         #if ENGLISH
  835.             //Serial.printf("\n[ESP] [TIME] UTC Time : %s", timeClient.getFormattedUTCTime().c_str());
  836.             //Serial.printf("\n[ESP] [TIME] UTC Data : %d/%d/%d", timeClient.getUTCDay(),timeClient.getUTCMonth(),timeClient.getUTCYear());
  837.             //Serial.printf("\n[ESP] [TIME] LOC Time : %s", timeClient.getFormattedTime().c_str());
  838.             //Serial.printf("\n[ESP] [TIME] LOC Data : %d/%d/%d", timeClient.getDay(),timeClient.getMonth(),timeClient.getYear());
  839.             //Serial.printf("\n[ESP] [TIME] EXT Data : %s %d %s %d", MyClock.sEN_DayOfWeek, timeClient.getDay(), MyClock.sEN_Month, timeClient.getYear());
  840.             PRINT(F("\n[ESP] [TIME] RTC Time : %d:%d:%d"), myRTC.hours, myRTC.minutes, myRTC.seconds);
  841.             PRINT(F("\n[ESP] [TIME] RTC Data : %d/%d/%d"), myRTC.dayofmonth, myRTC.month, myRTC.year);  
  842.         #endif
  843.     #endif
  844. }
  845.  
  846. // ------------------------------------------------------------------------------------------------------------------- //
  847. // --- U P D A T E   M Y N T P   S T R U C T U R E ------------------------------------------------------------------- //
  848. // ------------------------------------------------------------------------------------------------------------------- //
  849.  
  850. void MyClock_Update()
  851. {    
  852.     // *** L O C   T I M E   &   D A T A *** ///
  853.    
  854.     myRTC.updateTime();
  855.    
  856.     MyClock.iLOCYear      = myRTC.year;
  857.     MyClock.iLOCMonth     = myRTC.month;    
  858.     MyClock.iLOCWeekDay   = myRTC.dayofweek;
  859.     MyClock.iLOCDay       = myRTC.dayofmonth;
  860.     MyClock.iLOCHours     = myRTC.hours;    
  861.     MyClock.iLOCMinutes   = myRTC.minutes;    
  862.     MyClock.iLOCSeconds   = myRTC.seconds;
  863.  
  864.     // *** E X T R A   C H A R *** ///
  865.  
  866.     if( MyClock.iLOCHours < 10 )
  867.     {
  868.         strcpy (MyClock.cHour, "0");                                          // 0H:MM:SS
  869.         strcat (MyClock.cHour, String(MyClock.iLOCHours).c_str());            // 01:MM:SS
  870.     }
  871.     else
  872.     if( MyClock.iLOCHours > 9 )
  873.     {
  874.         strcpy (MyClock.cHour, String(MyClock.iLOCHours).c_str());             // 01:MM:SS
  875.     }
  876.  
  877.     if( MyClock.iLOCMinutes < 10 )
  878.     {
  879.         strcpy (MyClock.cMinutes, "0");                                       // HH:0M:SS
  880.         strcat (MyClock.cMinutes, String(MyClock.iLOCMinutes).c_str());       // 01:M0:SS
  881.     }
  882.     else
  883.     if( MyClock.iLOCMinutes > 9 )
  884.     {
  885.         strcpy (MyClock.cMinutes, String(MyClock.iLOCMinutes).c_str());       // HH:10:SS
  886.     }
  887.  
  888.     if( MyClock.iLOCSeconds < 10 )
  889.     {
  890.         strcpy (MyClock.cSeconds, "0");                                       // HH:MM:0S
  891.         strcat (MyClock.cSeconds, String(MyClock.iLOCSeconds).c_str());       // HH:MH:S0
  892.     }
  893.     else
  894.     if( MyClock.iLOCSeconds > 9 )
  895.     {
  896.         strcpy (MyClock.cSeconds, String(MyClock.iLOCSeconds).c_str());        // HH:MM:10
  897.     }
  898.  
  899.     // *** E X T R A   S T R I N G   *** ///
  900.  
  901.     // Zmienne globalne używają 43680 bajtów (53%) pamięci dynamicznej, pozostawiając 38240 bajtów dla zmiennych lokalnych. Maksimum to 81920 bajtów.
  902.     // bez PROGMEM
  903.    
  904.     char buf[30];
  905.     strcpy_P(buf, (char*) pgm_read_dword(&(PL_MONTH[MyClock.iLOCMonth])));
  906.     MyClock.sPL_Month = String(buf);
  907.     strcpy_P(buf, (char*) pgm_read_dword(&(EN_MONTH[MyClock.iLOCMonth])));
  908.     MyClock.sEN_Month = String(buf);
  909.  
  910.     // Zmienne globalne używają 43388 bajtów (52%) pamięci dynamicznej, pozostawiając 38532 bajtów dla zmiennych lokalnych. Maksimum to 81920 bajtów.
  911.     // z PROGMEM
  912.  
  913.     // Szkic używa 464601 bajtów (44%) pamięci programu. Maksimum to 1044464 bajtów.
  914.     // Zmienne globalne używają 43388 bajtów (52%) pamięci dynamicznej, pozostawiając 38532 bajtów dla zmiennych lokalnych. Maksimum to 81920 bajtów.
  915.     // bez PROGMEM
  916.  
  917.     strcpy_P(buf, (char*) pgm_read_dword(&(PL_DAY[MyClock.iLOCWeekDay])));
  918.     MyClock.sPL_DayOfWeek = String(buf);
  919.     strcpy_P(buf, (char*) pgm_read_dword(&(EN_DAY[MyClock.iLOCWeekDay])));
  920.     MyClock.sEN_DayOfWeek = String(buf);
  921.  
  922.     // Szkic używa 464649 bajtów (44%) pamięci programu. Maksimum to 1044464 bajtów.
  923.     // Zmienne globalne używają 43196 bajtów (52%) pamięci dynamicznej, pozostawiając 38724 bajtów dla zmiennych lokalnych. Maksimum to 81920 bajtów.
  924.     // z PROGMEM
  925.  
  926.     //MyClock.sPL_DayOfWeek       = PL_DAY[MyClock.iLOCWeekDay];      // day of week (dzień tygodnia) POLISH (need Re-Build Library NTP by Tomasz Majcher)
  927.     //MyClock.sPL_DayOfWeek       = EN_DAY[MyClock.iLOCWeekDay];      // day of week (dzień tygodnia) ENGLISH(need Re-Build Library NTP by Tomasz Majcher)    
  928.     //MyClock.sPL_Month           = PL_MONTH[MyClock.iLOCMonth];      // month (miesiąc) in POLISH
  929.     //MyClock.sEN_Month           = EN_MONTH[MyClock.iLOCMonth];      // month (miesiąć) in ENGLISH
  930.  
  931.  
  932.    
  933. }
  934.  
  935. // ------------------------------------------------------------------------------------------------------------------- //
  936. // --- T A S K   S E T U P ------------------------------------------------------------------------------------------- //
  937. // ------------------------------------------------------------------------------------------------------------------- //
  938.  
  939. void TaskInit()
  940. {
  941.     runner.init();                                       // inicjalizuj scheluder
  942.                                                                                  
  943.     runner.addTask(task_0);                              // dodaj zadanie do scheluder
  944.     task_0.enable();                                     // włącz zadanie do scheluder
  945.  
  946.     // Szkic używa 464649 bajtów (44%) pamięci programu. Maksimum to 1044464 bajtów.
  947.     // Zmienne globalne używają 43196 bajtów (52%) pamięci dynamicznej, pozostawiając 38724 bajtów dla zmiennych lokalnych. Maksimum to 81920 bajtów.
  948.     // bez makra F
  949.  
  950.     // Szkic używa 464649 bajtów (44%) pamięci programu. Maksimum to 1044464 bajtów.
  951.     // Zmienne globalne używają 42860 bajtów (52%) pamięci dynamicznej, pozostawiając 39060 bajtów dla zmiennych lokalnych. Maksimum to 81920 bajtów.
  952.     // z makrem F
  953.  
  954.    
  955.     #if SERIAL
  956.         #if ENGLISH
  957.             PRINT(F("\n[ESP] [TASK] Init Task0 - status OK"));
  958.         #endif
  959.         #if POLISH
  960.             PRINT(F("\n[ESP] [TASK] Init Task0 - wszystko w porządku"));
  961.         #endif
  962.     #endif
  963.        
  964.     runner.addTask(task_1);                              // dodaj zadanie do scheluder
  965.     task_1.enable();          
  966.  
  967.     #if SERIAL
  968.         #if ENGLISH
  969.             PRINT(F("\n[ESP] [TASK] Init Task1 - status OK"));
  970.         #endif
  971.         #if POLISH
  972.             PRINT(F("\n[ESP] [TASK] Init Task1 - wszystko w porządku"));
  973.         #endif
  974.     #endif
  975.    
  976.                              
  977.     runner.addTask(task_2);                              // dodaj zadanie do scheluder
  978.     task_2.enable();                  
  979.  
  980.     #if SERIAL
  981.         #if ENGLISH
  982.             PRINT(F("\n[ESP] [TASK] Init Task2 - status OK"));
  983.         #endif
  984.         #if POLISH
  985.             PRINT(F("\n[ESP] [TASK] Init Task2 - wszystko w porządku"));
  986.         #endif
  987.     #endif    
  988.                      
  989.     runner.addTask(task_3);                              // dodaj zadanie do scheluder
  990.     task_3.enable();                                     // włącz zadanie do scheluder
  991.  
  992.     #if SERIAL
  993.         #if ENGLISH
  994.             PRINT(F("\n[ESP] [TASK] Init Task3 - status OK"));
  995.         #endif
  996.         #if POLISH
  997.             PRINT(F("\n[ESP] [TASK] Init Task3 - wszystko w porządku"));
  998.         #endif
  999.     #endif
  1000.  
  1001.    
  1002.     runner.addTask(task_4);                              // dodaj zadanie do scheluder
  1003.     task_4.enable();                                     // włącz zadanie do scheluder
  1004.  
  1005.     #if SERIAL
  1006.         #if ENGLISH
  1007.             PRINT(F("\n[ESP] [TASK] Init Task4 - status OK"));
  1008.         #endif
  1009.         #if POLISH
  1010.             PRINT(F("\n[ESP] [TASK] Init Task4 - wszystko w porządku"));
  1011.         #endif
  1012.     #endif
  1013.    
  1014.     runner.addTask(task_5);                              // dodaj zadanie do scheluder
  1015.     task_5.enable();                                     // włącz zadanie do scheluder
  1016.  
  1017.     #if SERIAL
  1018.         #if ENGLISH
  1019.             PRINT(F("\n[ESP] [TASK] Init Task5 - status OK"));
  1020.         #endif
  1021.         #if POLISH
  1022.             PRINT(F("\n[ESP] [TASK] Init Task5 - wszystko w porządku"));
  1023.         #endif
  1024.     #endif
  1025.    
  1026.     runner.addTask(task_6);                              // dodaj zadanie do scheluder
  1027.     task_6.enable();                                     // włącz zadanie do scheluder
  1028.  
  1029.     #if SERIAL
  1030.         #if ENGLISH
  1031.             PRINT(F("\n[ESP] [TASK] Init Task6 - status OK"));
  1032.         #endif
  1033.         #if POLISH
  1034.             PRINT(F("\n[ESP] [TASK] Init Task6 - wszystko w porządku"));
  1035.         #endif
  1036.     #endif
  1037. }
  1038.  
  1039. // ------------------------------------------------------------------------------------------------------------------- //
  1040. // --- T A S K   C A L L B A C K ------------------------------------------------------------------------------------- //
  1041. // ------------------------------------------------------------------------------------------------------------------- //
  1042.  
  1043. void Task0Callback()    // run with interval 60 minutes
  1044. {  
  1045.     if (!FtimeUpdate)    
  1046.     {
  1047.       myRTC_Update();    
  1048.       myRTC.updateTime();      
  1049.       MyClock_Update();
  1050.       FtimeUpdate = true;
  1051.     }
  1052.  
  1053.     if (WiFi.status() == WL_CONNECTED)      // jeśli połączenie WiFi jest aktywne
  1054.     {
  1055.         WeatherUpdate();                    // aktualizuj pogodę
  1056.         AstronomyUpdate();                  // aktualizuj astronomię
  1057.         AirUpdate();                        // aktualizuj jakość powietrza
  1058.         SuperMsgCreate();                   // stwoj super_msg
  1059.     }
  1060. }
  1061.  
  1062. // ------------------------------------------------------------------------------------------------------------------- //
  1063. // --- T A S K   C A L L B A C K ------------------------------------------------------------------------------------- //
  1064. // ------------------------------------------------------------------------------------------------------------------- //
  1065.  
  1066. void Task1Callback()    // run with interval 60 seconds
  1067. {  
  1068.     MyClock_Update();
  1069.    
  1070.     #if SERIAL
  1071.         PRINT(F("\n\n[ESP] [TASK1] Inside Task1Callback() "));
  1072.         DrawLine(60,'*');
  1073.         PRINT(F("\n[ESP] [TASK1] [Memory Free]     : %u [kB]"), ESP.getFreeHeap());      
  1074.         PRINT(F("\n[ESP] [TASK1] [CPU frequency]   : %u [MHz]"),ESP.getCpuFreqMHz());  
  1075.         PRINT(F("\n[ESP] [TASK1] [WiFi IP]         : ")); Serial.print(WiFi.localIP() );
  1076.         PRINT(F("\n[ESP] [TASK1] RTC Time          : %d:%d:%d"), myRTC.hours, myRTC.minutes, myRTC.seconds);
  1077.         PRINT(F("\n[ESP] [TASK1] RTC Time          : %s:%s:%s"), MyClock.cHour, MyClock.cMinutes, MyClock.cSeconds);        
  1078.        
  1079.         #if ENGLISH
  1080.             PRINT(F("\n[ESP] [TASK1] Nameday           : %s"), GetNameday(myRTC.month, myRTC.dayofmonth).c_str());
  1081.             PRINT(F("\n[ESP] [TASK1] Event of the day  : %s"), GetEvent(myRTC.month, myRTC.dayofmonth).c_str());
  1082.             PRINT(F("\n[ESP] [TASK1] RTC Data          : %s %d/%d/%d"), MyClock.sEN_DayOfWeek, myRTC.dayofmonth, myRTC.month, myRTC.year);  
  1083.             PRINT(F("\n[ESP] [TASK1] RTC Data          : %s %d %s %d"), MyClock.sEN_DayOfWeek, myRTC.dayofmonth, MyClock.sEN_Month, myRTC.year);              
  1084.         #endif
  1085.  
  1086.         #if POLISH
  1087.             PRINT(F("\n[ESP] [TASK1] Imieniny obchodzą : %s"), GetNameday(myRTC.month, myRTC.dayofmonth).c_str());
  1088.             PRINT(F("\n[ESP] [TASK1] Wydarzenie dnia   : %s"), GetEvent(myRTC.month, myRTC.dayofmonth).c_str());
  1089.             PRINT(F("\n[ESP] [TASK1] RTC Data          : %s %d/%d/%d"), MyClock.sPL_DayOfWeek, myRTC.dayofmonth, myRTC.month, myRTC.year);  
  1090.             PRINT(F("\n[ESP] [TASK1] RTC Data          : %s %d %s %d"), MyClock.sPL_DayOfWeek, myRTC.dayofmonth, MyClock.sPL_Month, myRTC.year);              
  1091.         #endif    
  1092.        
  1093.     #endif  
  1094.    
  1095.     switch (myRTC.minutes)
  1096.     {
  1097.  
  1098.         case 2   :   {
  1099.                           if(F_display_clock)
  1100.                           {
  1101.                               F_display_clock  = false;      
  1102.                               F_display_temp   = true;      
  1103.                               F_display_moon   = false;
  1104.                               F_display_sun    = false;
  1105.                               F_refresh_all    = true;              // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
  1106.                               tft.fillRect(1,60,319,180,TFT_BLACK);                              
  1107.                           }
  1108.                           break;              
  1109.                       }  
  1110.         case  3   :  {              
  1111.                           if(!F_display_clock)
  1112.                           {
  1113.                               F_display_clock  = true;      
  1114.                               F_display_temp   = false;      
  1115.                               F_display_moon   = false;
  1116.                               F_display_sun    = false;
  1117.                               F_refresh_all    = true;              // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
  1118.                               tft.fillRect(1,60,319,180,TFT_BLACK);                              
  1119.                           }                                        
  1120.                       }
  1121.        
  1122.         case   5  :  {
  1123.                           if (F_display_clock)
  1124.                           {                              
  1125.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1126.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1127.                               tft.setTextSize(2);                                       // ustaw rozmiar fontów
  1128.                               tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów                  
  1129.                               tft.drawCentreString(super_msg, 160,217,1);               // wyświetl super msg
  1130.                           }                          
  1131.                           break;
  1132.                       }                        
  1133.  
  1134.         case   7   :  {
  1135.            
  1136.                           if (F_display_clock)
  1137.                           {                              
  1138.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1139.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1140.                               tft.setTextSize(2);                                           // ustaw rozmiar fontów
  1141.                               tft.setTextColor(TFT_LIGHTGREY);                              // ustaw kolor fontów                  
  1142.                               tft.drawCentreString("Free Memory : " + String(ESP.getFreeHeap()), 160,217,1);   // wyświetl sformatowaną datę pod zegarem na TFT    
  1143.                           }                          
  1144.                           break;
  1145.                       }
  1146.  
  1147.         case 8   :   {
  1148.                           if(F_display_clock)
  1149.                           {
  1150.                               F_display_clock  = false;      
  1151.                               F_display_temp   = true;      
  1152.                               F_display_moon   = false;
  1153.                               F_display_sun    = false;
  1154.                               F_refresh_all    = true;              // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
  1155.                               tft.fillRect(1,60,319,180,TFT_BLACK);                              
  1156.                           }
  1157.                           break;              
  1158.                       }  
  1159.         case  9   :   {              
  1160.                           if(!F_display_clock)
  1161.                           {
  1162.                               F_display_clock  = true;      
  1163.                               F_display_temp   = false;      
  1164.                               F_display_moon   = false;
  1165.                               F_display_sun    = false;
  1166.                               F_refresh_all    = true;              // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
  1167.                               tft.fillRect(1,60,319,180,TFT_BLACK);                              
  1168.                           }                                        
  1169.                       }              
  1170.    
  1171.         case  10   :  {
  1172.                           if (F_display_clock)
  1173.                           {                              
  1174.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1175.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1176.                               tft.setTextSize(2);                                       // ustaw rozmiar fontów
  1177.                               tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów                  
  1178.                               tft.drawCentreString(super_msg, 160,217,1);               // wyświetl super msg
  1179.                           }                          
  1180.                           break;
  1181.                       }        
  1182.        
  1183.         case  12   :  {
  1184.                           if (F_display_clock)
  1185.                           {
  1186.                               #if ENGLISH
  1187.                                   String bufor = "Temperature " + String(ptrWeather->temp_c) + " st.C";
  1188.                               #endif
  1189.                               #if POLISH
  1190.                                   String bufor = "Temperatura " + String(ptrWeather->temp_c) + " st.C";
  1191.                               #endif
  1192.                              
  1193.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1194.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1195.                               tft.setTextSize(2);                                       // ustaw rozmiar fontów
  1196.                               tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów                  
  1197.                               tft.drawCentreString(bufor, 160,217,1);                   // wyświetl temperarurę            
  1198.                           }                          
  1199.                           break;                          
  1200.                       }                      
  1201.                        
  1202.         case  15   :  {
  1203.                           if (F_display_clock)
  1204.                           {
  1205.                               #if ENGLISH
  1206.                                   String bufor = "Humidity " + String(ptrWeather->humidity) + " %";
  1207.                               #endif
  1208.                               #if POLISH
  1209.                                   String bufor = "Wilgotnosc " + String(ptrWeather->humidity) + " %";
  1210.                               #endif
  1211.                              
  1212.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1213.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1214.                               tft.setTextSize(2);                                       // ustaw rozmiar fontów
  1215.                               tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów                  
  1216.                               tft.drawCentreString(bufor, 160,217,1);                   // wyświetl wilgotność            
  1217.                           }                          
  1218.                           break;
  1219.                       }  
  1220.         case 17   :   {
  1221.                           if(F_display_clock)
  1222.                           {
  1223.                               F_display_clock  = false;      
  1224.                               F_display_temp   = true;      
  1225.                               F_display_moon   = false;
  1226.                               F_display_sun    = false;
  1227.                               F_refresh_all    = true;              // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
  1228.                               tft.fillRect(1,60,319,180,TFT_BLACK);                              
  1229.                           }
  1230.                           break;              
  1231.                       }  
  1232.         case  18   :  {              
  1233.                           if(!F_display_clock)
  1234.                           {
  1235.                               F_display_clock  = true;      
  1236.                               F_display_temp   = false;      
  1237.                               F_display_moon   = false;
  1238.                               F_display_sun    = false;
  1239.                               F_refresh_all    = true;              // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
  1240.                               tft.fillRect(1,60,319,180,TFT_BLACK);                              
  1241.                           }                                        
  1242.                       }
  1243.         case  19   :  {
  1244.                           if (F_display_clock)
  1245.                           {
  1246.                               #if ENGLISH
  1247.                                   String bufor = "Pressure " + String(ptrWeather->pressure_mb    ) + " mPA";
  1248.                               #endif
  1249.                               #if POLISH
  1250.                                   String bufor = "Ciśnienie " + String(ptrWeather->pressure_mb    ) + " mPA";
  1251.                               #endif
  1252.                                
  1253.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1254.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1255.                               tft.setTextSize(2);                                       // ustaw rozmiar fontów
  1256.                               tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów                  
  1257.                               tft.drawCentreString(bufor, 160,217,1);                   // wyświetl cisnienie atmosferyczne            
  1258.                           }                          
  1259.                           break;
  1260.                       }  
  1261.  
  1262.        
  1263.  
  1264.         case  21   :  {
  1265.                           if (F_display_clock)
  1266.                           {
  1267.                               #if ENGLISH
  1268.                                   String bufor = "Wind " + String(ptrWeather->wind_kph) + " km/h";
  1269.                               #endif
  1270.                               #if POLISH
  1271.                                   String bufor = "Wiatr " + String(ptrWeather->wind_kph) + " km/h";
  1272.                               #endif
  1273.                              
  1274.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1275.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1276.                               tft.setTextSize(2);                                       // ustaw rozmiar fontów
  1277.                               tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów                  
  1278.                               tft.drawCentreString(bufor, 160,217,1);                   // wyświetl prędkość wiatru
  1279.                           }                          
  1280.                           break;
  1281.                       }    
  1282.  
  1283.         case  23   :  {
  1284.                           if (F_display_clock)
  1285.                           {
  1286.                               #if ENGLISH                    
  1287.                                   String bufor = "Rainfall " + String(ptrWeather->precip_mm) + " mm";
  1288.                               #endif
  1289.                               #if POLISH
  1290.                                   String bufor = "Opady " + String(ptrWeather->precip_mm) + " mm";
  1291.                               #endif
  1292.                              
  1293.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1294.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1295.                               tft.setTextSize(2);                                       // ustaw rozmiar fontów
  1296.                               tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów                  
  1297.                               tft.drawCentreString(bufor, 160,217,1);                   // wyświetl opady atmosferyczne          
  1298.                           }                          
  1299.                           break;
  1300.                       }      
  1301.          
  1302.        
  1303.                      
  1304.         case  25   :  {
  1305.                           if (F_display_clock)
  1306.                           {
  1307.                               #if ENGLISH                          
  1308.                                   String bufor = "Cloudy " + String(ptrWeather->cloud) + " %";
  1309.                               #endif
  1310.                               #if POLISH
  1311.                                   String bufor = "Zachmurzenie " + String(ptrWeather->cloud) + " %";
  1312.                               #endif
  1313.                              
  1314.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1315.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1316.                               tft.setTextSize(2);                                       // ustaw rozmiar fontów
  1317.                               tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów                  
  1318.                               tft.drawCentreString(bufor, 160,217,1);                   // wyświetl zachmurzenie w %          
  1319.                           }                          
  1320.                           break;
  1321.                       }    
  1322.                    
  1323.         case  26   :  {
  1324.                           if (F_display_clock)
  1325.                           {
  1326.                               String bufor;
  1327.                          
  1328.                               #if ENGLISH                            
  1329.                                   bufor = "Visibility " + String(ptrWeather->vis_km) + " km";
  1330.                               #endif                                  
  1331.                               #if POLISH
  1332.                                   bufor = "Widzialnosc " + String(ptrWeather->vis_km) + " km";
  1333.                               #endif
  1334.                              
  1335.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1336.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1337.                               tft.setTextSize(2);                                       // ustaw rozmiar fontów
  1338.                               tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów                  
  1339.                               tft.drawCentreString(bufor, 160,217,1);                   // wyświetl widzialność w km            
  1340.                           }                          
  1341.                           break;
  1342.                       }  
  1343.        
  1344.        
  1345.         case 27   :   {
  1346.                           if(F_display_clock)
  1347.                           {
  1348.                               F_display_clock  = false;      
  1349.                               F_display_temp   = true;      
  1350.                               F_display_moon   = false;
  1351.                               F_display_sun    = false;
  1352.                               F_refresh_all    = true;              // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
  1353.                               tft.fillRect(1,60,319,180,TFT_BLACK);                                                                
  1354.                           }
  1355.                           break;              
  1356.                       }  
  1357.         case  28   :  {              
  1358.                           if(!F_display_clock)
  1359.                           {
  1360.                               F_display_clock  = true;      
  1361.                               F_display_temp   = false;      
  1362.                               F_display_moon   = false;
  1363.                               F_display_sun    = false;
  1364.                               F_refresh_all    = true;              // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
  1365.                               tft.fillRect(1,60,319,180,TFT_BLACK);                              
  1366.                           }                                        
  1367.                       }
  1368.         case  29   :  {
  1369.                           if (F_display_clock)
  1370.                           {
  1371.                               #if ENGLISH                          
  1372.                                   String bufor = "Sunrise" + String(ptrAstronomy->sunrise);
  1373.                               #endif
  1374.                               #if POLISH
  1375.                                   String bufor = "Wschod slonca " + String(ptrAstronomy->sunrise);
  1376.                               #endif
  1377.                              
  1378.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1379.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1380.                               tft.setTextSize(2);                                       // ustaw rozmiar fontów
  1381.                               tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów                  
  1382.                               tft.drawCentreString(bufor, 160,217,1);                   // wyświetl godzinę wschodu słońca          
  1383.                           }                          
  1384.                           break;
  1385.                       }
  1386.  
  1387.         case 30   :   {
  1388.                           if(F_display_clock)
  1389.                           {
  1390.                               F_display_clock  = false;      
  1391.                               F_display_temp   = true;      
  1392.                               F_display_moon   = false;
  1393.                               F_display_sun    = false;
  1394.                               F_refresh_all    = true;              // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
  1395.                               tft.fillRect(1,60,319,180,TFT_BLACK);                              
  1396.                           }
  1397.                           break;              
  1398.                       }  
  1399.         case  31   :  {
  1400.              
  1401.                           if(!F_display_clock)
  1402.                           {
  1403.                               F_display_clock  = true;      
  1404.                               F_display_temp   = false;      
  1405.                               F_display_moon   = false;
  1406.                               F_display_sun    = false;
  1407.                               F_refresh_all    = true;              // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
  1408.                               tft.fillRect(1,60,319,180,TFT_BLACK);                              
  1409.                           }                          
  1410.                          
  1411.                           if (F_display_clock)
  1412.                           {
  1413.                               #if ENGLISH                          
  1414.                                   String bufor = "Sunset " + String(ptrAstronomy->sunset);
  1415.                               #endif
  1416.                               #if POLISH
  1417.                                   String bufor = "Zachod slonca " + String(ptrAstronomy->sunset);
  1418.                               #endif
  1419.                              
  1420.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1421.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1422.                               tft.setTextSize(2);                                       // ustaw rozmiar fontów
  1423.                               tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów                  
  1424.                               tft.drawCentreString(bufor, 160,217,1);                   // wyświetl godzinę zachodu słońca          
  1425.                           }                          
  1426.                           break;
  1427.                       }  
  1428.  
  1429.         case  32   :  {
  1430.                           if (F_display_clock)
  1431.                           {                              
  1432.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1433.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1434.                               tft.setTextSize(2);                                       // ustaw rozmiar fontów
  1435.                               tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów                  
  1436.                               tft.drawCentreString(super_msg, 160,217,1);               // wyświetl super msg
  1437.                           }                          
  1438.                           break;
  1439.                       }  
  1440.                      
  1441.         case  33   :  {
  1442.                      
  1443.                           if(F_display_clock)
  1444.                           {
  1445.                               F_display_clock  = false;      
  1446.                               F_display_temp   = true;      
  1447.                               F_display_moon   = false;
  1448.                               F_display_sun    = false;
  1449.                               F_refresh_all    = true;              // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
  1450.                               tft.fillRect(1,60,319,180,TFT_BLACK);                              
  1451.                           }
  1452.                           break;              
  1453.                    
  1454.                       }
  1455.        
  1456.         case  34   :  {
  1457.  
  1458.                           if(!F_display_clock)
  1459.                           {
  1460.                               F_display_clock  = true;      
  1461.                               F_display_temp   = false;      
  1462.                               F_display_moon   = false;
  1463.                               F_display_sun    = false;
  1464.                               F_refresh_all    = true;              // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
  1465.                               tft.fillRect(1,60,319,180,TFT_BLACK);                              
  1466.                           }                          
  1467.                          
  1468.                           if (F_display_clock)
  1469.                           {
  1470.                               #if ENGLISH                          
  1471.                                   String bufor = "Sunset " + String(ptrAstronomy->sunset);
  1472.                               #endif
  1473.                               #if POLISH
  1474.                                   String bufor = "Zachod slonca " + String(ptrAstronomy->sunset);
  1475.                               #endif
  1476.                              
  1477.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1478.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1479.                               tft.setTextSize(2);                                       // ustaw rozmiar fontów
  1480.                               tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów                  
  1481.                               tft.drawCentreString(bufor, 160,217,1);                   // wyświetl godzinę zachodu słońca          
  1482.                           }                          
  1483.                           break;
  1484.                       }                
  1485.                      
  1486.  
  1487.         case  35   :  {
  1488.                           if (F_display_clock)
  1489.                           {
  1490.                               #if ENGLISH                          
  1491.                                   String bufor = "Moonrise " + String(ptrAstronomy->moonrise);
  1492.                               #endif
  1493.                               #if POLISH
  1494.                                   String bufor = "Wschod ksiezyca " + String(ptrAstronomy->moonrise);
  1495.                               #endif
  1496.                              
  1497.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1498.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1499.                               tft.setTextSize(2);                                       // ustaw rozmiar fontów
  1500.                               tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów                  
  1501.                               tft.drawCentreString(bufor, 160,217,1);                   // wyświetl godzinę wschodu księżyca
  1502.                           }                          
  1503.                           break;
  1504.                       }            
  1505.  
  1506.         case  36   :  {
  1507.                           if (F_display_clock)
  1508.                           {
  1509.                               #if ENGLISH                          
  1510.                                   String bufor = "Moonset " + String(ptrAstronomy->moonset);
  1511.                               #endif
  1512.                               #if POLISH
  1513.                                   String bufor = "Zachod ksiezyca " + String(ptrAstronomy->moonset);
  1514.                               #endif
  1515.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1516.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1517.                               tft.setTextSize(2);                                       // ustaw rozmiar fontów
  1518.                               tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów                  
  1519.                               tft.drawCentreString(bufor, 160,217,1);                   // wyświetl godzinę zachodu księżyca
  1520.                           }                          
  1521.                           break;
  1522.                       }  
  1523.  
  1524.                                                    
  1525.        
  1526.         case  37   :  {
  1527.                      
  1528.                           if(F_display_clock)
  1529.                           {
  1530.                               F_display_clock  = false;      
  1531.                               F_display_temp   = true;      
  1532.                               F_display_moon   = false;
  1533.                               F_display_sun    = false;
  1534.                               F_refresh_all    = true;              // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
  1535.                               tft.fillRect(1,60,319,180,TFT_BLACK);                              
  1536.                           }
  1537.                           break;              
  1538.                    
  1539.                       }
  1540.        
  1541.         case  38   :  {
  1542.  
  1543.                           if(!F_display_clock)
  1544.                           {
  1545.                               F_display_clock  = true;      
  1546.                               F_display_temp   = false;      
  1547.                               F_display_moon   = false;
  1548.                               F_display_sun    = false;
  1549.                               F_refresh_all    = true;              // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
  1550.                               tft.fillRect(1,60,319,180,TFT_BLACK);                              
  1551.                           }                          
  1552.                          
  1553.                           if (F_display_clock)
  1554.                           {
  1555.                               #if ENGLISH                          
  1556.                                   String bufor = "Sunset " + String(ptrAstronomy->sunset);
  1557.                               #endif
  1558.                               #if POLISH
  1559.                                   String bufor = "Zachod slonca " + String(ptrAstronomy->sunset);
  1560.                               #endif
  1561.                              
  1562.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1563.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1564.                               tft.setTextSize(2);                                       // ustaw rozmiar fontów
  1565.                               tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów                  
  1566.                               tft.drawCentreString(bufor, 160,217,1);                   // wyświetl godzinę zachodu słońca          
  1567.                           }                          
  1568.                           break;
  1569.                       }            
  1570.        
  1571.         case  43   :  {
  1572.                      
  1573.                           if(F_display_clock)
  1574.                           {
  1575.                               F_display_clock  = false;      
  1576.                               F_display_temp   = true;      
  1577.                               F_display_moon   = false;
  1578.                               F_display_sun    = false;
  1579.                               F_refresh_all    = true;              // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
  1580.                               tft.fillRect(1,60,319,180,TFT_BLACK);                              
  1581.                           }
  1582.                           break;              
  1583.                    
  1584.                       }
  1585.        
  1586.         case  44   :  {
  1587.  
  1588.                           if(!F_display_clock)
  1589.                           {
  1590.                               F_display_clock  = true;      
  1591.                               F_display_temp   = false;      
  1592.                               F_display_moon   = false;
  1593.                               F_display_sun    = false;
  1594.                               F_refresh_all    = true;              // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
  1595.                               tft.fillRect(1,60,319,180,TFT_BLACK);                              
  1596.                           }                          
  1597.                          
  1598.                           if (F_display_clock)
  1599.                           {
  1600.                               #if ENGLISH                          
  1601.                                   String bufor = "Sunset " + String(ptrAstronomy->sunset);
  1602.                               #endif
  1603.                               #if POLISH
  1604.                                   String bufor = "Zachod slonca " + String(ptrAstronomy->sunset);
  1605.                               #endif
  1606.                              
  1607.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1608.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1609.                               tft.setTextSize(2);                                       // ustaw rozmiar fontów
  1610.                               tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów                  
  1611.                               tft.drawCentreString(bufor, 160,217,1);                   // wyświetl godzinę zachodu słońca          
  1612.                           }                          
  1613.                           break;
  1614.                       }      
  1615.        
  1616.         case   45  :  {
  1617.            
  1618.                           if (F_display_clock)
  1619.                           {                              
  1620.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1621.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1622.                               tft.setTextSize(2);                                           // ustaw rozmiar fontów
  1623.                               tft.setTextColor(TFT_LIGHTGREY);                              // ustaw kolor fontów                  
  1624.                               tft.drawCentreString("Free Memory : " + String(ESP.getFreeHeap()), 160,217,1);    
  1625.                           }                          
  1626.                           break;
  1627.                       }
  1628.                      
  1629.                                      
  1630.         case  54   :  {
  1631.                      
  1632.                           if(F_display_clock)
  1633.                           {
  1634.                               F_display_clock  = false;      
  1635.                               F_display_temp   = true;      
  1636.                               F_display_moon   = false;
  1637.                               F_display_sun    = false;
  1638.                               F_refresh_all    = true;              // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
  1639.                               tft.fillRect(1,60,319,180,TFT_BLACK);                              
  1640.                           }
  1641.                           break;              
  1642.                    
  1643.                       }
  1644.  
  1645.         case  55   :  {
  1646.                      
  1647.                           if(!F_display_clock)
  1648.                           {
  1649.                               F_display_clock  = true;      
  1650.                               F_display_temp   = false;      
  1651.                               F_display_moon   = false;
  1652.                               F_display_sun    = false;
  1653.                               F_refresh_all    = true;              // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
  1654.                               tft.fillRect(1,60,319,180,TFT_BLACK);                              
  1655.                           }
  1656.                           break;              
  1657.                    
  1658.                       }              
  1659.        
  1660.         case  58   :  {
  1661.                           if (F_display_clock)
  1662.                           {                              
  1663.                               tft.fillRect(1,210,319,30,TFT_BLACK);
  1664.                               tft.drawRect(1,210,319,30,TFT_WHITE);
  1665.                               tft.setTextSize(2);                                       // ustaw rozmiar fontów
  1666.                               tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów                  
  1667.                               tft.drawCentreString(super_msg, 160,217,1);               // wyświetl super msg
  1668.                           }                          
  1669.                           break;
  1670.                       }                                              
  1671.                                    
  1672.         default   :   {
  1673.                           if(!F_display_clock)
  1674.                           {
  1675.                               F_display_clock  = true;      
  1676.                               F_display_temp   = false;      
  1677.                               F_display_moon   = false;
  1678.                               F_display_sun    = false;
  1679.                               F_refresh_all    = true;              // niezbedna flaga dla zegara (odswież po powrotcie w tryb tft_clock)
  1680.                               tft.fillRect(1,60,319,180,TFT_BLACK);                              
  1681.                           }
  1682.                           break;
  1683.                       }
  1684.        
  1685.     }  
  1686.  
  1687.    
  1688.     if (F_display_temp && F_ptrWeather)       TFT_WeatherDisplay();  
  1689.    
  1690. }
  1691.  
  1692. // ------------------------------------------------------------------------------------------------------------------- //
  1693. // --- T A S K   C A L L B A C K ------------------------------------------------------------------------------------- //
  1694. // ------------------------------------------------------------------------------------------------------------------- //
  1695.  
  1696. void Task2Callback()    // run with interval 1 seconds
  1697. {
  1698.     static byte staticHour = 0;
  1699.     static byte staticMinutes = 0;
  1700.    
  1701.     byte x_pos_hour = 10;
  1702.     byte y_pos_hour = 100;
  1703.  
  1704.     byte x_pos_min = 180;
  1705.     byte y_pos_min = 100;
  1706.        
  1707.     myRTC.updateTime();
  1708.  
  1709.     // -------------------------------------------- DISPLAY CLOCK ---------------------------------------- //
  1710.     if (F_display_clock)                                              // jesli flaga jest true
  1711.     {
  1712.         tft.setTextColor(clock_color);                                // ustaw kolor znaków na ciemno szary
  1713.         tft.setTextSize(1);                                           // ustaw wielkosc znakow na 2
  1714.  
  1715.         if (F_refresh_all)
  1716.         {
  1717.             staticHour = -1;
  1718.             staticMinutes = -1;
  1719.             F_refresh_all = false;
  1720.         }
  1721.  
  1722.         if ((staticHour != myRTC.hours) )                                // jesli zmienila sie godzina wyswietl nowa
  1723.         {            
  1724.             // ---------------------------------------------------------------------- //
  1725.             // check clock color mode --- use only for TFT FONT --------------------- //
  1726.             // ---------------------------------------------------------------------- //
  1727.  
  1728.             if ( myRTC.hours > 6 && myRTC.hours < 20 )  clock_color = clock_color_day;
  1729.             else                                        clock_color = clock_color_night;
  1730.  
  1731.             // ---------------------------------------------------------------------- //
  1732.            
  1733.             staticHour = myRTC.hours;                                 // zapisz nowa godzine                        
  1734.            
  1735.             drawJpeg(digit112[myRTC.hours/10], 10, 80);               // wyświetla dziesiątki godziny
  1736.             drawJpeg(digit112[myRTC.hours%10], 74, 80);               // wyświetla jedności godziny
  1737.            
  1738.         }
  1739.      
  1740.         if (staticMinutes != myRTC.minutes)                           // jesli zmienila sie minuta wyswietl nowa
  1741.         {            
  1742.             staticMinutes = myRTC.minutes;                            // zapisz nowa minute
  1743.  
  1744.             drawJpeg(digit112[myRTC.minutes/10], 180, 80);
  1745.             drawJpeg(digit112[myRTC.minutes%10], 244, 80);      
  1746.  
  1747.             tft.fillRect(1,210,319,30,TFT_BLACK);
  1748.             tft.drawRect(1,210,319,30,TFT_WHITE);
  1749.             tft.setTextSize(2);                                       // ustaw rozmiar fontów
  1750.             tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów
  1751.  
  1752.             String bufor;
  1753.            
  1754.             #if POLISH
  1755.                 bufor = MyClock.sPL_DayOfWeek + " " + String(myRTC.dayofmonth) + "-" + String(myRTC.month) + "-" + String(myRTC.year);
  1756.             #endif
  1757.             #if ENGLISH
  1758.                 bufor = MyClock.sEN_DayOfWeek + " " + String(myRTC.dayofmonth) + "-" + String(myRTC.month) + "-" + String(myRTC.year);
  1759.             #endif
  1760.            
  1761.             tft.drawCentreString(bufor, 160,217,1);                   // wyświetl sformatowaną datę pod zegarem na TFT        
  1762.                    
  1763.         }
  1764.  
  1765.         // --------------------------- display : (second) ------------------------------------------------- //
  1766.        
  1767.         if(myRTC.seconds%2)                                     // jesli sekunda modulo daje 0
  1768.         {
  1769.             tft.fillCircle(160, 115, 7, TFT_WHITE);
  1770.             tft.fillCircle(160, 150, 7, TFT_WHITE);
  1771.         }
  1772.         else                                                          // jesli sekunda modula daje 1
  1773.         {                                                            
  1774.             tft.fillCircle(160, 115, 7, TFT_BLACK);
  1775.             tft.fillCircle(160, 150, 7, TFT_BLACK);    
  1776.         }
  1777.     }    
  1778.  
  1779. }
  1780.  
  1781. // ------------------------------------------------------------------------------------------------------------------- //
  1782. // --- T A S K   C A L L B A C K ------------------------------------------------------------------------------------- //
  1783. // ------------------------------------------------------------------------------------------------------------------- //
  1784.  
  1785. void Task3Callback()    // run with interval 90 seconds
  1786. {
  1787.     #if SERIAL
  1788.         #if ENGLISH
  1789.             PRINT(F("\n\n[ESP] [TASK3] Inside -> Task3Callback() "));
  1790.         #endif
  1791.         #if POLISH
  1792.             PRINT(F("\n\n[ESP] [TASK3] Wykonuje ->  Task3Callback() "));
  1793.         #endif
  1794.     #endif
  1795.  
  1796.     if (WiFi.status() == WL_CONNECTED)                      // jeśli połączenie WiFi jest aktywne
  1797.     {
  1798.         if ( !F_WeatherUpdate )   WeatherUpdate();          // i pogoda nie została jeszcze zaktualizowana
  1799.         if ( !F_AstronomyUpdate ) AstronomyUpdate();        // i pogoda nie została jeszcze zaktualizowana
  1800.     }
  1801. }
  1802.  
  1803. // ------------------------------------------------------------------------------------------------------------------- //
  1804. // --- T A S K   C A L L B A C K ------------------------------------------------------------------------------------- //
  1805. // ------------------------------------------------------------------------------------------------------------------- //
  1806.  
  1807. void Task4Callback()    // run with interval 15 minut
  1808. {
  1809.     #if SERIAL
  1810.         #if ENGLISH
  1811.             PRINT(F("\n\n[ESP] [TASK3] Inside -> Task4Callback() "));
  1812.         #endif
  1813.         #if POLISH
  1814.             PRINT(F("\n\n[ESP] [TASK3] Wykonuje ->  Task4Callback() "));
  1815.         #endif
  1816.     #endif
  1817.  
  1818.     if (WiFi.status() == WL_CONNECTED)                      // jeśli połączenie WiFi jest aktywne
  1819.     {
  1820.         WeatherUpdate();                                    // i pogoda nie została jeszcze zaktualizowana    
  1821.     }
  1822.    
  1823. }
  1824.  
  1825. // ------------------------------------------------------------------------------------------------------------------- //
  1826. // --- T A S K   C A L L B A C K ------------------------------------------------------------------------------------- //
  1827. // ------------------------------------------------------------------------------------------------------------------- //
  1828.  
  1829. void Task5Callback()    // run with interval 120 minut
  1830. {
  1831.     #if SERIAL
  1832.         #if ENGLISH
  1833.             PRINT(F("\n\n[ESP] [TASK3] Inside -> Task5Callback() "));
  1834.         #endif
  1835.         #if POLISH
  1836.             PRINT(F("\n\n[ESP] [TASK3] Wykonuje ->  Task5Callback() "));
  1837.         #endif
  1838.     #endif
  1839.  
  1840.     if (WiFi.status() == WL_CONNECTED)                      // jeśli połączenie WiFi jest aktywne
  1841.     {    
  1842.         AstronomyUpdate();                                  // i pogoda nie została jeszcze zaktualizowana
  1843.     }
  1844.    
  1845. }
  1846.  
  1847. // ------------------------------------------------------------------------------------------------------------------- //
  1848. // --- T A S K   C A L L B A C K ------------------------------------------------------------------------------------- //
  1849. // ------------------------------------------------------------------------------------------------------------------- //
  1850.  
  1851. void Task6Callback()    // run with interval 140 minut
  1852. {
  1853.     #if SERIAL
  1854.         #if ENGLISH
  1855.             PRINT(F("\n\n[ESP] [TASK3] Inside -> Task6Callback() "));
  1856.         #endif
  1857.         #if POLISH
  1858.             PRINT(F("\n\n[ESP] [TASK3] Wykonuje ->  Task6Callback() "));
  1859.         #endif
  1860.     #endif
  1861.  
  1862.     if (WiFi.status() == WL_CONNECTED)                // jeśli połączenie WiFi jest aktywne
  1863.     {    
  1864.         AirUpdate();                                  // i astronomia nie została jeszcze zaktualizowana
  1865.     }
  1866.    
  1867. }
  1868.  
  1869.  
  1870. // ------------------------------------------------------------------------------------------------------------------- //
  1871. // --- S E T U P --- T F T --- I N I T ------------------------------------------------------------------------------- //
  1872. // ------------------------------------------------------------------------------------------------------------------- //
  1873.  
  1874. void TFTInit()
  1875. {
  1876.     tft.begin();
  1877.     tft.setRotation(1);  
  1878.     tft.fillScreen(TFT_BLACK);
  1879.     tft.setSwapBytes(true);
  1880.  
  1881.     drawJpeg("/wiki.jpg", 0, 0);    
  1882.     delay(5000);
  1883.     tft.fillScreen(TFT_BLACK);    
  1884. }
  1885.  
  1886. // ------------------------------------------------------------------------------------------------------------------- //
  1887. // --- E X P A N D E R   I N I T ------------------------------------------------------------------------------------- //
  1888. // ------------------------------------------------------------------------------------------------------------------- //
  1889.  
  1890. void ExpanderInit()
  1891. {
  1892.     rWire.begin(5, 4);
  1893.     rWire.setClock(100000L);
  1894.     expander.begin();
  1895.     RelayOff(0);                               //  all Relay OFF (send 0)
  1896. }
  1897.  
  1898. // ------------------------------------------------------------------------------------------------------------------- //
  1899. // --- M A I N   S E T U P ------------------------------------------------------------------------------------------- //
  1900. // ------------------------------------------------------------------------------------------------------------------- //
  1901.  
  1902. void setup()
  1903. {
  1904.     SerialInit();                                         // check and init serial monitor
  1905.                                       // Init TFT Display
  1906.  
  1907.     if (!SPIFFS.begin())
  1908.     {
  1909.         #if SERIAL
  1910.             #if ENGLISH
  1911.                 PRINT(F("\n[ESP] [SETUP] SPIFFS initialisation failed!"));
  1912.             #endif
  1913.             #if POLISH
  1914.                 PRINT(F("\n[ESP] [SETUP] błąd inicjalizacji SPIFFS !"));
  1915.             #endif
  1916.         #endif
  1917.        
  1918.         while (1) yield();
  1919.     }
  1920.     else
  1921.     {
  1922.         #if SERIAL
  1923.             #if ENGLISH
  1924.                 PRINT(F("\n[ESP] [SETUP] SPIFFS initialisation done."));
  1925.             #endif
  1926.             #if POLISH
  1927.                 PRINT(F("\n[ESP] [SETUP] SPIFFS zainicjowano pomyślnie."));
  1928.             #endif
  1929.         #endif
  1930.     }
  1931.    
  1932.     listFiles(); // Lists the files so you can see what is in the SPIFFS
  1933.     TFTInit();          
  1934.    
  1935.     WiFiInit();                                           // start WiFi Connection
  1936.     WiFiStat();                                           // show WiFi Status
  1937.     WiFiReconect();                                       // check WiFi Connection and conect if loss !!!
  1938.  
  1939.     timeClient.begin();                                   // start timeClient
  1940.  
  1941.     DrawLine(60,'*');                                     // Draw 60x separator *
  1942.    
  1943.     if ( WiFi.status() == WL_CONNECTED )                  // if WiFi is OK
  1944.     {
  1945.         while(!NTPInit());                                // init NTP server                        
  1946.         myRTC_Update();                                   // update RTC module
  1947.         MyClock_Update();                                   // copy Time & Data to structure MyClock        
  1948.         Show_NTP();                                       // show NTP time & data
  1949.     }
  1950.  
  1951.     ExpanderInit();                                       // ExpanderInit
  1952.        
  1953.     TaskInit();                                           // Init Task Scheluder
  1954.  
  1955.    
  1956.     for(byte i = 1; i <= 8; i ++) Bulb(i, 0);      // wyłącz wszystkie żarówki
  1957.    
  1958.     timer.setInterval(3000L, checkBlynkStatus); // check if Blynk server is connected every 3 seconds  
  1959.     Blynk.config(AUTH);    
  1960.  
  1961.      
  1962. }
  1963.  
  1964.  
  1965. // ------------------------------------------------------------------------------------------------------------------- //
  1966. // --- M A I N   L O O P --------------------------------------------------------------------------------------------- //
  1967. // ------------------------------------------------------------------------------------------------------------------- //
  1968.  
  1969. void loop()
  1970. {
  1971.     runner.execute();                                     // scheluder  
  1972.     Blynk.run();                                          // Blynk
  1973. }
  1974.  
  1975. // ------------------------------------------------------------------------------------------------------------------- //
  1976. //
  1977. //
  1978. //    ***   T F T   f u n c t i o n s ***
  1979. //
  1980. //
  1981. // ------------------------------------------------------------------------------------------------------------------- //
  1982. // --- T F T   B U L B   O N / O F F --------------------------------------------------------------------------------- //
  1983. // ------------------------------------------------------------------------------------------------------------------- //
  1984.  
  1985. void Bulb(byte nr, byte state)
  1986. {
  1987.     switch(nr)
  1988.     {
  1989.         case 1 :  {
  1990.                       if (!state)  tft.pushImage(5, 10, bulb_off_Width, bulb_off_Height, bulb_off);
  1991.                       else         tft.pushImage(5, 10, bulb_off_Width, bulb_off_Height, bulb_on);
  1992.                       break;
  1993.                   }
  1994.         case 2 :  {
  1995.                       if (!state)  tft.pushImage(45, 10, bulb_off_Width, bulb_off_Height, bulb_off);
  1996.                       else         tft.pushImage(45, 10, bulb_off_Width, bulb_off_Height, bulb_on);
  1997.                       break;
  1998.                   }
  1999.         case 3 :  {
  2000.                       if (!state)  tft.pushImage(85, 10, bulb_off_Width, bulb_off_Height, bulb_off);
  2001.                       else         tft.pushImage(85, 10, bulb_off_Width, bulb_off_Height, bulb_on);
  2002.                       break;
  2003.                   }
  2004.         case 4 :  {
  2005.                       if (!state)  tft.pushImage(125, 10, bulb_off_Width, bulb_off_Height, bulb_off);
  2006.                       else         tft.pushImage(125, 10, bulb_off_Width, bulb_off_Height, bulb_on);
  2007.                       break;
  2008.                   }
  2009.         case 5 :  {
  2010.                       if (!state)  tft.pushImage(165, 10, bulb_off_Width, bulb_off_Height, bulb_off);
  2011.                       else         tft.pushImage(165, 10, bulb_off_Width, bulb_off_Height, bulb_on);
  2012.                       break;
  2013.                   }
  2014.         case 6 :  {
  2015.                       if (!state)  tft.pushImage(205, 10, bulb_off_Width, bulb_off_Height, bulb_off);
  2016.                       else         tft.pushImage(205, 10, bulb_off_Width, bulb_off_Height, bulb_on);                      
  2017.                       break;
  2018.                   }
  2019.         case 7 :  {
  2020.                       if (!state)  tft.pushImage(245, 10, bulb_off_Width, bulb_off_Height, bulb_off);
  2021.                       else         tft.pushImage(245, 10, bulb_off_Width, bulb_off_Height, bulb_on);
  2022.                       break;
  2023.                   }
  2024.         case 8 :  {
  2025.                       if (!state)  tft.pushImage(285, 10, bulb_off_Width, bulb_off_Height, bulb_off);
  2026.                       else         tft.pushImage(285, 10, bulb_off_Width, bulb_off_Height, bulb_on);
  2027.                       break;
  2028.                   }
  2029.     }
  2030.  
  2031.     if ( F_display_clock )
  2032.     {
  2033.             tft.fillRect(1,210,319,30,TFT_BLACK);                     // wyczyść pole msg
  2034.             tft.drawRect(1,210,319,30,TFT_WHITE);                     // narysuj pole msg
  2035.             tft.setTextSize(2);                                       // ustaw rozmiar fontów
  2036.             tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów
  2037.             String bufor = "Relay no. " + String (nr) + " turn ";  // przygotuj bufor do wyswietlenia
  2038.            
  2039.             if (state) bufor += "ON";                                 // jesli przekaznik wlaczony
  2040.             else       bufor += "OFF";                                // jesli przekaznik wylaczony
  2041.            
  2042.             tft.drawCentreString(bufor, 160,217,1);                   // wyświetl sformatowaną datę pod zegarem na TFT            
  2043.     }
  2044. }
  2045.  
  2046. // ------------------------------------------------------------------------------------------------------------------- //
  2047. //
  2048. //
  2049. //    ***   R E L A Y S   ***
  2050. //
  2051. //
  2052. // ------------------------------------------------------------------------------------------------------------------- //
  2053. // --- Relay to OFF -------------------------------------------------------------------------------------------------- //
  2054. // ------------------------------------------------------------------------------------------------------------------- //
  2055.  
  2056. void RelayOff(byte nr)
  2057. {
  2058.     if (!nr)     // if nr = 0 all relay set to OFF (RelayMin, RelayMax)
  2059.     {
  2060.         for (byte i = RelayMin; i <= RelayMax; i++) expander.write(RELAY[i], HIGH);      
  2061.  
  2062.         #if SERIAL
  2063.             DrawLine(60,'-');                                                      // draw line
  2064.             #if POLISH
  2065.                 PRINT(F("\n[ESP] [RELAY] Wyłączono wszystkie przekaźniki"));
  2066.             #endif                
  2067.             #if ENGLISH
  2068.                 PRINT(F("\n[ESP] [RELAY] Turn off all relay"));
  2069.             #endif
  2070.         #endif
  2071.     }
  2072.     else
  2073.     {
  2074.         if ( nr >= RelayMin && nr <= RelayMax )                                   // only value (1-8)
  2075.         {
  2076.             if ( !expander.read(RELAY[nr]) )                                      // if Relay is ON
  2077.             {
  2078.                 expander.write(RELAY[nr], HIGH);                                  // turn off Relay
  2079.                 Bulb(nr, 0);
  2080.                
  2081.                 #if SERIAL
  2082.                     DrawLine(60,'-');                                             // draw line
  2083.                     #if POLISH
  2084.                         PRINT(F("\n[ESP] [RELAY] Wyłączono przekaźnik nr. %d"), nr);
  2085.                     #endif                        
  2086.                     #if ENGLISH
  2087.                         PRINT(F("\n[ESP] [RELAY] Turn off relay no. %d"), nr);
  2088.                     #endif
  2089.                 #endif
  2090.             }
  2091.             else                                                                  // relay is off, re-off
  2092.             {
  2093.                 #if SERIAL
  2094.                     DrawLine(60,'-');
  2095.                     #if POLISH
  2096.                         PRINT(F("\n[ESP] [RELAY] Wykryto próbę ponownego wyłączenia przekaźnika nr. %d"), nr);
  2097.                     #endif
  2098.                     #if ENGLISH
  2099.                         PRINT(F("\n[ESP] [RELAY] An attempt to re-engage the relay has been detected no. %d"), nr);
  2100.                     #endif
  2101.                 #endif
  2102.             }
  2103.         }
  2104.         else                    // ERROR !!! Relay does not exist (jeśli taki przekaźnik nie istnieje)
  2105.         {
  2106.             #if SERIAL
  2107.                 DrawLine(60,'-');                                                
  2108.                 #if POLISH
  2109.                     PRINT(F("\n[ESP] [RELAY] Nie ma takiego przekaźnika, nr. %d"), nr);
  2110.                 #endif                
  2111.                 #if ENGLISH
  2112.                     PRINT(F("\n[ESP] [RELAY] There is no such relay, no. %d"), nr);
  2113.                 #endif
  2114.             #endif
  2115.         }
  2116.     }
  2117. }
  2118.  
  2119. // ------------------------------------------------------------------------------------------------------------------- //
  2120. // --- Relay to OFF -------------------------------------------------------------------------------------------------- //
  2121. // ------------------------------------------------------------------------------------------------------------------- //
  2122.  
  2123. void RelayOn(byte nr)
  2124. {
  2125.     if (!nr)     // if nr = 0 all relay set to ON (RelayMin, RelayMax)
  2126.     {
  2127.         for (byte i = RelayMin; i <= RelayMax; i++) expander.write(RELAY[i], LOW);    
  2128.  
  2129.         #if SERIAL
  2130.             DrawLine(60,'-');                                                      // draw line
  2131.             #if POLISH
  2132.                 PRINT(F("\n[ESP] [RELAY] Włączono wszystkie przekaźniki"));
  2133.             #endif                
  2134.             #if ENGLISH
  2135.                 PRINT(F("\n[ESP] [RELAY] Turn on all relay"));
  2136.             #endif
  2137.          #endif
  2138.     }
  2139.     else
  2140.     {
  2141.         if ( nr >= RelayMin && nr <= RelayMax )                                   // only value (1-8)
  2142.         {
  2143.             if ( expander.read(RELAY[nr]) )                                       // if Relay is OFF
  2144.             {
  2145.                 expander.write(RELAY[nr], LOW);                                   // turn on Relay
  2146.                 Bulb(nr, 1);
  2147.                
  2148.                 #if SERIAL
  2149.                     DrawLine(60,'-');                                             // draw line
  2150.                     #if POLISH
  2151.                         PRINT(F("\n[ESP] [RELAY] Włączono przekaźnik nr. %d"), nr);
  2152.                     #endif                        
  2153.                     #if ENGLISH
  2154.                         PRINT(F("\n[ESP] [RELAY] Turn on relay no. %d"), nr);
  2155.                     #endif
  2156.                 #endif
  2157.             }
  2158.             else                                                                  // relay is on, re-on
  2159.             {
  2160.                 #if SERIAL
  2161.                     DrawLine(60,'-');
  2162.                     #if POLISH
  2163.                         PRINT(F("\n[ESP] [RELAY] Wykryto próbę ponownego włączenia przekaźnika nr. %d"), nr);
  2164.                     #endif
  2165.                     #if ENGLISH
  2166.                         PRINT(F("\n[ESP] [RELAY] An attempt to re-engage the relay has been detected no. %d"), nr);
  2167.                     #endif
  2168.                 #endif
  2169.             }
  2170.         }
  2171.         else
  2172.         {
  2173.             #if SERIAL
  2174.                 DrawLine(60,'-');                                                      // draw line
  2175.                 #if POLISH
  2176.                     PRINT(F("\n[ESP] [RELAY] Nie ma takiego przekaźnika, nr. %d"), nr);
  2177.                 #endif                
  2178.                 #if ENGLISH
  2179.                     PRINT(F("\n[ESP] [RELAY] There is no such relay, no. %d"), nr);
  2180.                 #endif  
  2181.             #endif
  2182.         }
  2183.     }
  2184. }
  2185.  
  2186. // ------------------------------------------------------------------------------------------------------------------- //
  2187. //
  2188. //
  2189. // B L Y N K   S E C T I O N
  2190. //
  2191. //
  2192. // ------------------------------------------------------------------------------------------------------------------- //
  2193. // BLYNK_CONNECTED
  2194. // ------------------------------------------------------------------------------------------------------------------- //
  2195.  
  2196. BLYNK_CONNECTED()
  2197. {  
  2198.     Blynk.syncVirtual(VPIN_BUTTON_1);  
  2199.     Blynk.syncVirtual(VPIN_BUTTON_2);  
  2200.     Blynk.syncVirtual(VPIN_BUTTON_3);  
  2201.     Blynk.syncVirtual(VPIN_BUTTON_4);  
  2202.     Blynk.syncVirtual(VPIN_BUTTON_5);  
  2203.     Blynk.syncVirtual(VPIN_BUTTON_6);  
  2204.     Blynk.syncVirtual(VPIN_BUTTON_7);  
  2205.     Blynk.syncVirtual(VPIN_BUTTON_8);
  2206. }  
  2207.  
  2208. // ------------------------------------------------------------------------------------------------------------------- //
  2209. // BLYNK BUTTON 1
  2210. // ------------------------------------------------------------------------------------------------------------------- //
  2211.  
  2212. BLYNK_WRITE(VPIN_BUTTON_1)
  2213. {    
  2214.   toggleState_1 = param.asInt();  
  2215.  
  2216.   if(toggleState_1)
  2217.   {
  2218.       RelayOn(1);
  2219.   }
  2220.   else
  2221.   {
  2222.       RelayOff(1);
  2223.   }
  2224. }  
  2225.  
  2226. // ------------------------------------------------------------------------------------------------------------------- //
  2227. // BLYNK BUTTON 2
  2228. // ------------------------------------------------------------------------------------------------------------------- //
  2229.  
  2230. BLYNK_WRITE(VPIN_BUTTON_2)
  2231. {  
  2232.   toggleState_2 = param.asInt();
  2233.    
  2234.   if(toggleState_2)
  2235.   {
  2236.       RelayOn(2);
  2237.   }
  2238.   else
  2239.   {
  2240.       RelayOff(2);
  2241.   }
  2242. }
  2243.  
  2244. // ------------------------------------------------------------------------------------------------------------------- //
  2245. // BLYNK BUTTON 3
  2246. // ------------------------------------------------------------------------------------------------------------------- //
  2247.  
  2248. BLYNK_WRITE(VPIN_BUTTON_3)
  2249. {  
  2250.   toggleState_3 = param.asInt();
  2251.    
  2252.   if(toggleState_3)
  2253.   {
  2254.       RelayOn(3);
  2255.   }
  2256.   else
  2257.   {
  2258.       RelayOff(3);
  2259.   }
  2260. }  
  2261.  
  2262. // ------------------------------------------------------------------------------------------------------------------- //
  2263. // BLYNK BUTTON 4
  2264. // ------------------------------------------------------------------------------------------------------------------- //
  2265.  
  2266. BLYNK_WRITE(VPIN_BUTTON_4)
  2267. {  
  2268.   toggleState_4 = param.asInt();
  2269.    
  2270.   if(toggleState_4)
  2271.   {
  2272.       RelayOn(4);
  2273.   }
  2274.   else
  2275.   {
  2276.       RelayOff(4);
  2277.   }
  2278. }  
  2279.  
  2280. // ------------------------------------------------------------------------------------------------------------------- //
  2281. // BLYNK BUTTON 5
  2282. // ------------------------------------------------------------------------------------------------------------------- //
  2283.  
  2284. BLYNK_WRITE(VPIN_BUTTON_5)
  2285. {  
  2286.   toggleState_5 = param.asInt();
  2287.  
  2288.   if(toggleState_5)
  2289.   {
  2290.       RelayOn(5);
  2291.   }
  2292.   else
  2293.   {
  2294.       RelayOff(5);
  2295.   }
  2296. }  
  2297.  
  2298. // ------------------------------------------------------------------------------------------------------------------- //
  2299. // BLYNK BUTTON 6
  2300. // ------------------------------------------------------------------------------------------------------------------- //
  2301.  
  2302. BLYNK_WRITE(VPIN_BUTTON_6)
  2303. {  
  2304.   toggleState_6 = param.asInt();
  2305.  
  2306.   if(toggleState_6)
  2307.   {
  2308.       RelayOn(6);
  2309.   }
  2310.   else
  2311.   {
  2312.       RelayOff(6);
  2313.   }
  2314. }  
  2315.  
  2316. // ------------------------------------------------------------------------------------------------------------------- //
  2317. // BLYNK BUTTON 7
  2318. // ------------------------------------------------------------------------------------------------------------------- //
  2319. BLYNK_WRITE(VPIN_BUTTON_7)
  2320. {  
  2321.   toggleState_7 = param.asInt();
  2322.  
  2323.   if(toggleState_7)
  2324.   {
  2325.       RelayOn(7);
  2326.   }
  2327.   else
  2328.   {
  2329.       RelayOff(7);
  2330.   }
  2331. }  
  2332.  
  2333. // ------------------------------------------------------------------------------------------------------------------- //
  2334. // BLYNK BUTTON 8
  2335. // ------------------------------------------------------------------------------------------------------------------- //
  2336.  
  2337. BLYNK_WRITE(VPIN_BUTTON_8)
  2338. {  
  2339.   toggleState_8 = param.asInt();
  2340.    
  2341.   if(toggleState_8)
  2342.   {
  2343.       RelayOn(8);
  2344.   }
  2345.   else
  2346.   {
  2347.       RelayOff(8);
  2348.   }
  2349. }  
  2350.  
  2351. void checkBlynkStatus()
  2352. {
  2353.    
  2354. }  
  2355.  
  2356.  
  2357. // ------------------------------------------------------------------------------------------------------------------- //
  2358. // ---   W E A T H E R   A L L O C A T E   M E M O R Y   ------------------------------------------------------------- //
  2359. // ------------------------------------------------------------------------------------------------------------------- //
  2360.  
  2361. void ptrWeatherMalloc()
  2362. {
  2363.     if (!F_ptrWeather)
  2364.     {
  2365.         #if SERIAL
  2366.             #if ENGLISH        
  2367.                 PRINT(F("\n[ESP] [Weather Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
  2368.                 PRINT(F("\n[ESP] [Weather Malloc] i try allocate memory in RAM for struct -> Weather"));
  2369.             #endif
  2370.             #if POLISH
  2371.                 PRINT(F("\n[ESP] [Weather Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
  2372.                 PRINT(F("\n[ESP] [Weather Malloc] próba alokacji pamięci RAM dla struktury -> Weather"));
  2373.             #endif
  2374.         #endif
  2375.      
  2376.         ptrWeather = ( struct Weather * ) malloc ( sizeof (struct Weather) );    
  2377.         F_ptrWeather = true;
  2378.  
  2379.         #if SERIAL
  2380.             #if ENGLISH          
  2381.                 PRINT(F("\n[ESP] [Weather Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
  2382.                 PRINT(F("\n[ESP] [Weather Malloc] allocate memory in RAM for struct Weather sucefull\n"));
  2383.             #endif
  2384.             #if POLISH
  2385.                 PRINT(F("\n[ESP] [Weather Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
  2386.                 PRINT(F("\n[ESP] [Weather Malloc] alokakacji pamięci RAM dla struktury - Weather UDANA\n"));
  2387.             #endif
  2388.         #endif
  2389.     }
  2390. }
  2391.  
  2392. // ------------------------------------------------------------------------------------------------------------------- //
  2393. // ---   W E A T H E R   C O N D I T I O N   T F T   D I S P L A Y --------------------------------------------------- //
  2394. // ------------------------------------------------------------------------------------------------------------------- //
  2395.  
  2396. void TFT_WeatherDisplay()
  2397. {
  2398.    
  2399.     // ------------------------------------------------------------------------------------ //
  2400.     // --- DRAW TEMPERATURE DIGIS --------------------------------------------------------- //
  2401.     // ------------------------------------------------------------------------------------ //
  2402.  
  2403.     TFT_WeatherIconShow();    
  2404.  
  2405.     drawJpeg(digit112[abs(int(ptrWeather -> temp_c)) / 10], 165,80);  // Xx digit
  2406.     drawJpeg(digit112[abs(int(ptrWeather -> temp_c)) % 10], 230,80);  // xX digit    
  2407.  
  2408.     tft.fillCircle(300,90, 7, TFT_WHITE);                             // st.C
  2409.     if (ptrWeather -> temp_c < 0) tft.fillRect(130,135,20,5,TFT_WHITE);// minus symbol  
  2410.  
  2411.     #if ENGLISH                          
  2412.         String bufor = String(ptrWeather -> condition_en);
  2413.     #endif
  2414.     #if POLISH
  2415.         String bufor = String(ptrWeather -> condition_pl);
  2416.     #endif
  2417.    
  2418.     tft.fillRect(1,210,319,30,TFT_BLACK);
  2419.     tft.drawRect(1,210,319,30,TFT_WHITE);
  2420.     tft.setTextSize(2);                                       // ustaw rozmiar fontów
  2421.     tft.setTextColor(TFT_LIGHTGREY);                          // ustaw kolor fontów                  
  2422.     tft.drawCentreString(bufor, 160,217,1);                   // wyświetl godzinę zachodu księżyca
  2423. }
  2424.  
  2425. // ------------------------------------------------------------------------------------------------------------------- //
  2426. // ---   W E A T H E R   D E L E T E   F R O M   M E M O R Y   ------------------------------------------------------- //
  2427. // ------------------------------------------------------------------------------------------------------------------- //
  2428.  
  2429. void ptrWeatherFree()
  2430. {
  2431.     if (F_ptrWeather)
  2432.     {
  2433.         free(ptrWeather);
  2434.         F_ptrWeather = false;        
  2435.  
  2436.         #if SERIAL
  2437.             #if ENGLISH
  2438.                 PRINT(F("\n[ESP] [Weather Malloc] delete [ptrWeather] from RAM memory ..."));          
  2439.             #endif        
  2440.             #if POLISH
  2441.                 PRINT(F("\n[ESP] [Weather Malloc] usunięto [ptrWeather] z pamięci RAM ..."));        
  2442.             #endif
  2443.         #endif
  2444.     }
  2445.     else
  2446.     {
  2447.         #if SERIAL
  2448.             #if ENGLISH
  2449.                 PRINT(F("\n[ESP] [Weather] cannot be deleted [ptrWeather] does not exist !!! "));          
  2450.             #endif        
  2451.             #if POLISH
  2452.                 PRINT(F("\n[ESP] [Weather] nie można usunąć [ptrWeather] nie isnieje w pamięci RAM ..."));        
  2453.             #endif
  2454.         #endif  
  2455.     }
  2456. }
  2457.  
  2458. // ------------------------------------------------------------------------------------------------------------ //
  2459. // --- WEATHER UPDATE --- CREATE BUFFOR in RAM --- COPY DATA to STRUCT WEATHER in RAM --- by TRANSLINE -------  //
  2460. // ------------------------------------------------------------------------------------------------------------ //
  2461. // --- DUAL LANGUAGE --- POLISH & ENGLISH --- SET IN MACRO in MAIN PROJECT --- TRANSLATE in GOOGLE --- :-) ---  //
  2462. // ------------------------------------------------------------------------------------------------------------ //
  2463.  
  2464. void WeatherUpdate()
  2465. {
  2466.     if (!F_ptrWeather) ptrWeatherMalloc();    // jesli pamięć nie utworzona stwórz ją w PSRAM
  2467.    
  2468.     #if SERIAL
  2469.         #if ENGLISH
  2470.             PRINT(F("\n[[ESP] Weather Update] Try Downloading JSON File from https://api.weatherapi.com/"));
  2471.         #endif
  2472.         #if POLISH
  2473.             PRINT(F("\n[ESP] [Weather Update] Próbuję pobrać plik JSON z https://api.weatherapi.com/"));
  2474.         #endif
  2475.     #endif
  2476.  
  2477.     #if ENGLISH
  2478.         String path = "http://api.weatherapi.com/v1/current.json?key=" + PogodaToken + "&q=" + PogodaMiasto + "&lang=en";
  2479.     #endif
  2480.     #if POLISH
  2481.         String path = "http://api.weatherapi.com/v1/current.json?key=" + PogodaToken + "&q=" + PogodaMiasto + "&lang=pl";
  2482.     #endif
  2483.        
  2484.     HTTPClient http;
  2485.     http.useHTTP10(true);
  2486.     http.begin(client, path);
  2487.     http.GET();
  2488.  
  2489.     DynamicJsonDocument doc(2000);
  2490.     DeserializationError error = deserializeJson(doc, http.getStream());
  2491.        
  2492.     if(error)
  2493.     {
  2494.         F_WeatherUpdate = false;      // aktualizacja nie powiodła się
  2495.         #if SERIAL
  2496.             #if ENGLISH
  2497.                 PRINT(F("\n[Weather Update] DeserializeJson() failed: "));
  2498.                 Serial.println(error.c_str());
  2499.             #endif
  2500.             #if POLISH
  2501.                 PRINT(F("\n[Weather Update] DeserializeJson() error: "));
  2502.                 Serial.println(error.c_str());
  2503.             #endif        
  2504.         #endif  
  2505.     }
  2506.     else
  2507.     {
  2508.         F_WeatherUpdate = true;
  2509.     }
  2510.  
  2511.     http.end();
  2512.    
  2513.     if(F_WeatherUpdate)
  2514.     {
  2515.         #if SERIAL
  2516.             #if ENGLISH
  2517.                 PRINT(F("\n[ESP] [Weather Update] JsonDocument Usage Memory : %s bytes"), String(doc.memoryUsage()));                  
  2518.                 PRINT(F("\n[ESP] [Weather Update] [FREE RAM]                : %d kB\n"), ESP.getFreeHeap());      
  2519.             #endif
  2520.             #if POLISH
  2521.                 PRINT(F("\n[ESP] [Weather Update] JsonDocument zaalokował pamięć : %s bajtów"), String(doc.memoryUsage()));  
  2522.                 PRINT(F("\n[ESP] [Weather Update] [FREE RAM]                     : %d kB\n"), ESP.getFreeHeap());      
  2523.             #endif
  2524.         #endif
  2525.  
  2526.         // --- update struct WEATHER in PSRAM !!! -------------------------------------------------- //
  2527.  
  2528.         strcpy(ptrWeather->city, doc["location"]["name"].as<String>().c_str());                       // nazwę miasta
  2529.         strcpy(ptrWeather->country, doc["location"]["country"].as<String>().c_str());                 // nazwę kraju
  2530.         ptrWeather->lat = doc["location"]["lat"].as<double>();                                        // szer.geograficzną
  2531.         ptrWeather->lon = doc["location"]["lon"].as<double>();                                        // dł.geograficzną
  2532.         strcpy(ptrWeather->tz_id, doc["location"]["tz_id"].as<String>().c_str());                     // kontynent/stolica
  2533.         ptrWeather->localtime_epoch = doc["location"]["localtime_epoch"];                             // czas EPOCH
  2534.         strcpy(ptrWeather->localtime, doc["location"]["localtime"].as<String>().c_str());             // czas lokalny
  2535.         strcpy(ptrWeather->last_updated, doc["current"]["last_updated"].as<String>().c_str());        // ost. aktualizacja
  2536.         ptrWeather->temp_c = doc["current"]["temp_c"].as<double>();                                   // temp Celcius
  2537.         ptrWeather->feelslike_c = doc["current"]["feelslike_c"].as<double>();                         // temp odczuwalna C
  2538.         ptrWeather->temp_f = doc["current"]["temp_f"].as<double>();                                   // temp Faranhaid
  2539.         ptrWeather->feelslike_f = doc["current"]["feelslike_f"].as<double>();                         // temp odczuwalna Faranhaid
  2540.         strcpy(ptrWeather->condition_en, doc["current"]["condition"]["text"].as<String>().c_str());   // opis pogody ENGLISH
  2541.         strcpy(ptrWeather->condition_pl, doc["current"]["condition"]["text"].as<String>().c_str());   // opis pogody POLISH *** do zrobienia ***
  2542.         strcpy(ptrWeather->icon, doc["current"]["condition"]["icon"].as<String>().c_str());           // adres ikony pogody
  2543.         ptrWeather->code = doc["current"]["condition"]["code"];                                       // kod pogody
  2544.         ptrWeather->wind_kph = doc["current"]["wind_kph"].as<double>();                               // prędkość wiatru w km/h
  2545.         ptrWeather->gust_kph = doc["current"]["gust_kph"].as<double>();                               // porywy wiatru w km/h
  2546.         ptrWeather->wind_mph = doc["current"]["wind_mph"].as<double>();                               // prędkość wiatru w milach/h
  2547.         ptrWeather->gust_mph = doc["current"]["gust_mph"].as<double>();                               // porywy wiatru w milach/h
  2548.         ptrWeather->wind_degree = doc["current"]["wind_degree"];                                      // kierunek wiatru (stopnie) int
  2549.         strcpy(ptrWeather->wind_dir, doc["current"]["wind_dir"].as<String>().c_str());                // kierunke wiatru (dir)
  2550.         ptrWeather->pressure_mb = doc["current"]["pressure_mb"];                                      // cisnienie atmosferyczne
  2551.         ptrWeather->pressure_in = doc["current"]["pressure_in"].as<double>();                         // huj wie co to !!!
  2552.         ptrWeather->precip_mm = doc["current"]["precip_mm"].as<double>();                             // opady w mm
  2553.         ptrWeather->precip_in = doc["current"]["precip_in"].as<double>();                             // huj wie co to !!!
  2554.         ptrWeather->humidity = doc["current"]["humidity"];                                            // wilgotność powietrza
  2555.         ptrWeather->cloud = doc["current"]["cloud"];                                                  // zachmurzenie %
  2556.         ptrWeather->vis_km = doc["current"]["vis_km"].as<double>();                                   // widzialnosc km
  2557.         ptrWeather->vis_miles = doc["current"]["vis_miles"].as<double>();                             // widzialnosc mile
  2558.         ptrWeather->uv = doc["current"]["uv"].as<double>();                                           // index UV
  2559.  
  2560.         // --- update struct WEATHER in PSRAM !!! -------------------------------------------------- //
  2561.  
  2562.         #if SERIAL
  2563.             if(F_WeatherUpdate) WeatherShow();      // pokaż jeśli SERIAl jest TRUE    
  2564.         #endif
  2565.     }
  2566. }
  2567.  
  2568. // ------------------------------------------------------------------------------------------------------------ //
  2569. // --- WEATHER SHOW FROM BUFFOR in RAM                                                                      --- //
  2570. // ------------------------------------------------------------------------------------------------------------ //
  2571. // --- DUAL LANGUAGE --- POLISH & ENGLISH --- SET IN MACRO in MAIN PROJECT --- TRANSLATE in GOOGLE --- :-) ---  //
  2572. // ------------------------------------------------------------------------------------------------------------ //
  2573.  
  2574. void WeatherShow()
  2575. {
  2576.     #if SERIAL
  2577.         #if ENGLISH
  2578.             PRINT(F("\n[API] [Weather] City             : %s"), ptrWeather->city);
  2579.             PRINT(F("\n[API] [Weather] Country          : %s"), ptrWeather->country);
  2580.             PRINT(F("\n[API] [Weather] TZ ID            : %s"), ptrWeather->tz_id);
  2581.             PRINT(F("\n[API] [Weather] Latitude         : %0.2f"), ptrWeather->lat);
  2582.             PRINT(F("\n[API] [Weather] Longitude        : %0.2f"), ptrWeather->lon);
  2583.             PRINT(F("\n[API] [Weather] Epoch Time       : %d"), ptrWeather->localtime_epoch);
  2584.             PRINT(F("\n[API] [Weather] Localtime        : %s"), ptrWeather->localtime);
  2585.             PRINT(F("\n[API] [Weather] Last Updade      : %s"), ptrWeather->last_updated);
  2586.             PRINT(F("\n[API] [Weather] Temp C           : %0.2f"), ptrWeather->temp_c);
  2587.             PRINT(F("\n[API] [Weather] Temp feel C      : %0.2f"), ptrWeather->feelslike_c);
  2588.             PRINT(F("\n[API] [Weather] Temp F           : %0.2f"), ptrWeather->temp_f);
  2589.             PRINT(F("\n[API] [Weather] Temp feel F      : %0.2f"), ptrWeather->feelslike_f);
  2590.             PRINT(F("\n[API] [Weather] Condition EN     : %s"), ptrWeather->condition_en);
  2591.             PRINT(F("\n[API] [Weather] Condition PL     : %s"), ptrWeather->condition_pl);
  2592.             PRINT(F("\n[API] [Weather] icon             : %s"), ptrWeather->icon);
  2593.             PRINT(F("\n[API] [Weather] icon code        : %d"), ptrWeather->code);
  2594.             PRINT(F("\n[API] [Weather] Wind speed kph   : %0.2f"), ptrWeather->wind_kph);
  2595.             PRINT(F("\n[API] [Weather] Wind gust kph    : %0.2f"), ptrWeather->gust_kph);
  2596.             PRINT(F("\n[API] [Weather] Wind speed mph   : %0.2f"), ptrWeather->wind_mph);
  2597.             PRINT(F("\n[API] [Weather] Wind gust mph    : %0.2f"), ptrWeather->gust_mph);
  2598.             PRINT(F("\n[API] [Weather] Wind degree      : %d"), ptrWeather->wind_degree);
  2599.             PRINT(F("\n[API] [Weather] Wind dir         : %s"), ptrWeather->wind_dir);
  2600.             PRINT(F("\n[API] [Weather] Pressure mb      : %d"), ptrWeather->pressure_mb);
  2601.             PRINT(F("\n[API] [Weather] Pressure in      : %0.2f"), ptrWeather->pressure_in);
  2602.             PRINT(F("\n[API] [Weather] Precip mm        : %0.2f"), ptrWeather->precip_mm);
  2603.             PRINT(F("\n[API] [Weather] Precip in        : %0.2f"), ptrWeather->precip_in);
  2604.             PRINT(F("\n[API] [Weather] Humidity         : %d"), ptrWeather->humidity);
  2605.             PRINT(F("\n[API] [Weather] Cloud            : %d"), ptrWeather->cloud);
  2606.             PRINT(F("\n[API] [Weather] Vis km           : %0.2f"), ptrWeather->vis_km);
  2607.             PRINT(F("\n[API] [Weather] Vis miles        : %0.2f"), ptrWeather->vis_miles);  
  2608.             PRINT(F("\n"));          
  2609.         #endif
  2610.         #if POLISH
  2611.             PRINT(F("\n[API] [Weather] City             : %s"), ptrWeather->city);
  2612.             PRINT(F("\n[API] [Weather] Country          : %s"), ptrWeather->country);
  2613.             PRINT(F("\n[API] [Weather] TZ ID            : %s"), ptrWeather->tz_id);
  2614.             PRINT(F("\n[API] [Weather] Latitude         : %0.2f"), ptrWeather->lat);
  2615.             PRINT(F("\n[API] [Weather] Longitude        : %0.2f"), ptrWeather->lon);
  2616.             PRINT(F("\n[API] [Weather] Epoch Time       : %d"), ptrWeather->localtime_epoch);
  2617.             PRINT(F("\n[API] [Weather] Localtime        : %s"), ptrWeather->localtime);
  2618.             PRINT(F("\n[API] [Weather] Last Updade      : %s"), ptrWeather->last_updated);
  2619.             PRINT(F("\n[API] [Weather] Temp C           : %0.2f"), ptrWeather->temp_c);
  2620.             PRINT(F("\n[API] [Weather] Temp feel C      : %0.2f"), ptrWeather->feelslike_c);
  2621.             PRINT(F("\n[API] [Weather] Temp F           : %0.2f"), ptrWeather->temp_f);
  2622.             PRINT(F("\n[API] [Weather] Temp feel F      : %0.2f"), ptrWeather->feelslike_f);
  2623.             PRINT(F("\n[API] [Weather] Condition EN     : %s"), ptrWeather->condition_en);
  2624.             PRINT(F("\n[API] [Weather] Condition PL     : %s"), ptrWeather->condition_pl);
  2625.             PRINT(F("\n[API] [Weather] icon             : %s"), ptrWeather->icon);
  2626.             PRINT(F("\n[API] [Weather] icon code        : %d"), ptrWeather->code);
  2627.             PRINT(F("\n[API] [Weather] Wind speed kph   : %0.2f"), ptrWeather->wind_kph);
  2628.             PRINT(F("\n[API] [Weather] Wind gust kph    : %0.2f"), ptrWeather->gust_kph);
  2629.             PRINT(F("\n[API] [Weather] Wind speed mph   : %0.2f"), ptrWeather->wind_mph);
  2630.             PRINT(F("\n[API] [Weather] Wind gust mph    : %0.2f"), ptrWeather->gust_mph);
  2631.             PRINT(F("\n[API] [Weather] Wind degree      : %d"), ptrWeather->wind_degree);
  2632.             PRINT(F("\n[API] [Weather] Wind dir         : %s"), ptrWeather->wind_dir);
  2633.             PRINT(F("\n[API] [Weather] Pressure mb      : %d"), ptrWeather->pressure_mb);
  2634.             PRINT(F("\n[API] [Weather] Pressure in      : %0.2f"), ptrWeather->pressure_in);
  2635.             PRINT(F("\n[API] [Weather] Precip mm        : %0.2f"), ptrWeather->precip_mm);
  2636.             PRINT(F("\n[API] [Weather] Precip in        : %0.2f"), ptrWeather->precip_in);
  2637.             PRINT(F("\n[API] [Weather] Humidity         : %d"), ptrWeather->humidity);
  2638.             PRINT(F("\n[API] [Weather] Cloud            : %d"), ptrWeather->cloud);
  2639.             PRINT(F("\n[API] [Weather] Vis km           : %0.2f"), ptrWeather->vis_km);
  2640.             PRINT(F("\n[API] [Weather] Vis miles        : %0.2f"), ptrWeather->vis_miles);  
  2641.             PRINT(F("\n"));          
  2642.         #endif
  2643.     #endif  
  2644. }
  2645.  
  2646. // ------------------------------------------------------------------------------------------------------------ //
  2647.  
  2648. void ptrAstronomyMalloc()
  2649. {
  2650.     if (!F_ptrAstronomy)
  2651.     {
  2652.         #if SERIAL
  2653.             #if ENGLISH        
  2654.                 PRINT(F("\n[ESP] [Weather Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
  2655.                 PRINT(F("\n[ESP] [Weather Malloc] i try allocate memory in RAM for struct -> Astronomy"));
  2656.             #endif
  2657.             #if POLISH
  2658.                 PRINT(F("\n[ESP] [Weather Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
  2659.                 PRINT(F("\n[ESP] [Weather Malloc] próba alokacji pamięci RAM dla struktury -> Astronomy"));
  2660.             #endif
  2661.         #endif
  2662.      
  2663.         ptrAstronomy = ( struct Astronomy * ) malloc ( sizeof (struct Astronomy) );    
  2664.         F_ptrAstronomy = true;
  2665.  
  2666.         #if SERIAL
  2667.             #if ENGLISH          
  2668.                 PRINT(F("\n[ESP] [Weather Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
  2669.                 PRINT(F("\n[ESP] [Weather Malloc] allocate memory in RAM for struct Astronomy sucefull\n"));
  2670.             #endif
  2671.             #if POLISH
  2672.                 PRINT(F("\n[ESP] [Weather Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
  2673.                 PRINT(F("\n[ESP] [Weather Malloc] alokakacji pamięci RAM dla struktury -> Astronomy UDANA\n"));
  2674.             #endif
  2675.         #endif
  2676.     }
  2677. }
  2678.  
  2679. // ------------------------------------------------------------------------------------------------------------ //
  2680.  
  2681. void ptrAstronomyFree()
  2682. {
  2683.     if (F_ptrAstronomy)
  2684.     {
  2685.         free(ptrAstronomy);
  2686.         F_ptrAstronomy = false;        
  2687.  
  2688.         #if SERIAL
  2689.             #if ENGLISH
  2690.                 PRINT(F("\n[ESP] [Astronomy Malloc] delete [ptrAstronomy] from RAM memory ..."));          
  2691.             #endif        
  2692.             #if POLISH
  2693.                 PRINT(F("\n[ESP] [Astronomy Malloc] usunięto [ptrAstronomy] z pamięci RAM ..."));        
  2694.             #endif
  2695.         #endif
  2696.     }
  2697.     else
  2698.     {
  2699.         #if SERIAL
  2700.             #if ENGLISH
  2701.                 PRINT(F("\n[ESP] [Astronomy] cannot be deleted [ptrAstronomy] does not exist !!! "));          
  2702.             #endif        
  2703.             #if POLISH
  2704.                 PRINT(F("\n[ESP] [Astronomy] nie można usunąć [ptrAstronomy] nie isnieje w pamięci RAM ..."));        
  2705.             #endif
  2706.         #endif  
  2707.     }
  2708. }
  2709.  
  2710.  
  2711. // ------------------------------------------------------------------------------------------------------------ //
  2712. // Display weather icon (sun/night) - load file *.jpg from SPIFF memory --------------------------------------- //
  2713. // ------------------------------------------------------------------------------------------------------------ //
  2714. // Wyświetla ikonę pogody (dzień/noc) - plik *.jpg ładowany z pamięci SPIFF ----------------------------------- //
  2715. // ------------------------------------------------------------------------------------------------------------ //
  2716.  
  2717. void TFT_WeatherIconShow()
  2718. {
  2719.     byte pos_x = 1;       // współrzędna ekranu -> x
  2720.     byte pos_y = 60;      // współrzędna ekranu -> y
  2721.        
  2722.     switch(ptrWeather->code)
  2723.     {
  2724.         case  1000  :
  2725.                       {
  2726.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2727.                           {
  2728.                              drawJpeg("/weather/150s00.jpg",  pos_x, pos_y);          // clear sun
  2729.                           }
  2730.                           else
  2731.                           {
  2732.                              drawJpeg("/weather/150m00.jpg",  pos_x, pos_y);          // clear moon
  2733.                           }
  2734.                           break;
  2735.                       }
  2736.         case  1003  :
  2737.                       {
  2738.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2739.                           {                              
  2740.                              drawJpeg("/weather/150s01.jpg", pos_x, pos_y);          // Partly cloudy sun (Test OK) rozmiar 150x150                            
  2741.                           }
  2742.                           else
  2743.                           {  
  2744.                              drawJpeg("/weather/150m01.jpg", pos_x, pos_y);          // Partly cloudy moon (Test OK) rozmiar 150x150
  2745.                           }
  2746.                           break;
  2747.                       }
  2748.                      
  2749.         case  1006  :
  2750.                       {
  2751.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2752.                           {
  2753.                              drawJpeg("/weather/150s02.jpg", pos_x, pos_y);          // cloudy sun (Test OK) rozmiar 150x150
  2754.                           }
  2755.                           else
  2756.                           {
  2757.                              drawJpeg("/weather/150m02.jpg", pos_x, pos_y);          // cloudy moon (Test OK) rozmiar 150x150
  2758.                           }
  2759.                           break;
  2760.                       }
  2761.         case  1009  : {
  2762.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2763.                           {
  2764.                              drawJpeg("/weather/150ovc.jpg", pos_x, pos_y);          // overcast (Tesk OK) rozmiar 150x150
  2765.                           }
  2766.                           else
  2767.                           {
  2768.                              drawJpeg("/weather/150ovc.jpg", pos_x, pos_y);          // overcast (Tesk OK) rozmiar 150x150
  2769.                           }
  2770.                           break;  
  2771.                       }
  2772.         case  1030  :
  2773.                       {
  2774.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2775.                           {
  2776.                              drawJpeg("/weather/150s10.jpg", pos_x, pos_y);          // mist (day) mgła dzień
  2777.                           }
  2778.                           else
  2779.                           {
  2780.                              drawJpeg("/weather/150m10.jpg", pos_x, pos_y);          // mist (night) mgła noc
  2781.                           }
  2782.                           break;  
  2783.                       }
  2784.         case  1063  :
  2785.                     {
  2786.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2787.                           {
  2788.                              drawJpeg("/weather/150s10.jpg", pos_x, pos_y);          // Patchy rain possible
  2789.                           }
  2790.                           else
  2791.                           {
  2792.                              drawJpeg("/weather/150m10.jpg", pos_x, pos_y);          // Patchy rain possible
  2793.                           }
  2794.                           break;  
  2795.                       }        
  2796.         case  1066  :
  2797.                     {
  2798.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2799.                           {
  2800.                              drawJpeg("/weather/150dps.jpg", pos_x, pos_y);          // Patchy snow possible (day) 150x150
  2801.                           }
  2802.                           else
  2803.                           {
  2804.                              drawJpeg("/weather/150mps.jpg", pos_x, pos_y);          // Patchy snow possible (night) 150x150
  2805.                           }
  2806.                           break;  
  2807.                     }        
  2808.         case  1069  :
  2809.                     {
  2810.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2811.                           {
  2812.                              drawJpeg("/weather/150dps.jpg", pos_x, pos_y);          // Patchy sleet possible (day) 150x150
  2813.                           }
  2814.                           else
  2815.                           {
  2816.                              drawJpeg("/weather/150mps.jpg", pos_x, pos_y);          // Patchy sleet possible (night) 150x150
  2817.                           }
  2818.                           break;  
  2819.                       }        
  2820.         case  1072  :
  2821.                     {
  2822.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2823.                           {
  2824.                              drawJpeg("/weather/150dmm.jpg", pos_x, pos_y);          // Patchy freezing drizzle possible (day) 150x150
  2825.                           }
  2826.                           else
  2827.                           {
  2828.                              drawJpeg("/weather/150nmm.jpg", pos_x, pos_y);          // Patchy freezing drizzle possible (night) 150x150
  2829.                           }
  2830.                           break;  
  2831.                       }  
  2832.         case  1087  :
  2833.                     {
  2834.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2835.                           {
  2836.                              drawJpeg("/weather/150sth.jpg", pos_x, pos_y);          // thunder possible 150x150
  2837.                           }
  2838.                           else
  2839.                           {
  2840.                              drawJpeg("/weather/150mth.jpg", pos_x, pos_y);          // thunder possible 150x150
  2841.                           }
  2842.                           break;  
  2843.                     }        
  2844.         case  1114  :
  2845.                     {
  2846.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2847.                           {
  2848.                              drawJpeg("/weather/150dmm.jpg", pos_x, pos_y);          // // Blowing snow 150x150
  2849.                           }
  2850.                           else
  2851.                           {
  2852.                              drawJpeg("/weather/150nmm.jpg", pos_x, pos_y);          // // Blowing snow 150x150
  2853.                           }
  2854.                           break;  
  2855.                     }
  2856.         case  1117  :
  2857.                     {
  2858.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2859.                           {
  2860.                              drawJpeg("/weather/150zss.jpg", pos_x, pos_y);          // blizzard 150x150
  2861.                           }
  2862.                           else
  2863.                           {
  2864.                              drawJpeg("/weather/150zss.jpg", pos_x, pos_y);          // blizzard 150x150
  2865.                           }
  2866.                           break;  
  2867.                      }  
  2868.         case  1135  :
  2869.                     {
  2870.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2871.                           {
  2872.                              drawJpeg("/weather/150s10.jpg", pos_x, pos_y);          // mist (day) mgła dzień 150x150
  2873.                           }
  2874.                           else
  2875.                           {
  2876.                              drawJpeg("/weather/150m10.jpg", pos_x, pos_y);             // mist (night) mgła noc 150x150
  2877.                           }
  2878.                           break;  
  2879.                       }
  2880.         case  1147  :
  2881.                     {
  2882.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2883.                           {
  2884.                              drawJpeg("/weather/150s10.jpg.jpg", pos_x, pos_y);          // mist (day) mgła dzień 150x150
  2885.                           }
  2886.                           else
  2887.                           {
  2888.                              drawJpeg("/weather/150m10.jpg", pos_x, pos_y);             // mist (night) mgła noc 150x150
  2889.                           }
  2890.                           break;  
  2891.                     }
  2892.         case  1150  :
  2893.                     {
  2894.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2895.                           {
  2896.                              drawJpeg("/weather/150s04.jpg.jpg", pos_x, pos_y);          // Patchy light drizzle 150x150
  2897.                           }
  2898.                           else
  2899.                           {
  2900.                              drawJpeg("/weather/150m04.jpg", pos_x, pos_y);              // Patchy light drizzle 150x150
  2901.                           }
  2902.                           break;  
  2903.                     }
  2904.         case  1153  :
  2905.                     {
  2906.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2907.                           {
  2908.                              drawJpeg("/weather/150s04.jpg.jpg", pos_x, pos_y);          // light drizzle 150x150
  2909.                           }
  2910.                           else
  2911.                           {
  2912.                              drawJpeg("/weather/150m04.jpg", pos_x, pos_y);              // light drizzle 150x150
  2913.                           }
  2914.                           break;  
  2915.                     }
  2916.        case  1168   :
  2917.                     {
  2918.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2919.                           {
  2920.                              drawJpeg("/weather/150dmm.jpg", pos_x, pos_y);          // freezing drizzle possible (day) 150x150
  2921.                           }
  2922.                           else
  2923.                           {
  2924.                              drawJpeg("/weather/150nmm.jpg", pos_x, pos_y);          // freezing drizzle possible (night) 150x150
  2925.                           }
  2926.                           break;  
  2927.                     }        
  2928.         case  1171  :
  2929.                     {
  2930.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2931.                           {
  2932.                              drawJpeg("/weather/150mm.jpg", pos_x, pos_y);          // Heavy freezing drizzle (day) 150x150
  2933.                           }
  2934.                           else
  2935.                           {
  2936.                              drawJpeg("/weather/150mm.jpg", pos_x, pos_y);          // Heavy freezing drizzle (night) 150x150
  2937.                           }
  2938.                           break;  
  2939.                     }
  2940.         case  1180  :
  2941.                     {
  2942.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2943.                           {
  2944.                              drawJpeg("/weather/150s04.jpg", pos_x, pos_y);          // patchy rain at times  
  2945.                           }
  2946.                           else
  2947.                           {
  2948.                              drawJpeg("/weather/150m04.jpg",  pos_x, pos_y);         // patchy rain at times  
  2949.                           }
  2950.                           break;                        
  2951.                     }        
  2952.         case  1183  :
  2953.                     {
  2954.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2955.                           {
  2956.                              drawJpeg("/weather/150s04.jpg", pos_x, pos_y);          // light rain at times  
  2957.                           }
  2958.                           else
  2959.                           {
  2960.                              drawJpeg("/weather/150m04.jpg",  pos_x, pos_y);          // light rain at times  
  2961.                           }
  2962.                           break;                        
  2963.                     }
  2964.         case  1186  :                                                         // Moderate rain at times  
  2965.                     {
  2966.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2967.                           {
  2968.                              drawJpeg("/weather/150s04.jpg", pos_x, pos_y);          // Moderate rain at times  
  2969.                           }
  2970.                           else
  2971.                           {
  2972.                              drawJpeg("/weather/150m04.jpg",  pos_x, pos_y);          // Moderate rain at times  
  2973.                           }
  2974.                           break;                        
  2975.                     }
  2976.        
  2977.         case  1189  :                                                               // Moderate rain
  2978.                     {
  2979.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2980.                           {
  2981.                              drawJpeg("/weather/150s05.jpg", pos_x, pos_y);          // Moderate rain  
  2982.                           }
  2983.                           else
  2984.                           {
  2985.                              drawJpeg("/weather/150m05.jpg",  pos_x, pos_y);          // Moderate rain
  2986.                           }
  2987.                           break;                        
  2988.                     }        
  2989.        
  2990.         case  1192  :                                                           // Heavy rain at times
  2991.                     {
  2992.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  2993.                           {
  2994.                              drawJpeg("/weather/150s06.jpg", pos_x, pos_y);          // Heavy rain at times
  2995.                           }
  2996.                           else
  2997.                           {
  2998.                              drawJpeg("/weather/150m06.jpg",  pos_x, pos_y);          // Heavy rain at times
  2999.                           }
  3000.                           break;                        
  3001.                     }
  3002.        
  3003.         case  1195  :
  3004.                     {
  3005.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3006.                           {
  3007.                              drawJpeg("/weather/150s06.jpg", pos_x, pos_y);          // Heavy rain
  3008.                           }
  3009.                           else
  3010.                           {
  3011.                              drawJpeg("/weather/150m06.jpg",  pos_x, pos_y);          // Heavy rain
  3012.                           }
  3013.                           break;                        
  3014.                     }
  3015.        
  3016.         case  1198  :
  3017.                     {
  3018.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3019.                           {
  3020.                              drawJpeg("/weather/150s04.jpg", pos_x, pos_y);          // light rain at times  
  3021.                           }
  3022.                           else
  3023.                           {
  3024.                              drawJpeg("/weather/150m04.jpg",  pos_x, pos_y);          // light rain at times  
  3025.                           }
  3026.                           break;                        
  3027.                     }
  3028.         case  1201  :
  3029.                     {
  3030.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3031.                           {
  3032.                              drawJpeg("/weather/150s07.jpg", pos_x, pos_y);          // Moderate or heavy freezing rain
  3033.                           }
  3034.                           else
  3035.                           {
  3036.                              drawJpeg("/weather/150m07.jpg",  pos_x, pos_y);         // Moderate or heavy freezing rain  
  3037.                           }
  3038.                           break;                        
  3039.                     }
  3040.         case  1204  :
  3041.                     {
  3042.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3043.                           {
  3044.                              drawJpeg("/weather/150s07.jpg", pos_x, pos_y);          // Light sleet
  3045.                           }
  3046.                           else
  3047.                           {
  3048.                              drawJpeg("/weather/150m07.jpg",  pos_x, pos_y);         // Light sleet
  3049.                           }
  3050.                           break;                        
  3051.                     }
  3052.         case  1207  :
  3053.                     {
  3054.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3055.                           {
  3056.                              drawJpeg("/weather/150s07.jpg", pos_x, pos_y);          // Moderate or heavy sleet
  3057.                           }
  3058.                           else
  3059.                           {
  3060.                              drawJpeg("/weather/150m07.jpg",  pos_x, pos_y);         // Moderate or heavy sleet
  3061.                           }
  3062.                           break;                        
  3063.                     }
  3064.         case  1210  :
  3065.                     {
  3066.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3067.                           {
  3068.                              drawJpeg("/weather/150ss.jpg", pos_x, pos_y);          // moderate snow
  3069.                           }
  3070.                           else
  3071.                           {
  3072.                              drawJpeg("/weather/150ms.jpg", pos_x, pos_y);          // moderate snow
  3073.                           }
  3074.                           break;                        
  3075.                     }
  3076.         case  1213  :
  3077.                     {
  3078.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3079.                           {
  3080.                              drawJpeg("/weather/150ss.jpg", pos_x, pos_y);          // light snow
  3081.                           }
  3082.                           else
  3083.                           {
  3084.                              drawJpeg("/weather/150ms.jpg", pos_x, pos_y);          // light snow
  3085.                           }
  3086.                           break;                        
  3087.                     }
  3088.                
  3089.         case  1216  :
  3090.                     {
  3091.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3092.                           {
  3093.                              drawJpeg("/weather/150ss.jpg", pos_x, pos_y);          // Patchy moderate snow
  3094.                           }
  3095.                           else
  3096.                           {
  3097.                              drawJpeg("/weather/150ms.jpg", pos_x, pos_y);          // Patchy moderate snow
  3098.                           }
  3099.                           break;                        
  3100.                     }
  3101.         case  1219  :
  3102.                     {
  3103.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3104.                           {
  3105.                              drawJpeg("/weather/150ss.jpg", pos_x, pos_y);          // Moderate snow
  3106.                           }
  3107.                           else
  3108.                           {
  3109.                              drawJpeg("/weather/150ms.jpg", pos_x, pos_y);          // Moderate snow
  3110.                           }
  3111.                           break;                        
  3112.                     }        
  3113.         case  1222  :
  3114.                     {
  3115.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3116.                           {
  3117.                              drawJpeg("/weather/150snow.jpg", pos_x, pos_y);          // Patchy heavy snow
  3118.                           }
  3119.                           else
  3120.                           {
  3121.                              drawJpeg("/weather/150snow.jpg", pos_x, pos_y);          // Patchy heavy snow
  3122.                           }
  3123.                           break;                        
  3124.                     }  
  3125.         case  1225  :
  3126.                     {
  3127.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3128.                           {
  3129.                              drawJpeg("/weather/150snow.jpg", pos_x, pos_y);          // heavy snow
  3130.                           }
  3131.                           else
  3132.                           {
  3133.                              drawJpeg("/weather/150snow.jpg", pos_x, pos_y);          // heavy snow
  3134.                           }
  3135.                           break;                        
  3136.                     }  
  3137.         case  1237  :
  3138.                     {
  3139.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3140.                           {
  3141.                              drawJpeg("/weather/150snow.jpg", pos_x, pos_y);          // Ice pellets
  3142.                           }
  3143.                           else
  3144.                           {
  3145.                              drawJpeg("/weather/150snow.jpg", pos_x, pos_y);          // Ice pellets
  3146.                           }
  3147.                           break;                        
  3148.                     }  
  3149.         case  1240  :                                                        
  3150.                     {
  3151.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3152.                           {
  3153.                              drawJpeg("/weather/150s04.jpg", pos_x, pos_y);          // light rain shower
  3154.                           }
  3155.                           else
  3156.                           {
  3157.                              drawJpeg("/weather/150m04.jpg",  pos_x, pos_y);          // light rain shower
  3158.                           }
  3159.                           break;                        
  3160.                     }        
  3161.        
  3162.         case  1243  :
  3163.                     {
  3164.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3165.                           {
  3166.                              drawJpeg("/weather/150s06.jpg", pos_x, pos_y);          // "Moderate or heavy rain shower"
  3167.                           }
  3168.                           else
  3169.                           {
  3170.                              drawJpeg("/weather/150m06.jpg",  pos_x, pos_y);          // "Moderate or heavy rain shower"
  3171.                           }
  3172.                           break;                        
  3173.                     }
  3174.      
  3175.         case  1246  :                                                               // Torrential rain shower
  3176.                     {
  3177.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3178.                           {
  3179.                              drawJpeg("/weather/150s06.jpg", pos_x, pos_y);          // Torrential rain shower
  3180.                           }
  3181.                           else
  3182.                           {
  3183.                              drawJpeg("/weather/150m06.jpg",  pos_x, pos_y);          // Torrential rain shower
  3184.                           }
  3185.                           break;                        
  3186.                     }
  3187.         case  1249  :
  3188.                     {
  3189.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3190.                           {
  3191.                              drawJpeg("/weather/150ss.jpg", pos_x, pos_y);          // Light sleet showers
  3192.                           }
  3193.                           else
  3194.                           {
  3195.                              drawJpeg("/weather/150ms.jpg", pos_x, pos_y);          // Light sleet showers
  3196.                           }
  3197.                           break;                        
  3198.                     }            
  3199.         case  1252  :
  3200.                     {
  3201.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3202.                           {
  3203.                              drawJpeg("/weather/150ss.jpg", pos_x, pos_y);          // Moderate or heavy sleet showers
  3204.                           }
  3205.                           else
  3206.                           {
  3207.                              drawJpeg("/weather/150ms.jpg", pos_x, pos_y);          // Moderate or heavy sleet showers
  3208.                           }
  3209.                           break;                        
  3210.                     }    
  3211.         case  1255  :
  3212.                     {
  3213.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3214.                           {
  3215.                              drawJpeg("/weather/150ss.jpg", pos_x, pos_y);          // Light snow showers
  3216.                           }
  3217.                           else
  3218.                           {
  3219.                              drawJpeg("/weather/150ms.jpg", pos_x, pos_y);          // Light snow showers
  3220.                           }
  3221.                           break;                        
  3222.                     }        
  3223.         case  1258  :
  3224.                     {
  3225.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3226.                           {
  3227.                              drawJpeg("/weather/150ss.jpg", pos_x, pos_y);          // Moderate or heavy snow showers
  3228.                           }
  3229.                           else
  3230.                           {
  3231.                              drawJpeg("/weather/150ms.jpg", pos_x, pos_y);          // Moderate or heavy snow showers
  3232.                           }
  3233.                           break;                        
  3234.                     }          
  3235.         case  1261  :
  3236.                     {
  3237.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3238.                           {
  3239.                              drawJpeg("/weather/150ss.jpg", pos_x, pos_y);          // Light showers of ice pellets
  3240.                           }
  3241.                           else
  3242.                           {
  3243.                              drawJpeg("/weather/150ms.jpg", pos_x, pos_y);          // Light showers of ice pellets
  3244.                           }
  3245.                           break;                        
  3246.                     }          
  3247.         case  1264  :
  3248.                     {
  3249.                           if (myRTC.hours > 7 && myRTC.hours < 20)
  3250.                           {
  3251.                              drawJpeg("/weather/150ss.jpg", pos_x, pos_y);          // Moderate or heavy showers of ice pellets
  3252.                           }
  3253.                           else
  3254.                           {
  3255.                              drawJpeg("/weather/150ms.jpg", pos_x, pos_y);          // Moderate or heavy showers of ice pellets
  3256.                           }
  3257.                           break;                        
  3258.                     }          
  3259.         case  1273  :
  3260.                     {
  3261.                         if (myRTC.hours > 7 && myRTC.hours < 20)
  3262.                         {
  3263.                             drawJpeg("/weather/150dprt.jpg", pos_x, pos_y);         // Patchy light rain with thunder
  3264.                         }
  3265.                         else
  3266.                         {
  3267.                            drawJpeg("/weather/1150nprt.jpg", pos_x, pos_y);         // Patchy light rain with thunder
  3268.                         }
  3269.                         break;
  3270.                     }        
  3271.         case  1276  :
  3272.                     {
  3273.                         if (myRTC.hours > 7 && myRTC.hours < 20)
  3274.                         {
  3275.                             drawJpeg("/weather/150srt01.jpg", pos_x, pos_y);         // rain and thunder
  3276.                         }
  3277.                         else
  3278.                         {
  3279.                            drawJpeg("/weather/150mrt01.jpg", pos_x, pos_y);         // rain and thunder        
  3280.                         }
  3281.                         break;
  3282.                     }
  3283.         case  1279  :
  3284.                     {
  3285.                         if (myRTC.hours > 7 && myRTC.hours < 20)
  3286.                         {
  3287.                             drawJpeg("/weather/150srt01.jpg", pos_x, pos_y);         // Patchy light snow with thunder
  3288.                         }
  3289.                         else
  3290.                         {
  3291.                            drawJpeg("/weather/150mrt01.jpg", pos_x, pos_y);         // Patchy light snow with thunder
  3292.                         }
  3293.                         break;
  3294.                     }
  3295.         case  1282  :
  3296.                     {
  3297.                         if (myRTC.hours > 7 && myRTC.hours < 20)
  3298.                         {
  3299.                             drawJpeg("/weather/150srt01.jpg", pos_x, pos_y);         // Moderate or heavy snow with thunder        
  3300.                         }
  3301.                         else
  3302.                         {
  3303.                            drawJpeg("/weather/150mrt01.jpg", pos_x, pos_y);         // Moderate or heavy snow with thunder        
  3304.                         }
  3305.                         break;
  3306.                     }
  3307.     }
  3308.  
  3309. }
  3310.  
  3311. // ------------------------------------------------------------------------------------------------------------ //
  3312. // --- ASTRONOMY SHOW FROM BUFFOR in RAM                                                                    --- //
  3313. // ------------------------------------------------------------------------------------------------------------ //
  3314. // --- DUAL LANGUAGE --- POLISH & ENGLISH --- SET IN MACRO in MAIN PROJECT --- TRANSLATE in GOOGLE --- :-) ---  //
  3315. // ------------------------------------------------------------------------------------------------------------ //
  3316.  
  3317. void AstronomyShow()
  3318. {
  3319.     #if SERIAL
  3320.         #if ENGLISH
  3321.             PRINT(F("\n[API] [Astronomy] City             : %s"), ptrAstronomy->city);
  3322.             PRINT(F("\n[API] [Astronomy] Country          : %s"), ptrAstronomy->country);
  3323.             PRINT(F("\n[API] [Astronomy] TZ ID            : %s"), ptrAstronomy->tz_id);          
  3324.             PRINT(F("\n[API] [Astronomy] Latitude         : %0.2f"), ptrAstronomy->lat);
  3325.             PRINT(F("\n[API] [Astronomy] Longitude        : %0.2f"), ptrAstronomy->lon);
  3326.             PRINT(F("\n[API] [Astronomy] Epoch Time       : %d"), ptrAstronomy->localtime_epoch);
  3327.             PRINT(F("\n[API] [Astronomy] Localtime        : %s"), ptrAstronomy->localtime);
  3328.             PRINT(F("\n[API] [Astronomy] Sunrise          : %s"), ptrAstronomy->sunrise);
  3329.             PRINT(F("\n[API] [Astronomy] Sunset           : %s"), ptrAstronomy->sunset);
  3330.             PRINT(F("\n[API] [Astronomy] Moonrise         : %s"), ptrAstronomy->moonrise);
  3331.             PRINT(F("\n[API] [Astronomy] Moonset          : %s"), ptrAstronomy->moonset);    
  3332.             PRINT(F("\n[API] [Astronomy] Moon Phase       : %s"), ptrAstronomy->moon_phase);
  3333.             PRINT(F("\n[API] [Astronomy] Illumination     : %d"), ptrAstronomy->moon_illumination);    
  3334.             PRINT(F("\n"));  
  3335.         #endif
  3336.         #if POLISH
  3337.             PRINT(F("\n[API] [Astronomy] City             : %s"), ptrAstronomy->city);
  3338.             PRINT(F("\n[API] [Astronomy] Country          : %s"), ptrAstronomy->country);
  3339.             PRINT(F("\n[API] [Astronomy] TZ ID            : %s"), ptrAstronomy->tz_id);          
  3340.             PRINT(F("\n[API] [Astronomy] Latitude         : %0.2f"), ptrAstronomy->lat);
  3341.             PRINT(F("\n[API] [Astronomy] Longitude        : %0.2f"), ptrAstronomy->lon);
  3342.             PRINT(F("\n[API] [Astronomy] Epoch Time       : %d"), ptrAstronomy->localtime_epoch);
  3343.             PRINT(F("\n[API] [Astronomy] Localtime        : %s"), ptrAstronomy->localtime);
  3344.             PRINT(F("\n[API] [Astronomy] Sunrise          : %s"), ptrAstronomy->sunrise);
  3345.             PRINT(F("\n[API] [Astronomy] Sunset           : %s"), ptrAstronomy->sunset);
  3346.             PRINT(F("\n[API] [Astronomy] Moonrise         : %s"), ptrAstronomy->moonrise);
  3347.             PRINT(F("\n[API] [Astronomy] Moonset          : %s"), ptrAstronomy->moonset);    
  3348.             PRINT(F("\n[API] [Astronomy] Moon Phase       : %s"), ptrAstronomy->moon_phase);
  3349.             PRINT(F("\n[API] [Astronomy] Illumination     : %d"), ptrAstronomy->moon_illumination);          
  3350.             PRINT(F("\n"));
  3351.         #endif
  3352.     #endif  
  3353. }
  3354.  
  3355. // ------------------------------------------------------------------------------------------------------------ //
  3356. // ---    ASTRONOMY UPDATE --- CREATE BUFFOR in RAM --- COPY DATA to STRUCT in RAM --- by TRANSLINE -------     //
  3357. // ------------------------------------------------------------------------------------------------------------ //
  3358. // --- DUAL LANGUAGE --- POLISH & ENGLISH --- SET IN MACRO in MAIN PROJECT --- TRANSLATE in GOOGLE --- :-) ---  //
  3359. // ------------------------------------------------------------------------------------------------------------ //
  3360.  
  3361. void AstronomyUpdate()
  3362. {
  3363.     if (!F_ptrAstronomy) ptrAstronomyMalloc();    // jesli pamięć nie utworzona stwórz ją w PSRAM
  3364.    
  3365.     #if SERIAL
  3366.         #if ENGLISH
  3367.             PRINT(F("\n[Astronomy Update] Try Downloading JSON File from https://api.weatherapi.com/"));            
  3368.         #endif
  3369.         #if POLISH
  3370.             PRINT(F("\n[Astronomy Update] Próbuję pobrać plik JSON z https://api.weatherapi.com/"));
  3371.         #endif
  3372.     #endif
  3373.  
  3374.     #if ENGLISH
  3375.         String path = "http://api.weatherapi.com/v1/astronomy.json?key=" + PogodaToken + "&q=" + PogodaMiasto;
  3376.     #endif
  3377.     #if POLISH
  3378.         String path = "http://api.weatherapi.com/v1/astronomy.json?key=" + PogodaToken + "&q=" + PogodaMiasto;
  3379.     #endif
  3380.        
  3381.     HTTPClient http;
  3382.     http.useHTTP10(true);
  3383.     http.begin(client, path);
  3384.     http.GET();
  3385.  
  3386.     DynamicJsonDocument doc(1024);
  3387.     DeserializationError error = deserializeJson(doc, http.getStream());
  3388.  
  3389.     if(error)
  3390.     {
  3391.         F_AstronomyUpdate = false;    //  aktualizacja nie powiodła się
  3392.         #if SERIAL
  3393.             #if ENGLISH
  3394.                 PRINT(F("\n[Astronomy Update] DeserializeJson() failed: "));
  3395.                 Serial.println(error.c_str());
  3396.             #endif
  3397.             #if POLISH
  3398.                 PRINT(F("\n[Astronomy Update] DeserializeJson() error: "));
  3399.                 Serial.println(error.c_str());
  3400.             #endif            
  3401.         #endif  
  3402.     }
  3403.     else
  3404.     {
  3405.         F_AstronomyUpdate = true;     // aktualizacja w porządku !!!
  3406.     }
  3407.  
  3408.     http.end();
  3409.  
  3410.     if(F_AstronomyUpdate)
  3411.     {
  3412.         #if SERIAL
  3413.             #if ENGLISH
  3414.                 PRINT(F("\n[ESP] [Astronomy Update] JsonDocument Usage Memory : %s bytes"), String(doc.memoryUsage()));                  
  3415.                 PRINT(F("\n[ESP] [Astronomy Update] [FREE RAM]                : %d kB\n"), ESP.getFreeHeap());      
  3416.             #endif
  3417.             #if POLISH
  3418.                 PRINT(F("\n[ESP] [Astronomy Update] JsonDocument zaalokował pamięć : %s bajtów"), String(doc.memoryUsage()));  
  3419.                 PRINT(F("\n[ESP] [Astronomy Update] [FREE RAM]                     : %d kB\n"), ESP.getFreeHeap());      
  3420.             #endif
  3421.         #endif
  3422.  
  3423.         // --- update struct ASTRONOMY in PSRAM !!! -------------------------------------------------- //
  3424.        
  3425.         strcpy(ptrAstronomy->sunrise, doc["astronomy"]["astro"]["sunrise"].as<String>().c_str());
  3426.         strcpy(ptrAstronomy->sunset, doc["astronomy"]["astro"]["sunset"].as<String>().c_str());
  3427.         sunrise = doc["astronomy"]["astro"]["sunrise"].as<String>();
  3428.         sunset  = doc["astronomy"]["astro"]["sunset"].as<String>();
  3429.         strcpy(ptrAstronomy->moonrise, doc["astronomy"]["astro"]["moonrise"].as<String>().c_str());
  3430.         moonrise = doc["astronomy"]["astro"]["moonrise"].as<String>();
  3431.         moonset  = doc["astronomy"]["astro"]["moonset"].as<String>();
  3432.         strcpy(ptrAstronomy->moonset, doc["astronomy"]["astro"]["moonset"].as<String>().c_str());
  3433.         strcpy(ptrAstronomy->moon_phase, doc["astronomy"]["astro"]["moon_phase"].as<String>().c_str());
  3434.         moon_phase = doc["astronomy"]["astro"]["moon_phase"].as<String>();
  3435.         ptrAstronomy->moon_illumination = doc["astronomy"]["astro"]["moon_illumination"];
  3436.         strcpy(ptrAstronomy->city, doc["location"]["name"].as<String>().c_str());                       // nazwę miasta
  3437.         strcpy(ptrAstronomy->country, doc["location"]["country"].as<String>().c_str());                 // nazwę kraju
  3438.         strcpy(ptrAstronomy->tz_id, doc["location"]["tz_id"].as<String>().c_str());                     // kontynent/stolica
  3439.         ptrAstronomy->lat = doc["location"]["lat"].as<double>();                                        // szer.geograficzną
  3440.         ptrAstronomy->lon = doc["location"]["lon"].as<double>();                                        // dł.geograficzną        
  3441.         strcpy(ptrAstronomy->localtime, doc["location"]["localtime"].as<String>().c_str());             // czas lokalny  
  3442.  
  3443.         // --- update struct ASTRONOMY in PSRAM !!! -------------------------------------------------- //
  3444.  
  3445.         #if SERIAL
  3446.             if (F_AstronomyUpdate) AstronomyShow();      // pokaż jeśli SERIAl jest TRUE    
  3447.         #endif
  3448.     }
  3449. }
  3450.  
  3451. // ------------------------------------------------------------------------------------------------------------ //
  3452.  
  3453. void ptrAirMalloc()
  3454. {
  3455.     if (!F_ptrAir)
  3456.     {
  3457.         #if SERIAL          
  3458.             PRINT(F("\n[ESP] [Air Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
  3459.             PRINT(F("\n[ESP] [Air Malloc] i try allocate memory in RAM for struct Air"));
  3460.         #endif
  3461.      
  3462.         ptrAir = ( struct Air * ) malloc ( sizeof (struct Air) );    
  3463.         F_ptrAstronomy = true;
  3464.  
  3465.         #if SERIAL          
  3466.             PRINT(F("\n[ESP] [Air Malloc] [FREE RAM] : %d kB"), ESP.getFreeHeap());
  3467.             PRINT(F("\n[ESP] [Air Malloc] allocate memory in RAM for struct Air sucefull\n"));
  3468.         #endif
  3469.     }
  3470. }
  3471.  
  3472. // ------------------------------------------------------------------------------------------------------------ //
  3473.  
  3474. void ptrAirFree()
  3475. {
  3476.     if (F_ptrAir)
  3477.     {
  3478.         free(ptrAir);
  3479.         F_ptrAir = false;        
  3480.  
  3481.         #if SERIAL
  3482.             #if ENGLISH
  3483.                 PRINT(F("\n[ESP] [Air Malloc] delete [ptrAir] from RAM memory ..."));          
  3484.             #endif        
  3485.             #if POLISH
  3486.                 PRINT(F("\n[ESP] [Air Malloc] usunięto [ptrAir] z pamięci RAM ..."));        
  3487.             #endif
  3488.         #endif
  3489.     }
  3490.     else
  3491.     {
  3492.         #if SERIAL
  3493.             #if ENGLISH
  3494.                 PRINT(F("\n[ESP] [Air] cannot be deleted [ptrAir] does not exist !!! "));          
  3495.             #endif        
  3496.             #if POLISH
  3497.                 PRINT(F("\n[ESP] [Air] nie można usunąć [ptrAir] nie isnieje w pamięci RAM ..."));        
  3498.             #endif
  3499.         #endif  
  3500.     }
  3501. }
  3502.  
  3503. // ------------------------------------------------------------------------------------------------------------ //
  3504. // --- Air SHOW FROM BUFFOR in PSRAM                                                                        --- //
  3505. // ------------------------------------------------------------------------------------------------------------ //
  3506. // --- DUAL LANGUAGE --- POLISH & ENGLISH --- SET IN MACRO in MAIN PROJECT --- TRANSLATE in GOOGLE --- :-) ---  //
  3507. // ------------------------------------------------------------------------------------------------------------ //
  3508.  
  3509. void AirShow()
  3510. {
  3511.     #if SERIAL
  3512.         #if ENGLISH
  3513.             PRINT(F("\n[API] [Air Quality] CO          : %2.3f [μg/ m3]"), ptrAir->co);
  3514.             PRINT(F("\n[API] [Air Quality] NO2         : %2.3f [μg/ m3]"), ptrAir->no2);
  3515.             PRINT(F("\n[API] [Air Quality] Ozon        : %2.3f [μg/m3]"), ptrAir->o3);
  3516.             PRINT(F("\n[API] [Air Quality] PM2.5       : %2.3f [μm]"), ptrAir->pm25);
  3517.             PRINT(F("\n[API] [Air Quality] PM10        : %2.3f [μm]"), ptrAir->pm10);
  3518.             PRINT(F("\n[API] [Air Quality] Index DEFRA : %d DEFRA"), ptrAir->defra);
  3519.             PRINT(F("\n[API] [Air Quality] Index EPA   : %d EPA"), ptrAir->epa);
  3520.             PRINT(F("\n[API] [Air Quality] Desciption  : %s "), ptrAir->description);          
  3521.             PRINT(F("\n"));        
  3522.            
  3523.         #endif
  3524.         #if POLISH
  3525.             PRINT(F("\n[API] [Jakość Powietrza] Tlenek węgla \t\t: %2.3f [μg/ m3]"), ptrAir->co);
  3526.             PRINT(F("\n[API] [Jakość Powietrza] Dwutlenek azotu \t: %2.3f [μg/ m3]"), ptrAir->no2);
  3527.             PRINT(F("\n[API] [Jakość Powietrza] Ozon \t\t\t: %2.3f [μg/m3]"), ptrAir->o3);
  3528.             PRINT(F("\n[API] [Jakość Powietrza] Pyły i aerozole PM2.5 \t: %2.3f [μm]"), ptrAir->pm25);
  3529.             PRINT(F("\n[API] [Jakość Powietrza] Pyły i aerozole PM10 \t: %2.3f [μm]"), ptrAir->pm10);
  3530.             PRINT(F("\n[API] [Jakość Powietrza] Index jakości \t\t: %d DEFRA"), ptrAir->defra);
  3531.             PRINT(F("\n[API] [Jakość Powietrza] Index jakości \t\t: %d EPA"), ptrAir->epa);
  3532.             PRINT(F("\n[API] [Jakość Powietrza] Jakość powietrza \t: %s "), ptrAir->description);          
  3533.             PRINT(F("\n"));          
  3534.         #endif
  3535.     #endif  
  3536. }
  3537.  
  3538. // ------------------------------------------------------------------------------------------------------------ //
  3539. // --- Air UPDATE --- CREATE BUFFOR in PSRAM --- COPY DATA to STRUCT Air in PSRAM --- by TRANSLINE -----------  //
  3540. // ------------------------------------------------------------------------------------------------------------ //
  3541. // --- DUAL LANGUAGE --- POLISH & ENGLISH --- SET IN MACRO in MAIN PROJECT --- TRANSLATE in GOOGLE --- :-) ---  //
  3542. // ------------------------------------------------------------------------------------------------------------ //
  3543.  
  3544. void AirUpdate()
  3545. {
  3546.     if (!F_ptrAir) ptrAirMalloc();    // jesli pamięć nie utworzona stwórz ją w PSRAM
  3547.    
  3548.     #if SERIAL
  3549.         #if ENGLISH
  3550.             PRINT(F("\n[Air Update] Try Downloading JSON File from https://api.weatherapi.com/"));
  3551.         #endif
  3552.         #if POLISH
  3553.             PRINT(F("\n[Air Update] Próbuję pobrać plik JSON z https://api.weatherapi.com/"));
  3554.         #endif
  3555.     #endif
  3556.  
  3557.     #if ENGLISH
  3558.         String path = "http://api.weatherapi.com/v1/current.json?key=" + PogodaToken + "&q=" + PogodaMiasto + "&aqi=yes";
  3559.     #endif
  3560.     #if POLISH
  3561.         String path = "http://api.weatherapi.com/v1/current.json?key=" + PogodaToken + "&q=" + PogodaMiasto + "&aqi=yes";
  3562.     #endif    
  3563.        
  3564.     HTTPClient http;
  3565.     http.useHTTP10(true);
  3566.     http.begin(client, path);
  3567.     http.GET();
  3568.  
  3569.     DynamicJsonDocument doc(2048);
  3570.     DeserializationError error = deserializeJson(doc, http.getStream());
  3571.        
  3572.     if(error)
  3573.     {
  3574.         F_AirUpdate = false;      // aktualizacja nie powiodła się
  3575.         #if SERIAL
  3576.             #if ENGLISH
  3577.                 PRINT(F("\n[Air Update] DeserializeJson() failed: "));
  3578.                 Serial.println(error.c_str());
  3579.             #endif
  3580.             #if POLISH
  3581.                 PRINT(F("\n[Air Update] DeserializeJson() error: "));
  3582.                 Serial.println(error.c_str());
  3583.             #endif        
  3584.         #endif  
  3585.     }
  3586.     else
  3587.     {
  3588.         F_AirUpdate = true;
  3589.     }
  3590.  
  3591.     http.end();
  3592.    
  3593.     if(F_AirUpdate)
  3594.     {
  3595.         #if SERIAL
  3596.             #if ENGLISH
  3597.                 PRINT(F("\n[ESP] [Air Update] JsonDocument Usage Memory : %s bytes"), String(doc.memoryUsage()));                  
  3598.                 PRINT(F("\n[ESP] [Air Update] [FREE RAM]                : %d kB\n"), ESP.getFreeHeap());      
  3599.             #endif
  3600.             #if POLISH
  3601.                 PRINT(F("\n[ESP] [Air Update] JsonDocument zaalokował pamięć : %s bajtów"), String(doc.memoryUsage()));  
  3602.                 PRINT(F("\n[ESP] [Air Update] [FREE RAM]                     : %d kB\n"), ESP.getFreeHeap());      
  3603.             #endif
  3604.         #endif
  3605.  
  3606.         // --- update struct Air in PSRAM !!! -------------------------------------------------- //
  3607.  
  3608.         ptrAir->co    = doc["current"]["air_quality"]["co"].as<double>();
  3609.         ptrAir->o3    = doc["current"]["air_quality"]["o3"].as<double>();
  3610.         ptrAir->no2   = doc["current"]["air_quality"]["no2"].as<double>();
  3611.         ptrAir->so2   = doc["current"]["air_quality"]["so2"].as<double>();
  3612.         ptrAir->pm25  = doc["current"]["air_quality"]["pm2_5"].as<double>();
  3613.         ptrAir->pm10  = doc["current"]["air_quality"]["pm10"].as<double>();
  3614.         ptrAir->defra = doc["current"]["air_quality"]["gb-defra-index"];
  3615.         ptrAir->epa   = doc["current"]["air_quality"]["us-epa-index"];
  3616.  
  3617.         switch (ptrAir->epa)
  3618.         {
  3619.             #if POLISH
  3620.                 case    1:  strcpy(ptrAir->description,  "dobra"); break;
  3621.                 case    2:  strcpy(ptrAir->description,  "umiarkowana"); break;
  3622.                 case    3:  strcpy(ptrAir->description,  "niezdrowa dla alergików"); break;
  3623.                 case    4:  strcpy(ptrAir->description,  "niezdrowa"); break;
  3624.                 case    5:  strcpy(ptrAir->description,  "bardzo niezdrowa"); break;
  3625.                 case    6:  strcpy(ptrAir->description,  "niebezpieczna"); break;
  3626.                 default  :  strcpy(ptrAir->description,  "błąd parsowania"); break;
  3627.             #endif
  3628.             #if ENGLISH
  3629.                 case    1:  strcpy(ptrAir->description,  "good"); break;
  3630.                 case    2:  strcpy(ptrAir->description,  "moderate"); break;
  3631.                 case    3:  strcpy(ptrAir->description,  "unhealthy for allergy sufferers"); break;
  3632.                 case    4:  strcpy(ptrAir->description,  "unhealthy"); break;
  3633.                 case    5:  strcpy(ptrAir->description,  "very unhealthy"); break;
  3634.                 case    6:  strcpy(ptrAir->description,  "dangerous"); break;
  3635.                 default  :  strcpy(ptrAir->description,  "parsing error"); break;
  3636.             #endif
  3637.         }
  3638.  
  3639.         // --- update struct Air in PSRAM !!! -------------------------------------------------- //
  3640.  
  3641.         #if SERIAL
  3642.             if (F_AirUpdate) AirShow();      // pokaż jeśli SERIAl jest TRUE    
  3643.         #endif
  3644.     }
  3645. }
  3646.  
  3647. // ------------------------------------------------------------------------------------------------------------ //
  3648. // --- W E A T H E R   E N D   S E C T I O N ------------------------------------------------------------------ //
  3649. // ------------------------------------------------------------------------------------------------------------ //
  3650. //
  3651. //
  3652. //
  3653. //
  3654. //
  3655. // ------------------------------------------------------------------------------------------------------------ //
  3656. // --- Opens the image file and prime the Jpeg decoder -------------------------------------------------------- //
  3657. // ------------------------------------------------------------------------------------------------------------ //
  3658. // --- Otwiera plik obrazu i uruchamia dekoder JPEG ----------------------------------------------------------- //
  3659. // ------------------------------------------------------------------------------------------------------------ //
  3660.  
  3661. void listFiles(void)
  3662. {
  3663.     #if SERIAL
  3664.         #if ENGLISH
  3665.             PRINT(F("\n\n====================================================================="));
  3666.             PRINT(F("SPIFFS files found:"));
  3667.             PRINT(F("\n  File name               Size"));
  3668.             PRINT(F("\n\n=====================================================================\n"));
  3669.         #endif
  3670.         #if POLISH
  3671.             PRINT(F("\n\n====================================================================="));
  3672.             PRINT(F("SPIFFS odnalezione pliki:"));
  3673.             PRINT(F("\n  Nazwa pliku             Rozmiar"));
  3674.             PRINT(F("\n\n=====================================================================\n"));
  3675.         #endif
  3676.     #endif
  3677.    
  3678.     fs::Dir dir = SPIFFS.openDir("/"); // Root directory
  3679.    
  3680.     String  line = "=====================================================================";
  3681.  
  3682.     while (dir.next())
  3683.     {
  3684.         String fileName = dir.fileName();
  3685.        
  3686.         Serial.print(fileName);
  3687.        
  3688.         int spaces = 25 - fileName.length(); // Tabulate nicely
  3689.         while (spaces--) PRINT(F(" "));
  3690.        
  3691.         fs::File f = dir.openFile("r");
  3692.         Serial.print(f.size());
  3693.  
  3694.         #if SERIAL
  3695.             #if ENGLISH
  3696.                 PRINT(F(" bytes"));
  3697.             #endif
  3698.             #if POLISH
  3699.                 PRINT(F(" bajtów"));
  3700.             #endif
  3701.         #endif
  3702.         Serial.println();
  3703.     }
  3704. }
  3705.  
  3706. // ------------------------------------------------------------------------------------------------------------ //
  3707. // --- replace minimum in JPEGDecoder !!! error in compilation ------------------------------------------------ //
  3708. // ------------------------------------------------------------------------------------------------------------ //
  3709.  
  3710. #define minimum(a,b)     (((a) < (b)) ? (a) : (b))
  3711.  
  3712. // ------------------------------------------------------------------------------------------------------------ //
  3713. // --- Opens the image file and prime the Jpeg decoder -------------------------------------------------------- //
  3714. // ------------------------------------------------------------------------------------------------------------ //
  3715. // --- Otwiera plik obrazu i uruchamia dekoder JPEG ----------------------------------------------------------- //
  3716. // ------------------------------------------------------------------------------------------------------------ //
  3717.  
  3718. void drawJpeg(const char *filename, int xpos, int ypos)
  3719. {
  3720.     #if SERIAL
  3721.         #if ENGLISH
  3722.             PRINT(F("\n\n====================================================================="));
  3723.             PRINT(F("\n[JPEG DECODER] [INFO] Drawing file: %s"), filename);            
  3724.         #endif
  3725.         #if POLISH
  3726.             PRINT(F("\n\n====================================================================="));
  3727.             PRINT(F("\nJPEG DECODER] [INFO] Wyświetlam plik: %s"), filename);            
  3728.         #endif
  3729.     #endif  
  3730.  
  3731.     fs::File jpegFile = SPIFFS.open( filename, "r");    
  3732.  
  3733.     if ( !jpegFile )
  3734.     {
  3735.         #if SERIAL
  3736.             #if ENGLISH
  3737.                 PRINT(F("\n[JPEG DECODER] [ERROR] File: %s not found!"), filename);
  3738.             #endif
  3739.             #if POLISH
  3740.                 PRINT(F("\n[JPEG DECODER] [ERROR] Plik: %s nie znaleziony!"), filename);
  3741.             #endif
  3742.         #endif
  3743.      
  3744.         return;
  3745.     }
  3746.  
  3747.     // ------------------------------------------------------------------------------------------------------------------- //
  3748.     //   Use one of the three following methods to initialise the decoder:                                                 //
  3749.     //   boolean decoded = JpegDec.decodeFsFile(jpegFile); // Pass a SPIFFS file handle to the decoder,                    //
  3750.     //   boolean decoded = JpegDec.decodeSdFile(jpegFile); // or pass the SD file handle to the decoder,                   //
  3751.     //   boolean decoded = JpegDec.decodeFsFile(filename);  // pass the filename (leading / distinguishes SPIFFS files)    //
  3752.     // ------------------------------------------------------------------------------------------------------------------- //
  3753.  
  3754.     boolean decoded = JpegDec.decodeFsFile(filename);  // pass the filename (leading / distinguishes SPIFFS files)
  3755.  
  3756.     if (decoded)
  3757.     {
  3758.         //jpegInfo();                   // print information about the image to the serial port    
  3759.         jpegRender(xpos, ypos);       // render the image onto the screen at given coordinates
  3760.     }
  3761.     else
  3762.     {
  3763.         #if SERIAL
  3764.             #if ENGLISH
  3765.                 PRINT(F("\n[JPEG DECODER] [ERROR] : Jpeg file format not supported!"));
  3766.             #endif
  3767.             #if POLISH
  3768.                 PRINT(F("\n[JPEG DECODER] [ERROR] : Format pliku JPEG nie jest obsługiwany!"));
  3769.             #endif
  3770.         #endif
  3771.    }
  3772.  
  3773.    #if SERIAL
  3774.       Serial.printf("\n=====================================================================");    // end line JPEG DECODER
  3775.    #endif
  3776. }
  3777.  
  3778. // ------------------------------------------------------------------------------------------------------------ //
  3779. // --- Decode and render the Jpeg image onto the TFT screen --------------------------------------------------- //
  3780. // ------------------------------------------------------------------------------------------------------------ //
  3781. // --- Dekoduj i renderuj obraz JPEG na ekranie TFT ----------------------------------------------------------- //
  3782. // ------------------------------------------------------------------------------------------------------------ //
  3783.  
  3784. void jpegRender(int xpos, int ypos)
  3785. {
  3786.     // ---------------------------------------------------------- //
  3787.     //          retrieve infomration about the image              //
  3788.     // ---------------------------------------------------------- //
  3789.     //             pobrać informacje o obrazie                    //
  3790.     // ---------------------------------------------------------- //
  3791.    
  3792.     uint16_t  *pImg;
  3793.     uint16_t  mcu_w = JpegDec.MCUWidth;
  3794.     uint16_t  mcu_h = JpegDec.MCUHeight;
  3795.     uint32_t  max_x = JpegDec.width;
  3796.     uint32_t  max_y = JpegDec.height;
  3797.  
  3798.     // --------------------------------------------------------------------------------------------- //
  3799.     //   Jpeg images are draw as a set of image block (tiles) called Minimum Coding Units (MCUs)     //
  3800.     //   Typically these MCUs are 16x16 pixel blocks                                                 //
  3801.     //   Determine the width and height of the right and bottom edge image blocks                    //
  3802.     // --------------------------------------------------------------------------------------------- //
  3803.     //   Obrazy JPEG są rysowane jako zestaw bloków obrazu (kafelków) zwanych (MCU)                  //
  3804.     //   zazwyczaj te MCU są blokami 16x16 pikseli                                                   //
  3805.     //   Określ szerokość i wysokość bloków obrazu prawej i dolnej krawędzi                          //
  3806.     // --------------------------------------------------------------------------------------------- //
  3807.  
  3808.     uint32_t min_w = minimum(mcu_w, max_x % mcu_w);
  3809.     uint32_t min_h = minimum(mcu_h, max_y % mcu_h);
  3810.  
  3811.     // --------------------------------------------------------------------------------------------- //
  3812.     //   save the current image block size                                                           //
  3813.     // --------------------------------------------------------------------------------------------- //
  3814.     //   zapisz aktualny rozmiar bloku obrazu                                                        //
  3815.     // --------------------------------------------------------------------------------------------- //
  3816.    
  3817.     uint32_t win_w = mcu_w;
  3818.     uint32_t win_h = mcu_h;
  3819.  
  3820.     // --------------------------------------------------------------------------------------------- //
  3821.     //   record the current time so we can measure how long it takes to draw an image                //
  3822.     // --------------------------------------------------------------------------------------------- //
  3823.     //   rejestruj aktualny czas, abyśmy mogli zmierzyć, ile czasu zajmuje narysowanie obrazu        //
  3824.     // --------------------------------------------------------------------------------------------- //
  3825.    
  3826.     uint32_t drawTime = millis();
  3827.  
  3828.     // --------------------------------------------------------------------------------------------- //
  3829.     //   save the coordinate of the right and bottom edges to assist image cropping                  //
  3830.     //   to the screen size                                                                          //
  3831.     // --------------------------------------------------------------------------------------------- //
  3832.     //   zapisz współrzędne prawej i dolnej krawędzi, aby ułatwić przycinanie obrazu                 //
  3833.     //   do rozmiaru ekranu                                                                          //
  3834.     // --------------------------------------------------------------------------------------------- //
  3835.    
  3836.     max_x += xpos;
  3837.     max_y += ypos;
  3838.  
  3839.     // read each MCU block until there are no more
  3840.  
  3841.     #ifdef USE_SPI_BUFFER
  3842.           while ( JpegDec.readSwappedBytes()) {
  3843.     #else
  3844.           while ( JpegDec.read()) {
  3845.     #endif
  3846.    
  3847.     pImg = JpegDec.pImage;    
  3848.     int mcu_x = JpegDec.MCUx * mcu_w + xpos;
  3849.     int mcu_y = JpegDec.MCUy * mcu_h + ypos;
  3850.  
  3851.     if ( mcu_y < tft.height() )
  3852.     {
  3853.         if (mcu_x + mcu_w <= max_x) win_w = mcu_w;
  3854.         else win_w = min_w;
  3855.  
  3856.         if (mcu_y + mcu_h <= max_y) win_h = mcu_h;
  3857.         else win_h = min_h;
  3858.  
  3859.         if (win_w != mcu_w)
  3860.         {
  3861.             for (int h = 1; h < win_h; h++)
  3862.             {
  3863.                 memcpy(pImg + h * win_w, pImg + h * mcu_w, win_w << 1);
  3864.             }
  3865.         }
  3866.      
  3867.         tft.pushImage(mcu_x, mcu_y, win_w, win_h, pImg);
  3868.     }
  3869.     else
  3870.     {
  3871.         JpegDec.abort();
  3872.     }
  3873.     } // else makro
  3874.  
  3875.     drawTime = millis() - drawTime; // Calculate the time it took
  3876.  
  3877.    
  3878.     #if SERIAL
  3879.         #if ENGLISH
  3880.             PRINT(F("\n====================================================================="));
  3881.             PRINT(F("\n[JPEG DECODER] [INFO] Total render time was    : %d ms"), drawTime);            
  3882.         #endif
  3883.         #if POLISH
  3884.             PRINT(F("\n====================================================================="));
  3885.             PRINT(F("\n[JPEG DECODER] [INFO] Całkowity czas renderowania wynosił    : %d ms"), drawTime);            
  3886.         #endif
  3887.     #endif
  3888. }
  3889.  
  3890. // ------------------------------------------------------------------------------------------------------------ //
  3891. // --- Print information decoded from the Jpeg image ---------------------------------------------------------- //
  3892. // ------------------------------------------------------------------------------------------------------------ //
  3893. // --- Wydrukuj informacje odkodowane z obrazu JPEG ----------------------------------------------------------- //
  3894. // ------------------------------------------------------------------------------------------------------------ //
  3895.  
  3896. void jpegInfo()
  3897. {
  3898.     #if SERIAL
  3899.         PRINT(F("\n====================================================================="));
  3900.         PRINT(F("\n[JPEG DECODER] [JPEG image info]"));
  3901.         PRINT(F("\n====================================================================="));
  3902.         PRINT(F("\nWidth      : %d"),JpegDec.width);
  3903.         PRINT(F("\nHeight     : %d"),JpegDec.height);
  3904.         PRINT(F("\nComponents : %d"),JpegDec.comps);
  3905.         PRINT(F("\nMCU / row  : %d"),JpegDec.MCUSPerRow);
  3906.         PRINT(F("\nMCU / col  : %d"),JpegDec.MCUSPerCol);
  3907.         PRINT(F("\nScan type  : %d"),JpegDec.scanType);
  3908.         PRINT(F("\nMCU width  : %d"),JpegDec.MCUWidth);
  3909.         PRINT(F("\nMCU height : %d"),JpegDec.MCUHeight);        
  3910.     #endif  
  3911. }
  3912.  
  3913. // ------------------------------------------------------------------------------------------------------------ //
  3914. // --- Open a Jpeg file and send it to the Serial port in a C array compatible format ------------------------- //
  3915. // ------------------------------------------------------------------------------------------------------------ //
  3916. // --- Otwórz plik JPEG i wyślij go do portu szeregowego w formacie zgodnym z tablicą C ----------------------- //
  3917. // ------------------------------------------------------------------------------------------------------------ //
  3918.  
  3919. void createArray(const char *filename)
  3920. {
  3921.     #if SERIAL
  3922.         Serial.printf("\n=====================================================================");
  3923.         Serial.printf("\n[JPEG DECODER] [JPEG ARRAY ENCODER] jpeg to array     ");
  3924.         Serial.printf("\n=====================================================================");
  3925.         fs::File jpgFile = SPIFFS.open( filename, "r");    // File handle reference for SPIFFS
  3926.         //  File jpgFile = SD.open( filename, FILE_READ);  // or, file handle reference for SD library
  3927.  
  3928.         if ( !jpgFile )
  3929.         {
  3930.             Serial.print("ERROR: File \""); Serial.print(filename); Serial.println ("\" not found!");
  3931.             return;
  3932.         }
  3933.  
  3934.         uint8_t data;
  3935.         byte line_len = 0;
  3936.  
  3937.         while (*filename != '.') Serial.print(*filename++);
  3938.    
  3939.         Serial.println("[] PROGMEM = {"); // PROGMEM added for AVR processors, it is ignored by Due
  3940.  
  3941.         while ( jpgFile.available())
  3942.         {
  3943.             data = jpgFile.read();
  3944.             line_len++;
  3945.    
  3946.             if ( line_len >= 32)   line_len = 0;                  
  3947.         }
  3948.  
  3949.         Serial.println("};\r\n");
  3950.         jpgFile.close();
  3951.     #endif
  3952. }
  3953.  
  3954. // ------------------------------------------------------------------------------------------------------------ //
  3955. // --- GET NAMEDAY --- POBIERZ kto obchodzi dziś imieniny ----------------------------------------------------- //
  3956. // ------------------------------------------------------------------------------------------------------------ //
  3957.  
  3958. String GetNameday(byte m, byte d)
  3959. {
  3960.     char   buf[100];
  3961.  
  3962.     switch(m)
  3963.     {
  3964.         case  1 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_STYCZEN[d])));  break;        
  3965.         case  2 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_LUTY[d]))); break;
  3966.         case  3 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_MARZEC[d]))); break;
  3967.         case  4 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_KWIECIEN[d]))); break;
  3968.         case  5 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_MAJ[d]))); break;
  3969.         case  6 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_CZERWIEC[d]))); break;
  3970.         case  7 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_LIPIEC[d]))); break;
  3971.         case  8 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_SIERPIEN[d]))); break;
  3972.         case  9 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_WRZESIEN[d]))); break;
  3973.         case 10 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_PAZDZIERNIK[d]))); break;
  3974.         case 11 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_LISTOPAD[d]))); break;
  3975.         case 12 : strcpy_P(buf, (char*) pgm_read_dword(&(IMIENINY_GRUDZIEN[d]))); break;
  3976.         default : strcpy(buf, "ERROR"); break;
  3977.     }
  3978.  
  3979.     return(String(buf));
  3980. }
  3981.  
  3982. // ------------------------------------------------------------------------------------------------------------ //
  3983. // --- GET Event --- POBIERZ jakie dziś święto / wydarzenie --------------------------------------------------- //
  3984. // ------------------------------------------------------------------------------------------------------------ //
  3985.  
  3986. String GetEvent(byte m, byte d)
  3987. {
  3988.    char   buf[150];
  3989.  
  3990.     switch(m)
  3991.     {
  3992.         case  1 : strcpy_P(buf, (char*) pgm_read_dword(&(STYCZEN[d]))); break;
  3993.         case  2 : strcpy_P(buf, (char*) pgm_read_dword(&(LUTY[d]))); break;
  3994.         case  3 : strcpy_P(buf, (char*) pgm_read_dword(&(MARZEC[d]))); break;
  3995.         case  4 : strcpy_P(buf, (char*) pgm_read_dword(&(KWIECIEN[d]))); break;
  3996.         case  5 : strcpy_P(buf, (char*) pgm_read_dword(&(MAJ[d]))); break;
  3997.         case  6 : strcpy_P(buf, (char*) pgm_read_dword(&(CZERWIEC[d]))); break;
  3998.         case  7 : strcpy_P(buf, (char*) pgm_read_dword(&(LIPIEC[d]))); break;
  3999.         case  8 : strcpy_P(buf, (char*) pgm_read_dword(&(SIERPIEN[d]))); break;
  4000.         case  9 : strcpy_P(buf, (char*) pgm_read_dword(&(WRZESIEN[d]))); break;
  4001.         case 10 : strcpy_P(buf, (char*) pgm_read_dword(&(PAZDZIERNIK[d]))); break;
  4002.         case 11 : strcpy_P(buf, (char*) pgm_read_dword(&(LISTOPAD[d]))); break;
  4003.         case 12 : strcpy_P(buf, (char*) pgm_read_dword(&(GRUDZIEN[d]))); break;
  4004.         default : strcpy(buf,"ERROR");                              break;
  4005.     }
  4006.  
  4007.     return(String(buf));
  4008. }
  4009.  
  4010.  
  4011.  
  4012. // ------------------------------------------------------------------------------------------------------------ //
  4013. // --- GET Event --- POBIERZ jakie dziś święto / wydarzenie --------------------------------------------------- //
  4014. // ------------------------------------------------------------------------------------------------------------ //
  4015.  
  4016. String GetSuperMsg(byte m, byte d)
  4017. {
  4018.     String bufor = "ESP8266 Wiki Center";
  4019.  
  4020.     if (m==1)
  4021.     {
  4022.         switch (d)
  4023.         {
  4024.             case   1  :   bufor = "Happy New Year";             break;
  4025.             default   :   bufor = "Sweet Home";                 break;
  4026.         }
  4027.     }
  4028.     else
  4029.     if (m==2)
  4030.     {
  4031.         switch (d)
  4032.         {
  4033.             default   :   bufor = "Sweet Home";                 break;
  4034.         }
  4035.     }
  4036.     else
  4037.     if (m==3)
  4038.     {
  4039.         switch (d)
  4040.         {
  4041.             default   :   bufor = "Sweet Home";                 break;
  4042.         }
  4043.     }
  4044.     else
  4045.     if (m==4)
  4046.     {
  4047.         switch (d)
  4048.         {
  4049.             default   :   bufor = "Sweet Home";                 break;
  4050.         }      
  4051.     }
  4052.     else
  4053.     if (m==5)
  4054.     {
  4055.         switch (d)
  4056.         {
  4057.             case  16  :   bufor = "Tomek's birthday";           break;
  4058.             default   :   bufor = "Sweet Home";                 break;
  4059.         }
  4060.     }
  4061.     else
  4062.     if (m==6)
  4063.     {
  4064.         switch (d)
  4065.         {
  4066.             default   :   bufor = "Sweet Home";                 break;
  4067.         }  
  4068.     }
  4069.     else
  4070.     if (m==7)
  4071.     {
  4072.         switch (d)
  4073.         {
  4074.             default   :   bufor = "Sweet Home";                 break;
  4075.         }  
  4076.     }
  4077.     else
  4078.     if (m==8)
  4079.     {
  4080.         switch (d)
  4081.         {
  4082.             default   :   bufor = "Sweet Home";                         break;
  4083.         }  
  4084.     }
  4085.     else
  4086.     if (m==9)
  4087.     {
  4088.         switch (d)
  4089.         {
  4090.             case  1   :   bufor = "Festival of Knowledge";      break;
  4091.             case  3   :   bufor = "Viking 2 on Mars";           break;
  4092.             case  14  :   bufor = "Gravitational Waves";        break;
  4093.             case  15  :   bufor = "Albatros is flying";         break;
  4094.             case  16  :   bufor = "PZL M-20 Mewa flying";       break;
  4095.             case  17  :   bufor = "Soyuz T-14 launch";          break;
  4096.             default   :   bufor = "ESP8266 Wiki Center";        break;
  4097.         }
  4098.     }
  4099.     else
  4100.     if (m==10)
  4101.     {
  4102.         switch (d)
  4103.         {
  4104.             case  7   :   bufor = "Marcin's birthday";                  break;
  4105.             default   :   bufor = "Sweet Home";                         break;
  4106.         }
  4107.     }
  4108.     else
  4109.     if (m==11)
  4110.     {
  4111.         switch (d)
  4112.         {
  4113.             case  3   :   bufor = "Sylwia's birthday";                  break;
  4114.             default   :   bufor = "Sweet Home";                         break;
  4115.         }  
  4116.     }
  4117.     else
  4118.     if (m==12)
  4119.     {
  4120.         switch (d)
  4121.         {
  4122.             default   :   bufor = "Sweet Home";                         break;
  4123.         }  
  4124.     }
  4125.    
  4126.  
  4127.     return bufor;
  4128. }
  4129. //---- END----------------//
  4130.  
Add Comment
Please, Sign In to add comment