OpenWeatherMap onecall - api

Hi,

I am trying to use https://api.openweathermap.org/data/2.5/onecall api to display some info, but even if I am using "exclude"=>"minutely,hourly,daily,alerts" seems to be very heavy sometimes.

No all call are working and the info is not refreshed.

Do you have some suggestions using OneCall from OpenWeatherMap to retrieve correct info?

Thanks

  • Hi mate,

    Yes, even if you use exclude, the datas received are very heavy (see http traffic in the sim) and you get error 403: data received but not enough ressources to deal with, you have to make your background code as light as possible and it will work. 

  • I use

    var url="https://api.openweathermap.org/data/2.5/weather";

    and not onecall.  In looking at onecall, it does look that the amount of data can be large as well as variable in size, making it hard to test in a background service, considering the memory for a background service also varies by target device. And to really test, looks like an "alert" needs to be in effect.

    It might be easier to get the current weather and forecast in two different calls - current at 5,15.25 minutes, forecast at 10,20,30 etc.

    if the forcast only changes say every hour, no need yo get it more often.

  • This is only thing that I am doing in the background

  • I am trying to retrieve UVI value, and this can be done only using onecall

  • I mean the code you use to do this, it has to be refracted etc. 

  • You have very limited memory in a background service.  And what you see coming back as json data needs to be converted into a dictionary, which means a bunch more memory is used when the conversion happens than it might appear

    Use Sys.getDeviceStats() to usee used, available and total memory in your background. 

    On some devices, the background can be at most 28k, and that includes your background code, it's data, as well as other bits like your AppBase class.

  • You can build your own proxy so that all that actually gets passed on to the watch is the UV value.  With something like Azure you'll probably never get to the level of traffic where you have to pay.

  • I use One Call API in my Alfa-Zulu watchface.
    I had to remove forecast some weeks ago, because openweathermap added some data to "daily", which made the response way too big.

    However it is working now. I also "uglyfied" the whole code to lower memory usage of watchface.

    This is my code (excerpt):

    (:background_method)
    function onTemporalEvent() {
        var location = app.getProperty("loc");
        var owmAPIKey = app.getProperty("owmAPIKey");
    
        makeWebRequest (
            "https://api.openweathermap.org/data/2.5/onecall",
            {
                "lat" => location[0],
                "lon" => location[1],
                "appid" => owmAPIKey,
                "exclude" => "minutely,hourly,daily,alerts",
                "units" => "metric"
            },
            method(:onReceiveOwm)
        );
    }

    (:background_method)
    function onReceiveOwm(responseCode, data) {
        var result = {};
    
            result = {
                "dt" =>                  data["current"]["dt"],
                "temperature" =>         data["current"]["temp"],
                "pressure" =>            data["current"]["pressure"],
                "humidity" =>            data["current"]["humidity"],
                "uvi" =>                 data["current"]["uvi"],
                "windSpeed" =>           data["current"]["wind_speed"],
                "windDeg" =>             data["current"]["wind_deg"],
                "icon" =>                data["current"]["weather"][0]["icon"],
                "description" =>         data["current"]["weather"][0]["description"],
                "clouds" =>              data["current"]["clouds"],
                "dew_point" =>           data["current"]["dew_point"],
                "error" =>               responseCode
            };
    
        Background.exit({"openWeatherMap" => result});
    }

  • I suceeded to get also daily but for exemple to save ressources I used array and not dictionnary, and made the app base lighter 

  • Hi,

    This is the code used by me and it seems that is not working all the time:

     function receiveWeather(responseCode,data) 
        {
        	var result = null;
      		
        	if(responseCode==200)
        	{
        		result = [data["current"]["temp"], data["current"]["weather"][0]["icon"], data["current"]["uvi"]];
        	}
        	
    		Background.exit(result);
    	}

    function onTemporalEvent() 
        {
        	if(Application.getApp().getProperty("WeatherApi") != null && Application.getApp().getProperty("a") != null && Application.getApp().getProperty("b") != null)
        	{
       	    	Comm.makeWebRequest
    			(
    	    	   	"https://api.openweathermap.org/data/2.5/onecall",
    	    	   	{
    	    			"lat" =>Application.getApp().getProperty("a").toFloat(),
    	    			"lon"=>Application.getApp().getProperty("b").toFloat(),
    	    			"exclude"=>"minutely,hourly,daily,alerts",
    	    			"appid"=>Application.getApp().getProperty("WeatherApi"),
    	    			"units" => (Sys.getDeviceSettings().temperatureUnits==Sys.UNIT_STATUTE) ? "imperial" : "metric"},
    	    	   	{
    					:methods => Comm.HTTP_REQUEST_METHOD_GET,
    					:headers => {"Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED},
    					:responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_JSON
    				},
    	    	   	method(:receiveWeather)
    	    	);
    		}
        }