Weather from weatherstack.com

<< Click to Display Table of Contents >>

Navigation:  Examples > HTTP requests >

Weather from weatherstack.com

Previous pageReturn to chapter overview

weatherstack.com has a convenient API for reading weather data. After registering on the site, you will receive a unique access key (API Access Key), which must be used in GET requests to obtain weather data. In the weatherstack documentation, we look at examples of requests and compose a request, for example, for Berlin it should be like this:

 

http://api.weatherstack.com/current?access_key=API_ACCESS_KEY&query=Berlin

 

instead of API_ACCESS_KEY, you need to insert the access key received during registration. Note, if you need to pass a parameter containing a space, for example "New York", then the space must be replaced with "% 20", i.e. "New% 20York". You can verify the correctness of the request by pasting it into the address bar of your browser:

 

weatherstack

The browser displayed a response with correct data, which means the request was composed correctly. As you can see, the response is sent in JSON format, later we will extract the properties we need from it. Now you can start solving the problem in TeslaSCADA2. First, let's create an interface in the project. The temperature, pressure, wind, humidity and local time will be displayed in the Text/EditField components. In the CityName Text/EditField component we enable Output value property to have possibility to change city name. The image below shows the created interface and the names we gave to the components:

interfaceweather

Every Text object we bound to the tags:

 

weathertags

Now we can create ST script that we'll be executed when you click on every screen:

weatherscript

The text of ST script below:

stweather

Change API_ACCESS_KEY to your key that you get from site. And now let's check how it works:

weatherhttp