Blog

Using wot.io protocol adapters with node-red

Nov 2015/ Posted By: wotio team

<p>One of the great tools available to developers who use the wot.io Data Service Exchange is the protocol adapter framework. The wot.io protocol adapters make it possible to take existing applications which speak a given protocol, and use them to generate new data products. The wot.io Data Bus allows for exchanging these data products across multiple protocols in real time, making it easy to share data across services and customers.</p>
<p>Currently, the wot.io Data Service Exchange protocol adapters have production support for HTTP, WebSockets, MQTT, CoAP, AMQP, TCP, and UDP. Labs also experimental support for JMS, ZeroMQ, STOMP, XMPP, DDSI-RTPS, and JDBC currently in development. In addition to the open standard protocols, the DSE also has application specific adapters for various databases, search engines, logging systems, and the like.</p>
<h3 id="asampleapplications">A sample applications</h3>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/protocoladapterarch.png" alt="" /></p>
<p>To see how these protocol adapters work in conjunction with applications, we'll create a simple node-red flow that will publish a stream of 5 messages per second across MQTT to the wot.io Data Bus. This feed with then be replicated and split into two separate output streams to clients using CoAP and WebSockets at the same time.</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/Screen-Shot-2015-11-11-at-3-23-36-PM.png" alt="" /></p>
<p>The node-red flow for our example application consists of five nodes:</p>
<ul>
<li>an inject node to start the flow of messages</li>
<li>a function node which generate the message payload</li>
<li>a delay node in a feedback configuration to generate 5 messages per second</li>
<li>a debug node to display the output in the node-red console</li>
<li>a MQTT node to send the messages to the Data Bus</li>
</ul>
<p>The data can be read off the wot.io Data Bus using off the shelf applications such as <a href="https://www.npmjs.com/package/coap-cli">coap-cli</a> and <a href="https://www.npmjs.com/package/wscat">wscat</a>. While I happened to use command line tools for this application, it is easy enough to use standard libraries like the CoAP libraries provided by ARM in mbed OS, or even your favorite web browser.</p>
<p>To see this application in action, please watch the following video:</p>
<p><iframe src="https://www.youtube.com/embed/6n4OPbTNlNY" frameborder="0" width="560" height="315" allowfullscreen="allowfullscreen"></iframe></p>
<p>In the above video, I show the creation of three wot.io Data Bus resources:</p>
<ul>
<li>wot:/wot/narf</li>
<li>wot:/wot/coap</li>
<li>wot:/wot/ws</li>
</ul>
<p>The names of these resources allow you to identify them across protocols. There is nothing intrinsically magical about any of these names, and any protocol can read or write to any of the resources. It is the URLs of each of the application connections:</p>
<ul>
<li>mqtt://token@host:port/account/resource</li>
<li>coap://token@host:port/account/resource</li>
<li>ws://token@host:port/account/resource</li>
</ul>
<p>that determines how the data is translated between encapsulation layers. The creation of resource bindings as demonstrated in the video, also provides a means to duplicate and route data between resources. The wot.io data bus routing supports filtering payloads based on regular expression matches, as well as hierarchical pattern matches. These advanced features are accessible through the protocol adapters, as well as, through the wot.io command line tools.</p>
<p>Since each Data Bus resource is addressable through all of the protocol adapters and the application adapters, it is possible to mix and match data making it both available to consumers of a data product, as well as, making it available for internal storage, processing, and analysis through applications made available as part of the Data Service Exchange. Each Data Bus resource has individualized access controls, with each type of resource operation (reading, writing, creating, deleting, binding, etc.) being controllable through policy. These access controls allows developers using the wot.io Data Service Exchange to make available some or all of their data to interested parties. With the protocol adapter framework in place, the wot.io Data Bus makes it easy to provide your customers with their data through what ever protocol they choose for their application.</p>