If we want to use information about the weather, sunrise or sunset in the system, we can use an external website for this purpose, e.g. https://openweathermap.org/.
According to the example on: https://openweathermap.org/current,
the API query looks like as following:
API call: api.openweathermap.org/data/2.5/weather?q={city name}&appid={your api key}.
Below is presented how we can easily obtain this information:
- Create the HttpRequest periphery object:
- The following parameters should be set in the HttpRequest object:
Where:
Host: api.openweathermap.org
Path: /data/2.5/weather
QueryStringParams: q=Krakow&appid={your api key}
Warning! The api key is obtained after creating an account at: https://home.openweathermap.org/users/sign_up - The next step is to create user features of the number type:
- Then prepare the script:
local resp = GATE_HTTP->open_weather_map->ResponseBody GATE_HTTP->lon_owm = resp.coord.lon GATE_HTTP->lat_owm = resp.coord.lat GATE_HTTP->weather_main_owm = resp.weather[1].main GATE_HTTP->weather_desc_owm = resp.weather[1].description GATE_HTTP->weather_base_owm = resp.base GATE_HTTP->temp_owm = resp.main.temp GATE_HTTP->temp_min_owm = resp.main.temp_min GATE_HTTP->temp_max_owm = resp.main.temp_max GATE_HTTP->pressure_owm = resp.main.pressure GATE_HTTP->humidity_owm = resp.main.humidity GATE_HTTP->visibility_owm = resp.visibility GATE_HTTP->wind_speed_owm = resp.wind.speed GATE_HTTP->wind_deg_owm = resp.wind.deg GATE_HTTP->cloud_all_owm = resp.clouds.all GATE_HTTP->country_owm = resp.sys.country GATE_HTTP->sunrise_owm = resp.sys.sunrise GATE_HTTP->sunset_owm = resp.sys.sunset GATE_HTTP->timezone_owm = resp.timezone GATE_HTTP->city_owm = resp.name
- Assign the script to the OnResponse event in the HttpRequest periphery object:
- Then, the configuration should be sent to the CLU.
- After the configuration has been successfully sent, the SendRequest method should be called in the Control tab of the HttpRequest periphery object:
- After calling the method, the StatusCode feature should receive the value 200.
- User features values should receive appropriate values:
- To verify received information, it is possible to paste query to an internet browser and compare:
- The obtained data can be displayed in the mobile application and Smart Panel or use to create logic in the system.