The company OpenWeather provides weather data and forecasts on its website OpenWeatherMap https://openweathermap.org for retrieval. The data can be integrated into your own applications. The retrieval is possible via the offered API via REST interface, whereby the integration can be automated. In addition to detailed long-term forecasts, which are subject to a charge, current weather data and short-term forecasts can be called up free of charge.
REST Open Weather with OPC Router
Using the example of OpenWeatherMap, we show the use of OPC Router REST Plug-in to call REST API interfaces and show how to
- retrieve weather data from OpenWeatherMap
- JSON weather data are processed
- Data can be stored in an SQL database using the SQL Server plug-in
- Weather data can be sent by telegram with the Telegram Plug-in
Weather API, the REST interface to weather data
A REST interface is a data interface based on web technologies. Data can be retrieved from the REST API via the https protocol. Technically, a web page is called with a URL, just like in a browser. Parameters are passed to the Web page call, which are appended to the URL as parameter fields. The meaning of the parameters is defined in the respective REST API documentation. For OpenWeather’s Weather API, the documentation is available online at https://openweathermap.org/api. For each form of data retrieval (current weather, forecast daily / 5 days / 16 days / 30 days, etc.) there is a separate REST API endpoint (call URL).
An example of retrieving the current weather in London looks like this: Result data in JSON format (call returns test data only)
The parameter “q” contains the city and the country code. The REST API endpoint is “weather”. The parameters are appended to the endpoint via “?” and chained with “&”. Each parameter is declared with name and value, separated by a “=”.
The parameter “appid” is used by the Weather API as authentication to identify the retrieving client. For your own test setup, you must request your own App-ID to make data retrievals. The App-ID or the API KEY can be obtained by registering on the following page https://home.openweathermap.org/users/sign_up. The API KEY can then be viewed in the user area under “API keys”.
The description for retrieving the current weather of any location is documented here: https://openweathermap.org/current