Domorela's Blog: Virtual Lab with Domorela DMRL1: Testing with REST API: Lights & HVAC operation

As we said in our past article, we will test same things we did with the WUI in our previous articles by sending queries to the KNX service of the API using scripts based in the well known Open Source tool called cURL. This tool can be compiled for your own system from source code and also there are dowloadable binaries for different CPU architectures and many Operating Sytems: GNU/Linux, FreeBSD, UNIX based as AIX, HPUX, Solaris and others, and also for Windows.

As we are using KNX service to send commands to the KNX BUS, first of all we need to construct these commands. To maintain consistency the commands need to be constructed in XML but, as they are computed as Str values, they have no oBIX standard tags nor attributes but the ones we defined for them.

Below you can see the command to write over the Group Address corresponding to Apagado General Luz Oficinas (General Switching Off of the Office Lights):

  <?xml version="1.0" standalone="yes" encoding="UTF-8"?>
  <comandos>
    <comando tipo="PC" cmd="escribe" p1="off">
      <KnxAddress tipo="GRP">0/3/4</KnxAddress>
    </comando>
  </comandos>

Once the command is constructed and saved as file cmdFile, then we need to encode it using Base64:

  $ echo "<str name='comandos' val='`base64 cmdFile`'/>" > data

Then we make the REST query with next cURL command:

  $ curl -b .cookies --data-binary "${@data}" "https://$host:8083/admin/api/knx?ref=knxcmd/" > result.xml

You can see the execution of a script doing the above tasks in the below video.

 

 

In order to test HVAC we used Domorela Scenes, so can do things in a different way. There is another query intended to send Scenes to KNX service of the REST API that requires other data that you can see below:

  <?xml version="1.0" standalone="yes" encoding="UTF-8"?>
  <list name="escena" of="obix:str">
    <str name="2304" val="25.0" />
    <str name="2306" val="off" />
    <str name="2307" val="cooling" />
  </list>

Note that 2304, 2306 and 2307 are Raw Group Addresses, that is, Integer values for 1/1/0, 1/1/2 and 1/1/3 Three Level Group Addresses.

 

To do this query we send an oBIX List of Str objects, as shown above, encoded in XML to the KNX service using a different ref parameter to invoke Scene execution in the KNX service:

  $ curl -b .cookies --data-binary "${@data}" "https://$host:8083/admin/api/knx?ref=knxusaescena/" > result.xml

Invoking KNX service this way, is possible to define as many external Domorela Scenes as you want with your own scripts or code. In the case you don't want to define externally the scenes (for instance, to avoid raw address calculation), you can obtain predefined Scenes from the Admin service then use them to invoke KNX service of the REST API:

  $ curl -b .cookies "https://$host:8083/admin/api/admin?ref=escenas/escena15/&tree=true&nivel=2" > escena.xml
  $ curl -b .cookies --data-binary "${@escena.xml}" "https://$host:8083/admin/api/knx?ref=knxusaescena/" > result.xml

 

The below video shows the execution of an externally defined Scene to simulate behaviour of the HVAC:

 

 

In the next article we'll move back to WUI in order to test alarms.