OpenWeatherMap API codes

yo2ldk
Offline
Зарегистрирован: 10.11.2017

  Hello dear friends,



  please help me with any tips or advice's in my project;



if I have on Arduino weather code to see on display parameters of humidity from openweathermap.org and that is ok with correct value on screen

 

humidity = root["main"]["humidity"];

pressure = root["main"]["pressure"];

But for sunrise and sunset on local city, value is always 0.00
I try it all variants, but nothing
  
 sunrise = root["sun"];
  sunset = root["set"];

  sunrise = root["city"]["sun"]["rise"];
  sunset = root["city"]["sun"]["set"]; 

  
  sunrise = root["sun"]["rise"];
  sunset = root["sun"]["set"]; 
as I can see, the path is not correct, please correct me in this
info here: https://openweathermap.org/current

 best regards,

                                 alexander

  

 

negavoid
Offline
Зарегистрирован: 09.07.2016
unsigned long sunrise = root["sys"]["sunrise"];
unsigned long sunset  = root["sys"]["sunset"];

 

yo2ldk
Offline
Зарегистрирован: 10.11.2017

[quote = negavoid]

unsigned long sunrise = root ["sys"] ["sunrise"];
unsigned long sunset = root ["sys"] ["sunset"];

 

[/ quote]

 

Negavoid, Thank you for your time and good advice, it's work very well, but i did it that before; this display the UTC time for sun event, and I need for local time.
on weathermap is instructions for that city.sun.set, where city is selected before by code in my case 

 

String cityID = "668954";

here is instructions:


 can be used this for local time sunrise and sunset?

 

negavoid
Offline
Зарегистрирован: 09.07.2016

If you wish to get local time from the UTC one, just add or subtract the corresponding amount of seconds. For example,

unsigned long sunrise_local = sunrise + ( 3600 * 2 );

To get the local times from ow api:

unsigned long city_sunrise = root["city"]["sun"]["rise"];

Check also if there are real values set and exists in json/xml api reply, when you see zero values as parsing result.

yo2ldk
Offline
Зарегистрирован: 10.11.2017

it seems that  root["city"]["sun"]["rise"] not give any info
better way to find how to convert Unix value provided by 

unsigned long sunrise = root ["sys"] ["sunrise"];

that give  "sunrise": 1560343627,  "sunset": 1560396563

in normal time like 08.10.00AM for example, but maybe I give up..

negavoid
Offline
Зарегистрирован: 09.07.2016
#include <TimeLib.h>

unsigned long t = root["sys"]["sunrise"];

char buff[32];
sprintf(buff, "%02d.%02d.%02d %02d:%02d:%02d", day(t), month(t), year(t), hour(t), minute(t), second(t));

Serial.println(buff);