OWM onecall not working properly.

I'm trying to call the weather via api.openweathermap.org/.../onecall, but sometimes it doesn't work correctly.

For me it is temperature_min, temperature_max, rainfall.

Here they attach their code:

function makeForecastWeatherRequest() {
      var UNITS = (System.getDeviceSettings().temperatureUnits==System.UNIT_STATUTE) ? "imperial" : "metric";
			var url = "https://api.openweathermap.org/data/2.5/onecall";
	    	var param = {
	    		"lat" => lattitude,
	    		"lon" => longitude,
	    		"appid" =>"7xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
          //"lang" => lang == null ? "en" : lang,
           "exclude" => "current,minutely,hourly",
	    		"units" => UNITS};
			var options = {
				:methods => Communications.HTTP_REQUEST_METHOD_GET,
				:headers => {"Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED},
				:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
			};

      System.println("Forecast request "+ url);
   	
			Communications.makeWebRequest(
	    	   	url,
	    	   	param,
	    	   	options,
	    	   	method(:forecastWeatherCallback));
    
    }

Top Replies

All Replies

  • What isn't working? With the basic call, you can see the location it's reporting about, and during the day, I sometimes get one and at other times, the second one.  Something like that could be involved if you don't always see what you expect.

  • If you aren't seeing the data you think you should, contact OWM

  • I'd like to know if onecall still works for free, does anyone have a similar problem?

  • on my side, it seems to work well for "old" API but does not work for new API, a suscription is needed.

  • Old keys created before August 2022 works fine. 
    after that you need a subscription. However 1000 calls per day is still free and you can limit the calls per day. After 1000 calls it starts to cost.

  • 1000 calls per day is enough for me, the renewal of the frequency will be done differently.

    it's more about how to properly incorporate the onecall function into my code.

    It works for me in the simulator, but not on the watch.

     function makeForecastWeatherRequest() {
          var UNITS = (System.getDeviceSettings().temperatureUnits==System.UNIT_STATUTE) ? "imperial" : "metric";
    			var url = "https://api.openweathermap.org/data/2.5/onecall";
    	    	var param = {
    	    		"lat" => lattitude,
    	    		"lon" => longitude,
    	    		"appid" =>appid,
              //"lang" => lang == null ? "en" : lang,
               "exclude" => "current,minutely,hourly",
    	    		"units" => UNITS};
    			var options = {
    				:methods => Communications.HTTP_REQUEST_METHOD_GET,
    				:headers => {"Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED},
    				:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
    			};
    
          System.println("Daily request "+ url);
       	
    			Communications.makeWebRequest(
    	    	   	url,
    	    	   	param,
    	    	   	options,
    	    	   	method(:forecastWeatherCallback));
        
        }

    function forecastWeatherCallback(responseCode as Number, data as Dictionary or String or Null) as Void {
          if (responseCode == 200) {
            System.println("Daily response code " + responseCode);
    
            var TimeStamp = Time.now().value();
            var temperature_min = ((((data as Dictionary)["daily"] as Dictionary)[0] as Dictionary)["temp"] as Array)["min"] as Number;
    
            dailyWeather = 
            {
              "daily_timestamp" => TimeStamp,
              "temp_min" => temperature_min,
            };
    
            state = DONE;
            ref();
          } else {
             Background.exit(responseCode);
          }
        }

  • The call is too large, even if you ecxlude stuff from it. I had to make own proxy where I narrow the amount of data.

  • I've used "api.openweathermap.org/data/2.5/weather" for years and at least in that data, temp_min and temp_max are not the daily min/max.  They are the temps from other nearby weather stations at the same time as the "temp" reading.

    Also, it has "dt" which is the time of the actual data came from the weather station, vs Time.now().value() which would be the time you got the data (they will likely be different)

    What error do you see on the real device?

  • Ah, then that will be the whole problem.

    Own proxy server, hm, I have no idea.

    Is it possible to replace the OWM provider with another, or does it not affect the calling function?