Tutorial: integrate web content from HTTP(S) servers

Basic architecture

It is possible to integrate web content from one ore more HTTP(S) servers.

The HTTP plugin that implements this functionality creates Server Items which represents the web content of interest. The NETx Server acts as HTTP client. HTTP GET requests are used to retrieve content. The retrieved information is parsed and relevant values are stored within Server Items. On the other hand, write request to these Server Items are sent to the HTTP server using HTTP PUT or POST requests. The web requests are encoding as XML for example.

Installation

The driver is implemented as a plugin. Therefore, it has to be installed via the Extension Manager. To do so, stop the NETx Server and open the Extension Manager via the studio using the menu "Extensions". Select the "HTTP" interface and press install as shown in the following screenshot:

After having installed the interface, restart the studio.

Configuration

The configuration is done using the following configuration files and definition tables. A detailed description can be found within the reference manual.

Integration steps

One of the most important step is the definition of the HTTP resource that is expected by the server. The resource depends on the used encoding and on the direction of the data change (polling or update). 

Parameters

Normally, an HTTP server will host multiple data points values. To avoid that a separate HTTP resource has to be specified for each data point, parameters can be used. The HTTP resource is defined in a generic way using placeholders for parameters. These placeholder are replaced by the parameters values defined within the xio.HTTP.DatapointDefinitions.dat.

XML encoding

XML encoding has to be used when the HTTP server provides the information as XML. The resource definition must be as follows:

  • Polling: for getting data point values out of an XML document, an XPath expression has to be specified. This XPath expression is used to select an XML element and its content. More information about XPath can be found here.

  • Updating: for updating a data point value, the XML fragment that is expected by the HTTP server has to be specified. This XML fragment must contain the "ValueTag" (specified within xio.http.cfg, default @value@).

JSON encoding

JSON encoding has to be used when the HTTP server provides the information as JSON. The resource definition must be as follows:

  • Polling: for getting data point values out of a JSON document, a JPath expression has to be specified. This JPath expression is used to select a JPath element and its content. More information about JPath can be found here.

  • Updating: for updating a data point value, the JSON fragment that is expected by the HTTP server has to be specified. This JSON fragment must contain the "ValueTag" (specified within xio.http.cfg, default @value@).

URL encoded

URL encoded can be used to send value via URL parameters. URL encoded is only available for updating resources. The resource definition must be as follows:

  • Polling: Not allowed

  • Updating: for updating a data point value, an URL parameters string must be provided. It will be appended to the update URL and must have the form: "<parameter1 name>=<parameter1 value>&<parameter2 name>=<parameter2 value>&...". The URL parameter string must contain the "ValueTag" (specified within xio.http.cfg, default @value@). Suppose the update URL is "http://192.168.0.1/cmd/switch.xml" and the URL parameter string within the resource definition is "id=ceiling_light&state=@value@". If the item value "1" is written the HTTP plugin will initiate a GET request with the URL "http://192.168.0.1/cmd/switch.xml?id=ceiling_light&state=1"

Text encoded

Text encoded can be used to retrieve and send values from HTTP servers that provide any kind of text in their responses. The resource definition must be as follows:

  • Polling: for getting data point values from any text document, the regular expressions has to be specified. This regular expression is used to parse the HTTP response and extract the information that shall be set as data point value. The regular expression must contain a matching group (denoted by "()" ) – otherwise the full match will be taken as data point value. Consider the response is as follows: "The data point value is 25%". To retrieve the value "25", the regular expression ".* ([0-9]+)%" can be used. 

  • Updating: for updating a data point value, the text that shall be sent to the HTTP server must be specified. The text must contain the "ValueTag" (specified within xio.http.cfg, default @value@). E.g. "any text. Datapoint value is @value@").

Example

Suppose there is a HTTP server (192.168.0.10) which acts as interface to different devices that provide data point values. The server provides all information as XML via an URL like http://192.168.0.10/data/current.xml. This XML looks as follows.

<devices> <device name="controller1"> <setpoint>25.5</setpoint> <input1>12</input1> ... </device> <device name="controller2"> <setpoint>23.5</setpoint> <input1>17</input1> ... </device> ... </devices>

To get the setpoint of the controllers, the following XPath definition has to be used:

/devices/device[@name="{0}"]/setpoint/text()

This expression with search for <devices> then for a <device> element that has the attribute "name" equal to parameter {0}, afterwards for <setpoint> and finally returns the text which is 25.5 in our example.

The resource definition looks as follows:

In addition, suppose that the value can also be changed by sending an HTTP POST request that contains an XML fragment to the URL http://192.168.0.10/data/update.xml. Suppose that the XML fragment must be as follows:

<devices> <device name="controller1"> <setpoint>21</setpoint> </device> </devices>

The corresponding resource definition looks as follows:

The value tag @value@ will be replaced the value that shall be written.

To use these resource definitions to integrate the setpoints of controller1 and controller2, you can use the following datapoint definitions:

As shown here, "controller1" and "controller2" are used as parameters. This means that the server will replace {0} by "controller1" and "controller2" respectively. For controller 1, this results in the following XPath  expression and XML fragement:

 

For controller 2:

 

The item tree of this example looks as follows:

Available resource definitions for already tested servers

EZR

Room controllers from EZR (http://ezr-home.de/) can be connected to a gateway that provides an HTTP server. For retrieving the current temperature and the set point, the following ZIP file can be used:

EZR.zip

It contains the resource definition and an example of some data point definitions.

Telegram

The NETx BMS Platform and NETx Multi Protocol Server have build-in support for Telegram via the Messenger plugin. 

For the NETx BMS Server 2.0, you can use the HTTP module to send messages to the messaging service Telegram. The following ZIP file contains the necessary configuration data:

Telegram.zip

More information can be found here.

Sending SMS

The NETx BMS Platform and NETx Multi Protocol Server have build-in support for sending SMS via the Messenger plugin. 

For the NETx BMS Server 2.0, you can use the HTTP module to send a SMS via online SMS services. An example of such a service is https://www.cm.com/. The following ZIP file contains the necessary configuration data:

SMS.zip

Article applies to the following products:

  • NETx BMS Platform

  • NETx Multi Protocol Server

  • NETx BMS Server 2.0

Related pages