|
<< Click to Display Table of Contents >> Navigation: Components > Communication > Multi-IO-IP > How to connect Multi I/O to a device > Example with HTTP |
In the following example, a Web request is to be issued and any evaluated response received. In the second example a response is to be received in the form of an XML document, extracting a certain value and forwarded to the internal network.
Example 1
Play a playlist on a MP3 player, which has an HTTP interface. How to stop the play list with another command. The device has the IP address 192.168.1.100 and the internal Web server is listening on port 80. According to the documentation, the Request URL for the two exemplary commands should look like as follows:
Command:
Command Play: GET /commandscript?cmd=play
Command Stop: GET /commandscript?cmd=stop
URL:
http://192.168.1.100:80
There are now several approaches to get the multi-IO component to send. One approach is, WITHOUT selected prefix / postfix entry and WITHOUT selected data filter entry (because in this example 1, we want to get an answer and evaluate) a request with the settings of this dialogue should be discontinued. Create a new entry and enter a unique name. Then enter in the "Command" the actual "Request URL" String.
Transmission method: HTTP
no Prefix/Postfix
no filter
Entries:
Name |
Prefix/Postfix |
Filter |
Command |
Url |
Http Method |
Forward Answer |
|---|---|---|---|---|---|---|
InputExample_1 |
no |
no |
/commandscript?cmd=play |
http://192.168.1.100:80 |
Get |
no |
Because the command entry will be only attached to the URL, the actual command may also be entered in full in the "URL". A possible value in the "command" field is only attahced to the URL, when this data point is linked and triggered with an on / off or a DataPointValue Boolean with a EisBaer output data type.
Entries:
Name |
Prefix/Postfix |
Filter |
Command |
Url |
Http Method |
Forward Answer |
|---|---|---|---|---|---|---|
InputExample_1 |
no |
no |
|
http://192.168.1.100:80/commandscript?cmd=play |
Get |
no |
Another more dynamic approach is for several different commands that are similar in structure, provide only ONE entry in the inbox. The be appended to the request URL to be deducted command data are transmitted via the connected to this input output of data type string or a DataPoint Value of type string to this input of the multi-IO component. Then, the entry in the "command" of this dialogue will be ignored and the transmitted value is taken instead.
Entries:
Name |
Prefix/Postfix |
Filter |
Command |
Url |
Http Method |
Forward Answer |
|---|---|---|---|---|---|---|
InputExample_1 |
no |
no |
|
http://192.168.1.100:80/commandscript?cmd= |
Get |
no |
|
|
|
|
|
|
|
Such dynamic data point will be linked to several outputs of other components, which transmit the commands to be the attached parts. As an example, a button switch, which is linked to its "Value On" starting with this input, the multi-IO component, only send the string "play" and, for example, for "Value On" the string "stop". This is attached to the URL and sent. Each button toggles "play" and "stop" of MP3 songs to the episode.
If you select an entry in the field "Prefix / Postfix", so the strings are as follows
Composed:
Request URL = <Content_FELD_URL>
+ <PREFIX>
+ <REQUEST_ODER_DYNAMICSTRING>
+ <POSTFIX>
Example 2
In the second example, a value from a received XML document should be selectively extracted and send to a EisBaer Net . An entry for querying a Web Services has already been created (Trigger Weatherford). This is e.g. triggered by a button. The answer is diverted to a second data point (InputWeatherTemp) and a data filter has been selected (see following table).
Entries:
Name |
Prefix/Postfix |
Filter |
Command |
Url |
Http Method |
Forward Answer |
|---|---|---|---|---|---|---|
TriggerWeather |
No |
No |
|
http://xoap.weather.com/weather/local/69412?cc=*&dayf=1&unit=m |
Get |
InputWeatherTemp |
InputWeatherTemp |
No |
FilterWeatherCurrentTemp |
|
|
Get |
|
Suppose the expected XML document is the temperature at the desired location and it is the value should be read in the following figure (value in bold):
<weather ver="2.0">
<head>
<locale>en_US</locale>
<form>MEDIUM</form>
<ut>C</ut>
<ud>km</ud>
<us>km/h</us>
<up>mb</up>
<ur>mm</ur>
</head>
<loc id="69412">
<dnam>Eberbach, BW, Germany</dnam>
<tm>11:40 AM</tm>
<lat>49.47</lat>
<lon>9.01</lon>
<sunr>6:21 AM</sunr>
<suns>8:25 PM</suns>
<zone>2</zone>
</loc>
<cc>
<lsup>4/21/15 11:25 AM CEST</lsup>
<obst>Michelstadt-Vielbrunn, BW, GM</obst>
<tmp>14</tmp>
<flik>14</flik>
<t>Partly Cloudy</t>
<icon>30</icon>
.
.
.
.
.
.
</weather>
In the list of this example is in the field "Data Filter" entry FilterWeatherCurrentTemp selected. The next figure shows how a filter entry looks to locate this value of the XML document and then convert into a EisBaer internal data type:
Filter:
Name |
Filter type |
Filter expression |
Data type |
Condition |
Text substitution |
|---|---|---|---|---|---|
FilterWeatherCurrentTemp |
XML |
/weather/cc/tmp |
DPT 14.* |
|
|
The highlighted text is the path of the search node in the XML document. The first word is the root node, the second for to search for nodes below this root node, etc.! For a more detailed description also as nodes are addressed with specific attribute values in the chapter Multi-IO-IP\Filter\XML_Filter. Did the component extracted this value after receiving the document , the value is converted into the data type selected in the "Data Type" field. The selectable data types, see the chapter Supported data point types.
If the conversion fails, an error text is send on the output "error messages" of the Multi-IO component. This can be displayed with a value driven text.
If the conversion is successful, then the value is sent to the component that is linked to the data point InputWeatherTemp.