misc/watchy-experimentation#2: Weather API Call returns wrong timezone

Issue Information

Issue Type: issue
Status: closed
Reported By: btasker
Assigned To: btasker

Created: 14-Jun-23 16:05


Watchy fetches time information from pool.ntp.org and then adjusts it for display using the timezone provided by the OpenWeather API

That adjustment is done here

It's not currently working correctly - my watch seems to think I'm in New York (or somewhere else 4 hours behind me).

Toggle State Changes


assigned to @btasker

We can reconstruct the call that'll be being made by using the api key from the settings file

Along with the way the url is constructed

url + cityID + String("&units=") + units +
                               String("&lang=") + lang + String("&appid=") +

So that should be (we'll fix the units later)

ben@optimus:~/tmp$ curl "http://api.openweathermap.org/data/2.5/weather?id=5128581&units=metric&lang=en&appid=f058fe1cad2afe8e2ddc5d063a64cecb"
{"coord":{"lon":-74.006,"lat":40.7143},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"base":"stations","main":{"temp":24.2,"feels_like":24.24,"temp_min":20.55,"temp_max":26.64,"pressure":1000,"humidity":60},"visibility":10000,"wind":{"speed":3.6,"deg":190},"clouds":{"all":0},"dt":1686759115,"sys":{"type":1,"id":4610,"country":"US","sunrise":1686734660,"sunset":1686788898},"timezone":-14400,"id":5128581,"name":"New York","cod":200}

So yeah, it puts me in the US (presumably because of the provision of that city id).

It looks like OpenWeather's API doesn't support geolocation (I'd assumed it did), you have to provide a City ID (deprecated) or lat+lon.

In the short-term, I can fix my watch's NTP reads by updating config.h to use the city ID for my location, but I'd actually quite like it to dynamically update depending on where I am (although I guess that would imply I'm reconfiguring it to connect to other Wifi's when out and about).

Could look at having it fetch timezone from http://ip-api.com/json/ instead.

For now, though, I'll just override the city ID

Updating settings.h to

#ifndef SETTINGS_H
#define SETTINGS_H

//Weather Settings
#define CITY_ID "2646057"
#define OPENWEATHERMAP_APIKEY "f058fe1cad2afe8e2ddc5d063a64cecb" //use your own API key :)
#define OPENWEATHERMAP_URL "http://api.openweathermap.org/data/2.5/weather?id=" //open weather api
#define TEMP_UNIT "metric" //metric = Celsius , imperial = Fahrenheit
#define TEMP_LANG "en"
#define WEATHER_UPDATE_INTERVAL 30 //must be greater than 5, measured in minutes
//NTP Settings
#define NTP_SERVER "pool.ntp.org"
#define GMT_OFFSET_SEC 3600 //New York is UTC -5 EST, -4 EDT, will be overwritten by weather data

watchySettings settings{
    .cityID = CITY_ID,
    .weatherUnit = TEMP_UNIT,
    .weatherLang = TEMP_LANG,
    .weatherUpdateInterval = WEATHER_UPDATE_INTERVAL,
    .ntpServer = NTP_SERVER,
    .gmtOffset = GMT_OFFSET_SEC,
    .vibrateOClock = true,


(Actually I swapped out my API key as well)

That worked, NTP sync gave me the correct time - score.

This is working correctly.

Although setting up geolocation would be cool, really it's not likely to get used much. The watch can only remember one Wifi network at a time (and is configured via a browser on another machine) so, realistically, I'm unlikely to configure it to join any other networks.

Worst case scenario, if I'm away for some reason, I'll just have to manually adjust the time on it or plan ahead and flash a new location onto it.

Closing this as done.