Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update code for arduinojson 6 #3

Open
AndreyVys opened this issue Mar 24, 2021 · 1 comment
Open

Update code for arduinojson 6 #3

AndreyVys opened this issue Mar 24, 2021 · 1 comment

Comments

@AndreyVys
Copy link

Function MakehttpRequest

if (httpCode == 200)  // Checking the returning code
    {
       String payload = http.getString();   // Getting the request response payload
       StaticJsonDocument<1024> doc;
       // Parse JSON object
       DeserializationError error = deserializeJson(doc, payload);
       if (error)
       {
       return;
       }
       else
       {
       
         JsonObject main = doc["main"];
         temp =        (float)main["temp"]-273.15;                      // Get temperature in °C
         humidity =    (uint_fast8_t)main["humidity"];                     // Get humidity in %
         pressure =    (uint_fast8_t)main["pressure"];            // Get pressure in bar
         visibility =  (float)doc["visibility"];         // Get visibility in m
         weatherCity = (const char*)doc["name"];

         JsonObject wind = doc["wind"];
         wind_speed =  (float)wind["speed"];                    // Get wind speed in m/s
         wind_degree = (float)wind["deg"];                     // Get wind degree in °

         JsonObject weather = doc["weather"][0];
         weatherDesc = (const char*)weather["description"];  
         weatherIcon = (const char*)weather["icon"];

         JsonObject sys = doc["sys"];
         sunrise = (time_t)sys["sunrise"];
         sunset = (time_t)sys["sunset"];
         weatherCountry = (const char*)sys["country"];
       }
@fermintm
Copy link

Forgiveness. Right now I can't check anything. I had a traffic accident

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants