weather in the openweathermap?

Please provide the exact source code for the weather in the openweathermap for Garmin F5

Thank You
  • Your code is much more readable if you put it into a code blocks.

    var unit = "metric";
    
    (:background_method)
    function initialize() {
        Sys.ServiceDelegate.initialize();
        if (Sys.getDeviceSettings().temperatureUnits == System.UNIT_STATUTE){
            unit = "imperial";
        }
    }
    
    (:background_method)
    function onTemporalEvent() {
        getWeather();
    }
    
    (:background_method)
    function getWeather(){
        var lat, lon;
    
        lat = Application.getApp().getProperty("lat");
        lon = Application.getApp().getProperty("lon");
    
        Comms.makeWebRequest(">api.openweathermap.org/.../weather", 
        /*
         * URL
         */ 
    
        {
            "lat" => lat,
            "lon" => lon,
            "appid" => "2225aec78cbbb36c8f92494c9ede2f64",
            "units" => unit // Celcius.
        },
        /*
         * PARAMS 
         */
    
        {
            :method => Comms.HTTP_REQUEST_METHOD_GET,
            :headers => {"Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED},
            :responseType => Comms.HTTP_RESPONSE_CONTENT_TYPE_JSON
        },
        /*
         * OPTIONS
         */
    
        method(:onReceiveWeatherdata));
    }
    

    (:background_method)
    function onReceiveWeatherdata(response, data){
        if(response != 200){
            Sys.println(response);
            Background.exit({"response" => response});
        } else {
            var result = {
                "cod" => data["200"],
                "lat" => data["coord"][0],
            };
    
            Background.exit({"weatherdata" => result, "response" => response});
        } 
    }

    I'm not sure what the (:background_method) annotation is, but it isn't something that we document. If you have code that is called from the background process, it must be annotated with (:background).

    Additionally, I'm not sure I understand what you doing here..

            var result = {
                "cod" => data["200"],
                "lat" => data["coord"]["50.09"],
                "lon" => data["coord"]["14.42"],
                "dt" => data["1592930217"],
                "temp" => data["main"]["296.04"],
                "humidity" => data["main"]["35"],
                "icon" => data["weather"][0]["icon"]
            };

    It looks like you're trying to get the current conditions as documented here. If the request was successful, data will be a dict as shown in their API response. The code above is trying to find a key named "200" in the response... this is simply never going to be found. It looks like you want "cod" => data["cod"]. Similarly, for the lat/lon fields, you want to extract the "lat" and "lon" fields from the "coord" dictionary...

    var result = {
        "cod" => data["cod"],
        "lat" => data["coord"]["lat"],
        "lon" => data["coord"]["lon"],
        ...
    };

    That should get you a pretty good idea of what you need to do.