Several systems provide information through Web Services. In other words, Web Services can provide information (usually through files/streams in the XML or JSON format) based on a request using the HTTP protocol. This tutorial will help you add these services to InduSoft Web Studio HMI/SCADA projecrs, and uses the example of a weather information service. Weather information may be useful in applications such as wind and solar energy applications, energy metering, building management, or similar applications.
The following diagram illustrates the transaction in a simplified manner:
InduSoft Web Studio offers an open architecture, with built-in tools to achieve interoperability among different devices and system, not only on the plant-floor, but also on the ERP/IT/Cloud level. For example:
- Built-in OPC Clients (OPC DA, OPC XML, OPC .NET, and OPC UA), native communication drivers for more than 250 protocols supported by PLCs, Motion Controller, Sensors, and other devices (e.g.: Modbus, BacNet, Ethernet/IP CIP, etc).
- Patented solution to exchange data with SQL Relational Databases on premise or on the cloud (e.g.: Microsoft SQL Server, Microsoft SQL Azure, Oracle, Sybase, MySQL, etc).
- Native communication for protocols typically used in Internet of Things (IoT) configurations, such as MQTT.
- Powerful and flexible scripting editor to build or use libraries of functions, based on the standard VBScript language.
In this example, we will demonstrate how to consume weather information (e.g.: temperature and dew point) from web services available on the web (internet). Specifically, it will retrieve information using the Data Server from the Aviation Digital Data Service (ADDS) – https://www.aviationweather.gov/adds/dataserver. For example, by the time that this article was written, sending the following URL, we would receive the following answer from the web service:
The URL specifies settings that will be analyzed by the web service before sending the response. These settings are defined after the “?” character and concatenated by the “&” character. For example, the instruction radialDistance=2;-104.65,39.83 indicates to the web service that the client wants to receive information from stations within the radial distance of 2 miles from the given coordinates (longitude -104.65 and latitude 39.83). The response (in XML format) includes several information from the weather station, including the temperature (-5.6 °C) under the XML path response\data\METAR\temp_c.
The goal is to configure a simple interface in InduSoft Web Studio, where the user can give an address and the application retrieves the temperature and dew point from this web service. In order to accomplish this task, we can create three functions in the Global Procedures interface of InduSoft Web Studio (Project Explorer > Global> Procedures): GetXMLNodeValue, GetLatLngFromAddress, and GetMetarAviationWeather.
The aforementioned GetXMLNodeValue function can be used to send a request to a remote Web Service through a URL, and return the value from a specific XML node from the stream returned by the Web Service. This is a generic function that will be called by two other functions to accomplish the goal of this example.
The aforementioned GetLatLngFromAddress function returns coordinates (latitude and longitude) from a given address. Notice that after setting the Google Maps Geocoding API url, this function calls the previously defined GetXMLNodeValue function to get both the latitude and the longitude from the returned XML stream. The GetLatLngFromAddress function returns both the latitude and the longitude as a string in CSV (comma separated value) format. For example, if the latitude is 40 and the longitude is -100, this function will return the string 40,-100.
The GetMetarAviationWeather function returns the value of a required weather parameter (e.g.: temp_c) measured by the weather station within 20 miles (radialDistance=20) from the given address within the last 3 hours (hoursBeforeNow=3).
After creating (or simply copying and pasting) the aforementioned three functions in your InduSoft Web Studio project (Project Explorer > Global> Procedures), you just need to call the GetMetarAviationWeather function to get the weather information from a specific address.
The aforementioned code (which can be created in the Command animation applied to a button) will update the tag $weather.temp with the temperature and the tag $weather.dewPoint with the dew point from the weather station nearly the address specified as the value of the tag $weather.address.
It is worth noting that the web services used in this example are publicly available (by the time this article was written) and they do not require authentication to return values. Web Services that require authentication will require additional configuration.
To sum up, using this example, you can easily retrieve weather information from the Aviation Digital Data Service (ADDS) data server. More importantly, using the generic GetXMLNodeValue function, you can retrieve information from web services that provide information as an XML stream.
Note: InduSoft is not responsible for the availability or accuracy of the information provided by third-party web services used in this example.