Categories
HowTo's VSCP

Using the #VSCP #MQTT driver Part 2 #IoT #m2m

VSCP MQTT Driver Simplify mode

Part 1

Screenshot from 2016-02-14 22:00:26

Make measurement event come out as a plain number over the MQTT channel.

Sometimes, and especially if your device is a low end device, it can be nice to publish measurement events from the VSCP daemon to it as plain numbers. You can do this with the simplify feature.

First look at the driver  entry in /etc/vscp/dm.xml

<!– Level II MQTT driver –>
<driver enable=”true” >
     <name>MQTT2</name>
     <path>/usr/local/lib/vscpl2drv_mqtt.so</path>
    <config>session2;publish;vscp-pub;192.168.1.9:1883
    <guid>00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00</guid>
</driver>

We see that this driver defines  a publishing MQTT channel with

  • topic = vscp_pub
  • session id = session2
  • broker is at  address = 192.168.1.9
  • broker use standard MQTT port  = 1823

Nothing strange here. Normally VSCP events would be available if you subscribe to the topic vscp_pub on this broker. On the console typically like

mosquitto_sub -h 192.168.1.9 -v -t ‘vscp-pub’

This is just the same as we described above. But now lets define a simplify variable like (/srv/vscp/variables.xml or in the web interface of the VSCP daemon).

<variable type=”string”>
     <name>MQTT2_SIMPLIFY</name>
     <note>Feed temperature measurements to “the thing”</note>
     <value>1040,6,0,1,0,0</value>
</variable>

When the MQTT driver loads it looks fore variables named like it’s name + “-” + keyword and configure itself from the variables. This configuration actually overrides the configuration done in the diver configuration string.

It also add extra configuration possibilities and SIMPLIFY is on of them so

MQTT2_SIMPLIFY

is a variable with name “SIMPLIFY” that is destined for the driver with name “MQTT2”.

The content of  a simplify variable specify the event we want to send on the MQTT channel as a plain number.  In our case we have

1040,6,0,1,0,0

which boils down to

  1. 1040 – This is the VSCP class. In this case CLASS2.MEASUREMENT_STR
  2. 6 – This is the VSCP Type and six is “temperature”.
  3. 0 – This is the sensor index. Only events with this sensor index will be published.
  4. 0  – This is the zone. Only events with this vallue will be published.
  5. 0  – This is the sub zone. Only events with this value will be published.
  6. 0 – This is the unit. Only events with this value will be published.

You can use CLASS1_MEASUREMENT and CLASS2_MEASUREMENT_FLOAT also if you which for this functionality and the format for them are here.

So now when you restart the VSCP daemon CLASS2.MEASUREMENT_STR events will come out as plain numbers on the MQTT channel. We can test this in the TCP/IP interface by sending

send 0,1040,6,0,0,-,0,0,0,1,0×35,0x35,0x35,0x2e,0x30,0x32

which will come out as

vscp-pub 555.02

if you subscribed using mosquitto_sub -h 192.168.1.9 -v -t ‘vscp-pub’

Send plain numbers over a MQTT channel and have them automatically translated into proper VSCP events.

You may just want to send plain numbers instead of a full VSCP event to the VSCP framework.  Typically this can be some stupid device that just is capable of sending out plain numbers. The simplicity mode can make these kind of devices a bit more useful also. YES you want at least the unt of your measurement to come along with your data in a standardized way.

To use this feature we us the first driver entry we specified

<!– Level II MQTT Driver –>
    <driver enable=”true” > 
    <name>MQTT1</name>
    <path>/usr/local/lib/vscpl2drv_mqtt.so</path>
    <config>session1;subscribe;vscp-sub;192.168.1.9:1883
    <guid>00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00</guid>
</driver>

Here we subscribe to a MQTT channel vscp_sub on the broker located at 192.168.1.9 on port 1883. We name the session “session1”.  Remember that all drivers MUST have a unique session name.

So things publishe form other devices on topic vscp_sub will be received by the driver and normally this is VSCP events on the standard string form

send head,class,type,obid,time-stamp,GUID,data1,data2,data3…

you can read mode here about this format used n the TCP/IP interface of the VSCP daemon among other places.

But now we want to send just a number and get a VSCP events. So for this we use the simplify feature again.

We start out just as above by specifying the SIMPLIFY variable.  As you see we now referee to the first driver entry MQTT1

<variable type=”string”>
   <name>MQTT1_SIMPLIFY</name>
   <note>Allow for sending plain numbers </note>
   <value>1060,6,0,1,0,0</value>
</variable>

Only 1060 is different than above, We could have used 1040 here alos to get CLASS2.MEASUREMENT_STR event but to be not to repetitive we use CLASS2.MEASUREMENT_FLOAT for this example.

And using VSCP Works to check the incoming event gives the expected result

Screenshot from 2016-02-14 22:32:04

 

If we set  CLASS2.MEASUREMENT_STR (1040) instead we got the same end result

Screenshot from 2016-02-14 22:32:04

And you can use one of the other measurement types also of course. Read the docs.

Well that was it for this time.  The full driver info is here.

 

One reply on “Using the #VSCP #MQTT driver Part 2 #IoT #m2m”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.