Advertisement
PowerTGS440

ESP Weather Station

Feb 19th, 2021 (edited)
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 47.53 KB | None | 0 0
  1. // ESP Weather Station v0.1 Beta (DEMO for YOU) Multilanguage: EN / PL (switch LANGUAGE to 1 if EN    //
  2. // this is free demo, no more update !!!
  3. //
  4. // powerTGS440@gmail.com
  5. //
  6. // -------------------------------------------------------------------------------------------------- //
  7. #include <WiFi.h>                                                                                     //
  8. #include <NTPClient.h>                                                                                //
  9. #include <WiFiUdp.h>                                                                                  //
  10. #include <HTTPClient.h>                                                                               //
  11. #include <WiFiClient.h>                                                                               //
  12. #include <Arduino_JSON.h>                                                                             //
  13. #include <TimeLib.h>                                                                                  //
  14. // -------------------------------------------------------------------------------------------------- //
  15. //
  16. //
  17. //
  18. // -------------------------------------------------------------------------------------------------- //    <--- D E B U G E R
  19. // ---    D E F I N E   -   T E R M I N A L   -   S E R I A L   D E B U G                         --- //
  20. // -------------------------------------------------------------------------------------------------- //
  21.                                                                                                       //
  22. #define TERMINAL 1                                        // 0 - wyłącz SERIAL, 1 - włącz SERIAL ---- //
  23. #define DEBUG 0                                           // Full Function Debugger              ---- //
  24.                                                                                                       //
  25. // -------------------------------------------------------------------------------------------------- //
  26. // --- D E F I N E  -  L A N G U A G E  -  P O L I S H   0  -  E N G L I S H   1                  --- //
  27. // -------------------------------------------------------------------------------------------------- //   <--- L A N G U A G E
  28.                                                    //                                             --- //
  29. #define LANGUAGE 0                                 // jeśli LANGUAGE jest zdefiniowane jako 0     --- //
  30.                                                    // to kolejne warunki dla makra przestawiają   --- //
  31. #if LANGUAGE                                       // język ma Polski                             --- //
  32.                                                                                                       //
  33.   #define POLISH 0                                 //                                                 //
  34.   #define ENGLISH 1                                // jeśli LANGUAGE jest zdefiniowane jako 1     --- //
  35.                                                                                                       //
  36. #else                                              // to kolejne warunki dla makra przestawiają   --- //
  37.                                                                                                       //
  38.   #define POLISH 1                                 // język na angielski (jak wyżej)              --- //
  39.   #define ENGLISH 0                                //                                                 //
  40.                                                                                                       //
  41. #endif                                             //   M U L T I   L A N G U A G E   P R O J E C T   //
  42.                                                    //                                                 //
  43. // -------------------------------------------------------------------------------------------------- //
  44. // --- O B J E C T   -   W I F I   &   N T P                                                          //
  45. // -------------------------------------------------------------------------------------------------- //    <--- W I F I
  46.                                                                                                       //  
  47. WiFiUDP ntpUDP;                                                 // ntp dla Time / Date Serwer     --- //
  48. NTPClient timeClient(ntpUDP, "pool.ntp.org", 3600);                                                   //
  49.                                                                                                       //
  50. // -------------------------------------------------------------------------------------------------- //    <--- V A R I A B L E S
  51. // --- O T H E R   V A R I A B L E   &   C O N S T                                                --- //
  52. // -------------------------------------------------------------------------------------------------- //
  53.                                                                                                       //                                                                                                      
  54. const char *ssid     = "NazwaWIFI";                                    // network wifi ssid       --- //
  55. const char *password = "TwojeHaslo";                                   // network wifi password   --- //
  56. String openWeatherMapApiKey = "565a88311e7c48c2d00b170cd0765c91";      // token for openWeather   --- //
  57. String city = "Legnica";                                               // city for weather        --- //
  58. String countryCode = "Pl";                                             // country for weather     --- //
  59. String jsonBuffer;                                                     // buffer - bufor          --- //
  60.                                                                                                       //
  61. // -------------------------------------------------------------------------------------------------- //    <--- S T R U C T   D A T E & T I M E
  62. // S T R U K T U R A   C Z A S   /   T I M E   S T R U C T U R E                                  --- //
  63. // -------------------------------------------------------------------------------------------------- //
  64. struct datatime                                                                                       //
  65. {                                                                                                     //
  66.     String SformatowanaData;                                           // formated data ------------- //
  67.     int    DzienTygodnia;                                              // day of week --------------- //
  68.     int    DzienMiesiaca;                                              // day of month -------------- //
  69.     int    Miesiac;                                                    // month --------------------- //
  70.     int    Rok;                                                        // year ---------------------- //
  71.     String SformatowanyCzas;                                           // formated time ------------- //
  72.     int    Godzina;                                                    // hour ---------------------- //
  73.     int    Minuta;                                                     // minute -------------------- //
  74.     int    Sekunda;                                                    // seconds ------------------- //
  75.     char   wschod_slonca[10];                                          // sunrise ------------------- //
  76.     char   zachod_slonca[10];                                          // sunset -------------------- //
  77. } czas;                                                                // time object --------------- //
  78.                                                                                                       //
  79. // -------------------------------------------------------------------------------------------------- //    <--- S T R U C T   W E A T H E R
  80. // S T R U K T U R A   P O G O D A                                                                --- //
  81. // -------------------------------------------------------------------------------------------------- //
  82. struct weather                                                                                        //
  83. {                                                                                                     //
  84.     double temperatura;                                                // temperature / temperatura - //
  85.     double temperatura_minimalna;                                      // min. temp ----------------- //
  86.     double temperatura_maksymalna;                                     // max. temp ----------------- //  
  87.     double temperatura_odczuwalna;                                     // feels temp ---------------- //
  88.     int cisnienie;                                                     // cisnienie powietrza ------- //
  89.     int wilgotnosc;                                                    // wilgotnosc powietrza ------ //
  90.     int wiatr;                                                         // wiatr / wind speed -------- //
  91.     int zachmurzenie;                                                  // zachmurzenie / cloudys ---- //
  92.     long widzialnosc;                                                  // widzialnosc / visible ----- //
  93. } pogoda;                                                              // weather object ------------ //
  94.                                                                                                       //
  95. // -------------------------------------------------------------------------------------------------- //   <--- S E T U P
  96. // --- S E T U P     M A I N   S E C T I O N                                                      --- //
  97. // -------------------------------------------------------------------------------------------------- //                                                                                                      //
  98.                                                                                                       //
  99. void setup()                                                                                          //
  100. {                                                                                                     //
  101.     #if TERMINAL                                                                                      //
  102.         Serial.begin(57600);                                           // set speed USB          ---- //
  103.     #endif                                                                                            //
  104.                                                                                                       //
  105.                                                                                                       //
  106.     WiFi.begin(ssid, password);                                        // WiFi start connection ----- //
  107.                                                                                                       //
  108.     delay(2000);                                                                                      //
  109.                                                                                                       //
  110.     while ( WiFi.status() != WL_CONNECTED )                            // czekaj na połączenie  ----- //   <--- WiFi Connected
  111.     {                                                                  // wait for connect      ----- //
  112.         delay ( 200 );                                                 // safe mode             ----- //    
  113.         Serial.print ( "." );                                          // print dot / drukuj .  ----- //            
  114.     }                                                                                                 //
  115.                                                                                                       //
  116.     #if TERMINAL                                                                                      //
  117.                                                                                                       //
  118.         #if POLISH                                                                                    //
  119.             Serial.printf("\nPOLACZONO z WiFi : %s\n", ssid);                                         //
  120.             Serial.printf("-------------------------------------\n");                                 //
  121.             Serial.printf("ESP Wolna Pamięć RAM : %u [kB]\n", ESP.getFreeHeap());                     //
  122.             Serial.printf("ESP Zegar procesora  : %u [MHz]\n", ESP.getCpuFreqMHz());                  //
  123.         #else                                                                                         //      
  124.             Serial.printf("\nCONNECT to WiFi : %s\n", ssid);                                          //
  125.             Serial.printf("-------------------------------------\n");                                 //
  126.             Serial.printf("ESP Memory Free   : %u [kB]\n",ESP.getFreeHeap());                         //
  127.             Serial.printf("ESP CPU frequency : %u [MHz]\n",ESP.getCpuFreqMHz());                      //
  128.         #endif                                                                                        //                                                                                                      
  129.                                                                                                       //
  130.     #endif                                                                                            //
  131.                                                                                                       //
  132.     WiFiUDP ntpUDP;                                                     // ntp client             --- //
  133.     NTPClient timeClient(ntpUDP, "pool.ntp.org", 3600);                 // ntp server             --- //
  134.                                                                                                       //
  135.     TimeUpdate();                                                       // update time from ntp   --- //   <--- Update TIME  
  136.     DateUpdate();                                                       // update date from ntp   --- //   <--- Update DATE
  137.     WeatherUpdate();                                                    // update weather from om --- //   <--- Update WEATHER
  138.                                                                                                       //
  139.     #if TERMINAL                                                                                      //
  140.                                                                                                       //
  141.         DateUpdateShow();                                               // show Update Date       --- //   <--- only if TERMINAL true
  142.         TimeUpdateShow();                                               // show Update Time       --- //   <--- jeśli TERMINAL jest 1
  143.         WeatherUpdateShow();                                            // show Update Weather    --- //
  144.                                                                                                       //
  145.     #endif                                                                                            //
  146. }                                                                                                     //
  147. // --- END SETUP ------------------------------------------------------------------------------------ //   <--- S E T U P   E N D
  148. //
  149. //
  150. //
  151. //
  152. //
  153. //
  154. //
  155. //
  156. // -------------------------------------------------------------------------------------------------- //
  157. // --- L O O P                                                                                    --- //    <--- L O O P   S T A R T   H E R E
  158. // -------------------------------------------------------------------------------------------------- //
  159.  
  160. void loop()
  161. {
  162.    
  163.     delay(1000);
  164.  
  165. }
  166.  
  167. // -------------------------------------------------------------------------------------------------- //
  168. // --- D A T E   P R I N T   T O   S E R I A L                                                    --- //   <--- DATE SHOW 2 SERIAL
  169. // -------------------------------------------------------------------------------------------------- //
  170.                                                                                                       //
  171. void DateUpdateShow()                                                                                 //
  172. {                                                                                                     //
  173.     #if TERMINAL                                                                                      //
  174.                                                                                                       //
  175.         #if POLISH                                                                                    //   <--- Raport po Polsku
  176.             Serial.printf("\n----------- NTP RAPORT --- DATA --------------------\n");                //
  177.             Serial.printf("Dzień tygodnia   : %d \n", czas.DzienTygodnia);                            //
  178.             Serial.printf("Dzień miesiąca   : %d \n", czas.DzienMiesiaca);                            //
  179.             Serial.printf("Miesiąc          : %d \n", czas.Miesiac);                                  //
  180.             Serial.printf("Rok              : %d", czas.Rok);                                         //
  181.         #endif                                                                                        //
  182.                                                                                                       //
  183.         #if ENGLISH                                                                                   //   <--- English Raport
  184.             Serial.printf("\n----------- NTP RAPORT --- DATE --------------------\n");                //
  185.             Serial.printf("Day of week      : %d \n", czas.DzienTygodnia);                            //
  186.             Serial.printf("Day number       : %d \n", czas.DzienMiesiaca);                            //
  187.             Serial.printf("Month number     : %d \n", czas.Miesiac);                                  //
  188.             Serial.printf("Year             : %d", czas.Rok);                                         //
  189.         #endif                                                                                        //
  190.                                                                                                       //
  191.     #endif                                                                                            //
  192. }                                                                                                     //
  193.                                                                                                       //
  194. // -------------------------------------------------------------------------------------------------- //
  195. // --- D A T A   U P D A T E                                                                      --- //
  196. // -------------------------------------------------------------------------------------------------- //
  197. // --- aktualizuj datę z serwera : pool.ntp.org ----------------------------------------------------- //   <--- aktualizacja daty z serwera NTP
  198. // -------------------------------------------------------------------------------------------------- //
  199. void DateUpdate()                                                                                     //
  200. {                                                                                                     //
  201.   timeClient.update();                                                                                //
  202.   unsigned long epochTime = timeClient.getEpochTime();                                                //
  203.   struct tm *ptm = gmtime ((time_t *)&epochTime);                                                     //
  204.                                                                                                       //
  205.   czas.SformatowanaData  =   timeClient.getFormattedTime();                                           //
  206.   czas.DzienTygodnia     =   timeClient.getDay();                                                     //
  207.   czas.DzienMiesiaca     =   ptm->tm_mday;                                                            //
  208.   czas.Miesiac           =   ptm->tm_mon+1;                                                           //
  209.   czas.Rok               =   ptm->tm_year+1900;                                                       //
  210.                                                                                                       //
  211.   #if DEBUG                                                                                           //
  212.       #if TERMINAL                                                                                    //
  213.           #if POLISH                                                                                  //
  214.               Serial.printf("\nPROJECT : zaktualizowano datę z serwera pool.ntp.org");                //
  215.           #else                                                                                       //
  216.               Serial.printf("\nPROJECT : update data from server pool.ntp.org");                      //
  217.           #endif                                                                                      //
  218.       #endif                                                                                          //
  219.   #endif                                                                                              //
  220. }                                                                                                     //
  221. // -------------------------------------------------------------------------------------------------- //
  222. // --- T I M E   P R I N T   T O   S E R I A L                                                    --- //   <---TIME SHOW 2 SERIAL
  223. // -------------------------------------------------------------------------------------------------- //
  224.                                                                                                       //
  225. void TimeUpdateShow()                                                                                 //
  226. {                                                                                                     //
  227.     #if TERMINAL                                                                                      //
  228.                                                                                                       //
  229.         #if POLISH                                                                                    //   <--- Raport po Polsku
  230.                                                                                                       //
  231.             Serial.printf("\n----------- NTP RAPORT --- CZAS --------------------\n");                //
  232.                                                                                                       //
  233.             if(czas.Godzina < 10)                                                                     //
  234.                 Serial.printf("Godzina          : 0%d \n", czas.Godzina);                             //
  235.             else                                                                                      //
  236.                 Serial.printf("Godzina          : %d \n", czas.Godzina);                              //
  237.                                                                                                       //
  238.             if(czas.Minuta < 10)                                                                      //
  239.                 Serial.printf("Minuta           : 0%d \n", czas.Minuta);                              //
  240.             else                                                                                      //
  241.                 Serial.printf("Minuta           : %d \n", czas.Minuta);                               //
  242.                                                                                                       //
  243.             if(czas.Sekunda < 10)                                                                     //
  244.                 Serial.printf("Sekunda          : 0%d", czas.Sekunda);                                //
  245.             else                                                                                      //
  246.                 Serial.printf("Sekunda          : %d", czas.Sekunda);                                 //
  247.         #endif                                                                                        //
  248.                                                                                                       //
  249.         #if ENGLISH                                                                                   //   <--- English Raport
  250.                                                                                                       //
  251.             Serial.printf("\n----------- NTP RAPORT --- TIME --------------------\n");                //
  252.                                                                                                       //
  253.             if(czas.Godzina < 10)                                                                     //
  254.                 Serial.printf("Hour             : 0%d \n", czas.Godzina);                             //
  255.             else                                                                                      //
  256.                 Serial.printf("Hour             : %d \n", czas.Godzina);                              //
  257.                                                                                                       //
  258.             if(czas.Minuta < 10)                                                                      //
  259.                 Serial.printf("Minute           : 0%d \n", czas.Minuta);                              //
  260.             else                                                                                      //
  261.                 Serial.printf("Minute           : %d \n", czas.Minuta);                               //
  262.                                                                                                       //
  263.             if(czas.Sekunda < 10)                                                                     //
  264.                 Serial.printf("Second           : 0%d", czas.Sekunda);                                //
  265.             else                                                                                      //
  266.                 Serial.printf("Second           : %d", czas.Sekunda);                                 //
  267.         #endif                                                                                        //
  268.                                                                                                       //
  269.     #endif                                                                                            //
  270. }                                                                                                     //
  271.                                                                                                       //
  272. // -------------------------------------------------------------------------------------------------- //
  273. // --- T I M E   U P D A T E                                                                      --- //
  274. // -------------------------------------------------------------------------------------------------- //
  275. // --- aktualizuj czas z serwera : pool.ntp.org ----------------------------------------------------- //   <--- aktualizacja czasu z serwera NTP
  276. // -------------------------------------------------------------------------------------------------- //
  277. void TimeUpdate()                                                                                     //
  278. {                                                                                                     //
  279.   timeClient.update();                                                                                //
  280.                                                                                                       //
  281.   czas.Godzina  =  timeClient.getHours();               // zapisz godzinę z serwera ----------------- //
  282.   czas.Minuta   =  timeClient.getMinutes();             // zapisz minutę z serwera ------------------ //
  283.   czas.Sekunda  =  timeClient.getSeconds();             // zapisz sekundę z serwera ----------------- //
  284.                                                                                                       //
  285.   #if DEBUG                                                                                           //
  286.       #if TERMINAL                                                                                    //
  287.           #if POLISH                                                                                  //
  288.               Serial.printf("\nPROJECT : zaktualizowano czas z serwera pool.ntp.org");                //
  289.           #else                                                                                       //
  290.               Serial.printf("\nPROJECT : update time from server pool.ntp.org");                      //
  291.           #endif                                                                                      //
  292.       #endif                                                                                          //
  293.   #endif                                                                                              //
  294. }                                                                                                     //
  295. // -------------------------------------------------------------------------------------------------- //
  296. // --- W E A T H E R   P R I N T   T O   S E R I A L                                              --- //   <--- WEATHER SHOW 2 SERIAL
  297. // -------------------------------------------------------------------------------------------------- //
  298.                                                                                                       //
  299. void WeatherUpdateShow()                                                                              //
  300. {                                                                                                     //
  301.     #if TERMINAL                                                                                      //
  302.                                                                                                       //
  303.         #if POLISH                                                                                    //   <--- Raport po Polsku
  304.             Serial.printf("\n----------- NTP RAPORT --- POGODA ------------------\n");                //
  305.             Serial.printf("Temperatura      : %.2f st.C\n", pogoda.temperatura);                      //
  306.             Serial.printf("Temp. Odczuwalna : %.2f st.C\n", pogoda.temperatura_odczuwalna);           //
  307.             Serial.printf("Temp. Minimalna  : %.2f st.C\n", pogoda.temperatura_minimalna);            //
  308.             Serial.printf("Temp. Maksymalna : %.2f st.C\n", pogoda.temperatura_maksymalna);           //
  309.             Serial.printf("Ćisnienie        : %d [ hPa ]\n", pogoda.cisnienie);                       //
  310.             Serial.printf("Wilgotność       : %d [ %% ]\n", pogoda.wilgotnosc);                       //
  311.             Serial.printf("Zachmurzenie     : %d [ %% ]\n", pogoda.zachmurzenie);                     //
  312.             Serial.printf("Prędkość wiatru  : %d [ km/h ]\n", pogoda.wiatr);                          //
  313.             Serial.printf("Widzialność      : %d [ m ]\n", pogoda.widzialnosc);                       //
  314.             Serial.printf("Wschód słońca    : %s\n", czas.wschod_slonca);                             //
  315.             Serial.printf("Zachód słóńca    : %s\n", czas.zachod_slonca);                             //
  316.             Serial.printf("----------------------------------------------------");                    //
  317.         #endif                                                                                        //
  318.                                                                                                       //
  319.         #if ENGLISH                                                                                   //   <--- English Raport
  320.             Serial.printf("\n----------- NTP RAPORT --- Weather ------------------\n");               //          
  321.             Serial.printf("Temperature      : %.2f st.C\n", pogoda.temperatura);                      //
  322.             Serial.printf("Temp. Feels      : %.2f st.C\n", pogoda.temperatura_odczuwalna);           //
  323.             Serial.printf("Temp. Min.       : %.2f st.C\n", pogoda.temperatura_minimalna);            //
  324.             Serial.printf("Temp. Max        : %.2f st.C\n", pogoda.temperatura_maksymalna);           //
  325.             Serial.printf("Pressure         : %d [ hPa ]\n", pogoda.cisnienie);                       //
  326.             Serial.printf("Humidity         : %d [ %% ]\n", pogoda.wilgotnosc);                       //
  327.             Serial.printf("Clouds           : %d [ %% ]\n", pogoda.zachmurzenie);                     //
  328.             Serial.printf("Wind speed       : %d [ km/h ]\n", pogoda.wiatr);                          //
  329.             Serial.printf("Visibility       : %d [ m ]\n", pogoda.widzialnosc);                       //
  330.             Serial.printf("Sunrise Time     : %s\n", czas.wschod_slonca);                             //
  331.             Serial.printf("Sunset Time      : %s\n", czas.zachod_slonca);                             //
  332.             Serial.printf("----------------------------------------------------");                    //
  333.         #endif                                                                                        //
  334.                                                                                                       //
  335.     #endif                                                                                            //
  336. }                                                                                                     //
  337.                                                                                                       //
  338. // -------------------------------------------------------------------------------------------------- //
  339. // --- W E A T H E R   U P D A T E                                                                --- //
  340. // -------------------------------------------------------------------------------------------------- //
  341. // --- aktualizuj pogode z serwera : openwearhermap.org --------------------------------------------- //   <--- aktualizacja pogody z serwera OPEN
  342. // -------------------------------------------------------------------------------------------------- //
  343. void WeatherUpdate()                                                                                  //
  344. {                                                                                                     //
  345.   if(WiFi.status()== WL_CONNECTED)                                                                    //
  346.   {                                                                                                   //
  347.       String serverPath = "http://api.openweathermap.org/data/2.5/weather?q=" + city + ","            //
  348.                            + countryCode + "&APPID=" + openWeatherMapApiKey;                          //
  349.                                                                                                       //
  350.       jsonBuffer = httpGETRequest(serverPath.c_str());                                                //
  351.                                                                                                       //
  352.       #if DEBUGER                                                                                     //
  353.           #if TERMINAL                                                                                //
  354.               Serial.println(jsonBuffer);             // DRUKUJE CAŁY NIESPARSOWY STRING z POGODA     //   <--- ALL WEATHER not PARSED
  355.           #endif                                                                                      //
  356.       #endif                                                                                          //
  357.                                                                                                       //
  358.       JSONVar myObject = JSON.parse(jsonBuffer);                                                      //
  359.                                                                                                       //
  360.       if (JSON.typeof(myObject) == "undefined")                                                       //
  361.       {                                                                                               //        
  362.         #if TERMINAL                                                                                  //
  363.             #if POLISH                                                                                //
  364.                 Serial.println("Bląd połączenia...");                                                 //
  365.             #else                                                                                     //
  366.                 Serial.println("Error connection...");                                                //
  367.             #endif                                                                                    //
  368.         #endif                                                                                        //
  369.                                                                                                       //
  370.         return;                                                                                       //
  371.       }                                                                                               //
  372.       // -------------------------------------------------------------------------------------------- //
  373.       // SHOW myObject                                                                                //
  374.                                                                                                       //
  375.       #if DEBUGER                                                                                     //
  376.           #if TERMINAL                                                                                //
  377.               Serial.println(myObject);                                                               //
  378.           #endif                                                                                      //
  379.       #endif                                                                                          //
  380.                                                                                                       //
  381.       // -------------------------------------------------------------------------------------------- //
  382.       // --- P R Z E T W A R Z A N I E   D A N Y C H   Z   S E R W E R A                          --- //   <--- PARSOWANIE danych z pogody
  383.       // -------------------------------------------------------------------------------------------- //   <--- PARSING WEATHER ONLY
  384.                                                                                                       //
  385.       double Kelvin = 273.15;                                                                         //
  386.                                                                                                       //
  387.       pogoda.temperatura = myObject["main"]["temp"];                 // pobieramy wartość do skruktury//
  388.       pogoda.temperatura -= Kelvin;                                  // odejmujemy wartość Kelvin --- //
  389.                                                                                                       //
  390.       pogoda.temperatura_odczuwalna = myObject["main"]["feels_like"];                                 //
  391.       pogoda.temperatura_odczuwalna -= Kelvin;                                                        //
  392.                                                                                                       //
  393.       pogoda.temperatura_minimalna = myObject["main"]["temp_min"];                                    //
  394.       pogoda.temperatura_minimalna -= Kelvin;                                                         //
  395.                                                                                                       //
  396.       pogoda.temperatura_maksymalna = myObject["main"]["temp_max"];                                   //
  397.       pogoda.temperatura_maksymalna -= Kelvin;                                                        //
  398.                                                                                                       //
  399.       pogoda.cisnienie = myObject["main"]["pressure"];                                                //
  400.                                                                                                       //
  401.       pogoda.wilgotnosc = myObject["main"]["humidity"];                                               //
  402.                                                                                                       //
  403.       pogoda.wiatr = myObject["wind"]["speed"];                                                       //
  404.                                                                                                       //
  405.       pogoda.zachmurzenie = myObject["clouds"]["all"];                                                //
  406.                                                                                                       //
  407.       pogoda.widzialnosc = myObject["visibility"];                                                    //
  408.                                                                                                       // ------------- //
  409.       // --- wykorzystana biblioteka TimeLib.h -----------                                                             //
  410.       sprintf(czas.wschod_slonca, "%02d:%02d",hour(myObject["sys"]["sunrise"]),minute(myObject["sys"]["sunrise"]));    //                                    
  411.                                                                                                                        //
  412.       // --- wykorzystana biblioteka TimeLib.h -----------                                                             //
  413.       sprintf(czas.zachod_slonca, "%02d:%02d",hour(myObject["sys"]["sunset"]),minute(myObject["sys"]["sunset"]));      //
  414.                                                                                                                        //
  415.                                                                                                       // ------------- //
  416.       #if DEBUG                                                                                       //
  417.           #if TERMINAL                                                                                //
  418.               #if POLISH                                                                              //
  419.                   Serial.printf("\nPROJECT : zaktualizowano pogodę z serwera openweathermap");        //
  420.               #else                                                                                   //
  421.                   Serial.printf("\nPROJECT : update weather from server openweathermap");             //
  422.               #endif                                                                                  //
  423.           #endif                                                                                      //
  424.       #endif                                                                                          //
  425.   }                                                                                                   //
  426. }                                                                                                     //
  427. // -------------------------------------------------------------------------------------------------- //
  428. // --- httpGET                                                                                    --- //   <--- http GET request
  429. // -------------------------------------------------------------------------------------------------- //
  430. String httpGETRequest(const char* serverName)                                                         //
  431. {                                                                                                     //
  432.     HTTPClient http;                                                                                  //
  433.     http.begin(serverName);                                                                           //
  434.     int httpResponseCode = http.GET();                                                                //
  435.     String bufor = "{}";                                                                              //
  436.                                                                                                       //
  437.     if ( httpResponseCode > 0 )                                                                       //
  438.     {                                                                                                 //      
  439.         #if DEBUG                                                                                     //
  440.             #if TERMINAL                                                                              //
  441.                 #if POLISH                                                                            //
  442.                     Serial.printf("\nHTTP - Kod odpowiedzi: %d\n", httpResponseCode);                 //
  443.                 #else                                                                                 //
  444.                     Serial.printf("\nHTTP - Response code: %d\n", httpResponseCode);                  //
  445.                 #endif                                                                                //
  446.             #endif                                                                                    //
  447.         #endif                                                                                        //
  448.                                                                                                       //
  449.         bufor = http.getString();                                                                     //
  450.     }                                                                                                 //
  451.     else                                                                                              //
  452.     {                                                                                                 //        
  453.         #if DEBUG                                                                                     //
  454.             #if TERMINAL                                                                              //
  455.                 #if POLISH                                                                            //
  456.                     Serial.printf("\nHTTP - Kod Błędu: %d\n", httpResponseCode);                      //
  457.                 #else                                                                                 //
  458.                     Serial.printf("\nHTTP - Error code: %d\n", httpResponseCode);                     //
  459.                 #endif                                                                                //
  460.             #endif                                                                                    //
  461.         #endif                                                                                        //
  462.     }                                                                                                 //
  463.                                                                                                       //
  464.     http.end();                                                                                       //
  465.     return bufor;                                                                                     //
  466. }                                                                                                     //
  467. // -------------------------------------------------------------------------------------------------- //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement