Weather from weatherstack.com

<< Click to Display Table of Contents >>

Navigation:  Examples > HTTP requests >

Weather from weatherstack.com

Previous pageReturn to chapter overviewNext page

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 you can look at examples of requests and  create 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. Please note that if you need to pass a parameter containing a space, for example "New York", then the space must be replaced with "%20", that is, "New%20York". You can check the validity of the request by pasting it into the address bar of your browser:

 

weatherstack

 

The browser displayed a response with the correct data, indicating that the request was made correctly. As you can see, the response is sent in JSON format, later we will extract the properties we need from it.

Now we can start solving the problem in TeslaSCADA2.

1. First, let's create an interface in the project. Temperature, pressure, wind, humidity and local time will be displayed using Text/EditField objects. In the CityName field we activate the Output value property to be able to change the name of the city. The image below shows the created interface and the names we gave to the components:

 

 

 

interfaceweather

 

2. Create tags for each text object and bind them:

 

 

weathertags

 

3. Now let's create a script in ST language that will be executed when you click on the screen:

 

weatherscript

 

The text of ST script below:

 

stweather

 

Change API_ACCESS_KEY to your key that you get from site.

After you have recorded the script, be sure to launch it by clicking the button on the toolbar: runsimulation

 

4. Let's Run simulation to check the settings:

 

weatherhttp

 

You can download this project here.