{"id":1528,"date":"2016-02-15T13:12:52","date_gmt":"2016-02-15T13:12:52","guid":{"rendered":"http:\/\/grodansparadis.com\/wordpress\/?p=1528"},"modified":"2017-11-30T20:09:37","modified_gmt":"2017-11-30T20:09:37","slug":"using-the-vscp-mqtt-driver-part-2-iot-m2m","status":"publish","type":"post","link":"https:\/\/grodansparadis.com\/wordpress\/?p=1528","title":{"rendered":"Using the #VSCP #MQTT driver Part 2  #IoT #m2m"},"content":{"rendered":"<h1>VSCP MQTT Driver Simplify mode<\/h1>\n<p><a href=\"http:\/\/grodansparadis.com\/wordpress\/?p=1533\">Part 1<\/a><\/p>\n<h2><a href=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-220026.png\" rel=\"attachment wp-att-1529\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1529\" data-permalink=\"https:\/\/grodansparadis.com\/wordpress\/?attachment_id=1529\" data-orig-file=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-220026.png?fit=735%2C1015&amp;ssl=1\" data-orig-size=\"735,1015\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Screenshot from 2016-02-14 22:00:26\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-220026.png?fit=580%2C801&amp;ssl=1\" class=\"alignnone size-full wp-image-1529\" src=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-220026.png?resize=580%2C801\" alt=\"Screenshot from 2016-02-14 22:00:26\" width=\"580\" height=\"801\" srcset=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-220026.png?w=735&amp;ssl=1 735w, https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-220026.png?resize=217%2C300&amp;ssl=1 217w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><\/h2>\n<h2><\/h2>\n<h3>Make measurement event come out as a plain number over the MQTT channel.<\/h3>\n<p>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 <strong>simplify<\/strong> feature.<\/p>\n<p>First look at the driver\u00a0 entry in <strong>\/etc\/vscp\/dm.xml<\/strong><\/p>\n<p><strong><em>&lt;!&#8211; Level II MQTT driver &#8211;&gt;<\/em><\/strong><br \/>\n<strong><em> &lt;driver enable=&#8221;true&#8221; &gt;<\/em><\/strong><br \/>\n<strong><em>\u00a0\u00a0\u00a0\u00a0 &lt;name&gt;MQTT2&lt;\/name&gt;<\/em><\/strong><br \/>\n<strong><em>\u00a0\u00a0\u00a0\u00a0 &lt;path&gt;\/usr\/local\/lib\/vscpl2drv_mqtt.so&lt;\/path&gt;<\/em><\/strong><br \/>\n<strong><em>\u00a0\u00a0\u00a0 &lt;config&gt;session2;publish;vscp-pub;192.168.1.9:1883<\/em><\/strong><br \/>\n<strong><em>\u00a0\u00a0\u00a0 &lt;guid&gt;00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00&lt;\/guid&gt;<\/em><\/strong><br \/>\n<strong><em> &lt;\/driver&gt;<\/em><\/strong><\/p>\n<p>We see that this driver defines\u00a0 a publishing MQTT channel with<\/p>\n<ul>\n<li><strong>topic<\/strong> = <em>vscp_pub<\/em><\/li>\n<li><strong>session id<\/strong> = <em>session2<\/em><\/li>\n<li><strong>broker is at\u00a0 address<\/strong> = <em>192.168.1.9<\/em><\/li>\n<li><strong>broker use standard MQTT port\u00a0<\/strong> = <em>1823<\/em><\/li>\n<\/ul>\n<p>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<\/p>\n<p><strong>mosquitto_sub -h 192.168.1.9 -v -t &#8216;vscp-pub&#8217;<\/strong><\/p>\n<p>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).<\/p>\n<p><em><strong>&lt;variable type=&#8221;string&#8221;&gt;<\/strong><\/em><br \/>\n<em><strong>\u00a0\u00a0\u00a0\u00a0 &lt;name&gt;MQTT2_SIMPLIFY&lt;\/name&gt;<\/strong><\/em><br \/>\n<em><strong>\u00a0\u00a0\u00a0\u00a0 &lt;note&gt;Feed temperature measurements to &#8220;the thing&#8221;&lt;\/note&gt;<\/strong><\/em><br \/>\n<em><strong>\u00a0\u00a0\u00a0\u00a0 &lt;value&gt;1040,6,0,1,0,0&lt;\/value&gt;<\/strong><\/em><br \/>\n<em><strong> &lt;\/variable&gt;<\/strong><\/em><\/p>\n<p>When the MQTT driver loads it looks fore variables named like it&#8217;s name + &#8220;-&#8221; + keyword and configure itself from the variables. This configuration actually overrides the configuration done in the diver configuration string.<\/p>\n<p>It also add extra configuration possibilities and SIMPLIFY is on of them so<\/p>\n<p><em><strong>MQTT2_SIMPLIFY<\/strong><\/em><\/p>\n<p>is a variable with name &#8220;SIMPLIFY&#8221; that is destined for the driver with name &#8220;MQTT2&#8221;.<\/p>\n<p>The content of\u00a0 a simplify variable specify the event we want to send on the MQTT channel as a plain number.\u00a0 In our case we have<\/p>\n<p><em><strong>1040,6,0,1,0,0<\/strong><\/em><\/p>\n<p>which boils down to<\/p>\n<ol>\n<li><strong>1040<\/strong> &#8211; This is the <strong>VSCP class<\/strong>. In this case <a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class2.measurement_str\">CLASS2.MEASUREMENT_STR<\/a><\/li>\n<li><strong>6<\/strong> &#8211; This is the VSCP Type and six is &#8220;temperature&#8221;.<\/li>\n<li><strong>0<\/strong> &#8211; This is the <strong>sensor index<\/strong>. Only events with this sensor index will be published.<\/li>\n<li><strong>0<\/strong>\u00a0 &#8211; This is the <strong>zone<\/strong>. Only events with this vallue will be published.<\/li>\n<li><strong>0<\/strong>\u00a0 &#8211; This is the <strong>sub zone<\/strong>. Only events with this value will be published.<\/li>\n<li>0 &#8211; This is the <strong>unit<\/strong>. Only events with this value will be published.<\/li>\n<\/ol>\n<p>You can use <a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class1.measurement\">CLASS1_MEASUREMENT<\/a> and <a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class2.measurement_float\">CLASS2_MEASUREMENT_FLOAT<\/a> also if you which for this functionality and the <a href=\"http:\/\/www.vscp.org\/docs\/vscpd\/doku.php?id=level2_driver_mqtt#simplify\">format for them are here<\/a>.<\/p>\n<p>So now when you restart the VSCP daemon <a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class2.measurement_str\">CLASS2.MEASUREMENT_STR<\/a> events will come out as plain numbers on the MQTT channel. We can test this in the TCP\/IP interface by sending<\/p>\n<p><strong><em>send 0,1040,6,0,0,-,0,0,0,1,0&#215;35,0x35,0x35,0x2e,0x30,0x32<\/em><\/strong><\/p>\n<p>which will come out as<\/p>\n<p><em><strong>vscp-pub 555.02<\/strong><\/em><\/p>\n<p>if you subscribed using <em>mosquitto_sub -h 192.168.1.9 -v -t &#8216;vscp-pub&#8217;<\/em><\/p>\n<h2>Send plain numbers over a MQTT channel and have them automatically translated into proper VSCP events.<\/h2>\n<p>You may just want to send plain numbers instead of a full VSCP event to the VSCP framework.\u00a0 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.<\/p>\n<p>To use this feature we us the first driver entry we specified<\/p>\n<p><em><strong>&lt;!&#8211; Level II MQTT Driver &#8211;&gt;<\/strong><\/em><br \/>\n<em><strong>\u00a0\u00a0\u00a0 &lt;driver enable=&#8221;true&#8221; &gt;\u00a0 <\/strong><\/em><br \/>\n<em><strong>\u00a0\u00a0\u00a0 &lt;name&gt;MQTT1&lt;\/name&gt;<\/strong><\/em><br \/>\n<em><strong>\u00a0\u00a0\u00a0 &lt;path&gt;\/usr\/local\/lib\/vscpl2drv_mqtt.so&lt;\/path&gt;<\/strong><\/em><br \/>\n<em><strong>\u00a0\u00a0\u00a0 &lt;config&gt;session1;subscribe;vscp-sub;192.168.1.9:1883<\/strong><\/em><br \/>\n<em><strong>\u00a0\u00a0\u00a0 &lt;guid&gt;00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00&lt;\/guid&gt;<\/strong><\/em><br \/>\n<em><strong> &lt;\/driver&gt;<\/strong><\/em><\/p>\n<p>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 &#8220;session1&#8221;.\u00a0 Remember that all drivers MUST have a unique session name.<\/p>\n<p>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<\/p>\n<p><em><strong>send head,class,type,obid,time-stamp,GUID,data1,data2,data3&#8230;<\/strong><\/em><\/p>\n<p>you <a href=\"http:\/\/www.vscp.org\/docs\/vscpd\/doku.php?id=vscp_daemon_tcp_ip_protocol_description#send_-_send_an_event\">can read mode here about this format<\/a> used n the TCP\/IP interface of the VSCP daemon among other places.<\/p>\n<p>But now we want to send just a number and get a VSCP events. So for this we use the simplify feature again.<\/p>\n<p>We start out just as above by specifying the SIMPLIFY variable.\u00a0 As you see we now referee to the first driver entry MQTT1<\/p>\n<p><em><strong>&lt;variable type=&#8221;string&#8221;&gt;<\/strong><\/em><br \/>\n<em><strong>\u00a0\u00a0 &lt;name&gt;MQTT1_SIMPLIFY&lt;\/name&gt;<\/strong><\/em><br \/>\n<em><strong>\u00a0\u00a0 &lt;note&gt;Allow for sending plain numbers &lt;\/note&gt;<\/strong><\/em><br \/>\n<em><strong>\u00a0\u00a0 &lt;value&gt;1060,6,0,1,0,0&lt;\/value&gt;<\/strong><\/em><br \/>\n<em><strong> &lt;\/variable&gt;<\/strong><\/em><\/p>\n<p>Only 1060 is different than above, We could have used 1040 here alos to get <a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class2.measurement_str\">CLASS2.MEASUREMENT_STR<\/a> event but to be not to repetitive we use <a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class2.measurement_float\">CLASS2.MEASUREMENT_FLOAT<\/a> for this example.<\/p>\n<p>And using VSCP Works to check the incoming event gives the expected result<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-223204.png\" rel=\"attachment wp-att-1530\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1530\" data-permalink=\"https:\/\/grodansparadis.com\/wordpress\/?attachment_id=1530\" data-orig-file=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-223204.png?fit=1788%2C736&amp;ssl=1\" data-orig-size=\"1788,736\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Screenshot from 2016-02-14 22:32:04\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-223204.png?fit=580%2C239&amp;ssl=1\" class=\"alignnone wp-image-1530\" src=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-223204.png?resize=580%2C239\" alt=\"Screenshot from 2016-02-14 22:32:04\" width=\"580\" height=\"239\" srcset=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-223204.png?w=1788&amp;ssl=1 1788w, https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-223204.png?resize=300%2C123&amp;ssl=1 300w, https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-223204.png?resize=768%2C316&amp;ssl=1 768w, https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-223204.png?resize=1024%2C422&amp;ssl=1 1024w, https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-223204.png?w=1160&amp;ssl=1 1160w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>If we set\u00a0 <a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class2.measurement_str\">CLASS2.MEASUREMENT_STR<\/a> (1040) instead we got the same end result<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-223204-1.png\" rel=\"attachment wp-att-1531\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1531\" data-permalink=\"https:\/\/grodansparadis.com\/wordpress\/?attachment_id=1531\" data-orig-file=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-223204-1.png?fit=1788%2C736&amp;ssl=1\" data-orig-size=\"1788,736\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Screenshot from 2016-02-14 22:32:04\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-223204-1.png?fit=580%2C239&amp;ssl=1\" class=\"alignnone size-full wp-image-1531\" src=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-223204-1.png?resize=580%2C239\" alt=\"Screenshot from 2016-02-14 22:32:04\" width=\"580\" height=\"239\" srcset=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-223204-1.png?w=1788&amp;ssl=1 1788w, https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-223204-1.png?resize=300%2C123&amp;ssl=1 300w, https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-223204-1.png?resize=768%2C316&amp;ssl=1 768w, https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-223204-1.png?resize=1024%2C422&amp;ssl=1 1024w, https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-14-223204-1.png?w=1160&amp;ssl=1 1160w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><\/p>\n<p>And you can use one of the other measurement types also of course. Read the docs.<\/p>\n<p>Well that was it for this time.\u00a0 <a href=\"http:\/\/www.vscp.org\/docs\/vscpd\/doku.php?id=level2_driver_mqtt\">The full driver info is here.<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>VSCP MQTT Driver Simplify mode Part 1 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[53,13],"tags":[],"class_list":["post-1528","post","type-post","status-publish","format-standard","hentry","category-howtos","category-vscp"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4raCZ-oE","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1528","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1528"}],"version-history":[{"count":2,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1528\/revisions"}],"predecessor-version":[{"id":1542,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1528\/revisions\/1542"}],"wp:attachment":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}