Hi, I have a request, I want to ask you for some functional project-dial where the current weather is from an openweather map provider. don't answer if you don't want to help me. I'm starting to link IQ with programming ... Thanks
Hi, I have a request, I want to ask you for some functional project-dial where the current weather is from an openweather map provider. don't answer if you don't want to help me. I'm starting to link IQ with programming ... Thanks
You've PM'd me code that looks like it should work, but I think you're not understanding now this works. On a watchface, you get the weather by way of a background process, and the code you sent needs to run as a background service. Which means you need things like registerForTemporal events and getServiceDelegate in your main code.
Here's a whole thread with an example (look at the end of the thread) that shows how backgrounding works. Look at the sample and run it in the sim to understand how backgrounding works.
In the vsbgwf sample I posted in that read, replace whats in the bgb.mc with what's here. (put in your own APIKEY)
The lat/lon are hard coded to be near Garmin..
using Toybox.Background; using Toybox.System as Sys; using Toybox.Communications as Comm; // The Service Delegate is the main entry point for background processes // our onTemporalEvent() method will get run each time our periodic event // is triggered by the system. (:background) class BgbgServiceDelegate extends Toybox.System.ServiceDelegate { var APIKEY="(your key here)"; var lat=38.8551; var lon=-94.8001; function initialize() { Sys.ServiceDelegate.initialize(); inBackground=true; } function onTemporalEvent() { var UNITS=(Sys.getDeviceSettings().temperatureUnits==Sys.UNIT_STATUTE) ? "imperial" : "metric"; var url="https://api.openweathermap.org/data/2.5/weather"; var param={ "lat" => lat.toFloat(), "lon"=>lon.toFloat(), "appid"=>APIKEY, "units" => UNITS}; var options = { :methods => Comm.HTTP_REQUEST_METHOD_GET, :headers => {"Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED}, :responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_JSON }; Comm.makeWebRequest( url, param, options, method(:receiveWeather)); } function receiveWeather(responseCode,data) { var ret=(responseCode==200) ? data :responseCode; Background.exit(ret); } }
These projects all appear to access the weather in the background:
/warmsound/crystal-face
/jpg63/crystal-face-jpg63
/ankineri/gweatherwatch
/Peterdedecker/kudos
/fabrikant/LowEnergyFace
/voseldop/timeless
/valgit/WeatherApp
/Laverlin/Yet-Another-WatchFace
They're all on github, but I didn't want to make them links as my reply will probably be flagged.