With the HTTP Gateway you can make service calls to a REST-Service or Webservice. You can even transmit a content to the service and also analyze the respond. We will demonstrate this with a simple REST-Service (MyStrom Switch) as example.

Request

The call is very simple:

The example Shows a simple call to a REST-Service without any parameter. The HTTP Type GET will be used. AS URL (http://) we define the webserver-adress and path, which executes the operation on the server.

The other types (e.g. POST) can give also a content as parameter additionally. Here you would enter the  JSON element which will be sent with the call.

Response

The analysis of the response is a little bit more difficult.

With the example of the MyStrom Switch we have a state request ([Server]/report), wich returs a JSON Element. It looks in the following way:

 

{"power": 0, "relay": false}

Power indicates the acutally power consumation, relay if the switch is turned on or off.

For sending an system event, if the Switch is turned on, we register the following response event:

 

When calling the HTTP command, a event with Parameter „power“ and value „on“ will be sent, if the Switch is turned on. The regular Expression „(.|\n)*\“relay\“:.true(.|\n)*“ matches with the response if after the string „relay“ a string „true“ is present.

On control we could now catch the event with an event handler and manipulate the control, so the state of the Switch will be visualized.

 

You have to configure the ID of the HTTP Device as „Sender“. The Parameter „Property“ and „value“ you have to set with the same values like in response event in the command of the HTTP Device.

For analisis of the power consumation the process is a different.

The regular expression „(?<=“power“:.)(.*)(?=(\r|,))“ does not check if it matches with the response, but searchs trough the Response. The value which was found will transmitted with the Event. This different behaviour, the system has, is set with the definition #value within the „Value“ property. We do also not want to transmit a fix value in this case, but the value from response, which is variable.

Now we can eisplay the value for example on a text control. The attributes in the upper part of the dialog works like a filter. It means only events with the same values will have any effect on the control.

Because we have a variable value, which will be sent with the event, we can’t configure in the event handler a fix „value“. So we can enter #null, which has the effect, that the „value“ property does not act as a filter. As „Sender“ we configure the ID of the HTTP Device, as „Property“ we use the same value we already defined in the response event. For changing the text control, you have to enter the property „text“ and the value „#value“.