Blog

Smarter Cities with ThingWorx, scriptr, bip.io, Elasticsearch, and wot.io (part 3)

Dec 2015/ Posted By: wotio team

<h2 id="dataserviceproviders">Data Service Providers</h2>
<p>In <a href="/mwc-arm-devices-open-data/">part 1</a> of this series, we went over the various <a href="http://arm.com">ARM</a> devices that were combined with open data from the <a href="http://data.london.gov.uk/">London Datastore</a> to represent the connected device side of our demo. In <a href="/smart-cities-with-iotx-arm-mds/">part 2</a>, we described how to use employ one or more device management platforms like <a href="http://www.stream-technologies.com/iotx/">Stream Technologies IoT-X Platform</a> or <a href="https://www.mbed.com/en/development/cloud/mbed-device-server/">ARM mbed Device Server</a> to manage devices and send their sensor readings onto the wot.io data service exchange&trade;.</p>
<p>Now, let's see how we can route all that valuable device data to some data service providers like <a href="http://scriptr.io">scriptr</a>, <a href="http://thingworx.com">ThingWorx</a>, and <a href="http://elastic.co">Elasticsearch</a> to extract or add business value to the raw IoT data streams.</p>
<h2 id="dataflowreview">Dataflow Review</h2>
<p>Recall that back in <a href="/mwc-arm-devices-open-data">part 1</a> we started with the <a href="http://multitech.com">MultiTech</a> model car, modified to include a <a href="http://www.multitech.com/brands/multiconnect-mdot">MultiConnect&reg; mDot</a> LoRaWAN module with an accelerometer sensor. The sensor sent the accelerometer data to a MultiTech <a>MultiConnect&reg; Conduit&trade; gateway</a> using the Semtech LoRa&trade; low-power, long-range wireless RF interface. The Conduit was registered with <a href="http://www.stream-technologies.com/iotx/">Stream's</a> IoT-X platform.</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/mdot2wotios.png" alt="" /></p>
<p>Since wot.io is fully integrated with IoT-X, making the device data available on the wot.io exchange where it could be sent to any of the data services was as easy as setting up the data routes.</p>
<h2 id="scriptrforbusinesslogic">scriptr for Business Logic</h2>
<p>Part of the reason for measuring the accelerometer readings in the smart vehicle was to detect if it has been involved in an accident. Some of the numerous and obvious opportunities for such intelligence include insurance, emergency response dispatch, traffic routing, long term traffic safety patterns, etc.</p>
<p>However, in order to translate the raw sensor readings into that business intelligence, we have to determine whether there was a sufficiently rapid deceleration to indicate an accident.</p>
<p>Of the many wot.io data services that could be employed, <a href="http://scriptr.io">scriptr</a> is an excellent choice for embodying this type of business logic.</p>
<p>scriptr is a cloud-based, hosted JavaScript engine with a web-based Integrated Development Environment (IDE). Since we can route wot.io data streams to specific scriptr scripts, we can use it to write our simple deceleration filter:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/Screen-Shot-2015-12-08-at-4-33-42-PM.png" alt="" /></p>
<p>Notice that the script receives our messages containing the raw X,Y,Z-plane acceleration readings. After parsing these parameters, we do a simple check to determine whether any of them exceed a given threshold. If so, we return a cheeky message back onto the wot.io data service exchange.</p>
<p>Notice that the the message we returned is a simple JSON object (although it could have been anything--XML, plain text, or even binary data). Furthermore, it does not contain any information about the destination. It simply returns a value.</p>
<p>That is, our script does not need to know where its response will be routed. Indeed, it may be routed to multiple data services! Loosely coupling data services together in this fashion makes for a much more flexible and resilient architecture.</p>
<h2 id="bipioforwebapiautomation">bip.io for Web API Automation</h2>
<p>Next, we chose to route any warning messages returned from our scriptr script to a <a href="http://bip.io">bip.io</a> workflow (known as a "bip") that we named <code>tweet</code> so that we could notify the appropriate parties of the "accident". Although we called it <code>tweet</code>, bip.io bips can easily perform complex workflows involving any of its 60+ data service integrations (known as "pods").</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/Screen-Shot-2015-12-08-at-4-43-45-PM.png" alt="" /></p>
<p>For the demo, we kept our bip simple, consisting of only twitter and email pods. But you can readily imagine how, given the conditional logic and branching capabilities of bip.io, much more complex and interesting workflows could be created with ease. For example, device events could be stored and visualized in <a href="http://keen.io">keen.io</a>, sensor data could be appended to a <a href="https://www.google.com/sheets/about/">Google spreadsheet</a> involving complex functions and charts, or SMS messages could be composed into a template and texted via SMS through <a href="http://twilio.com">Twilio</a>.</p>
<p>Since we authenticated the Twitter pod through our wot.io developer account <a href="https://twitter.com/wotiodevs">@wotiodevs</a>, whenever the data from the accelerometer is determined by scriptr to have exceeded the safety thresholds, we can see our tweets!</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/Screen-Shot-2015-11-30-at-4-38-22-PM.png" alt="" /></p>
<h1 id="thingworxasanapplicationenablementplatform">ThingWorx as an Application Enablement Platform</h1>
<p><a href="http://thingworx.com">ThingWorx</a> is a full-featured IoT platform that enables users to collect data from a variety of sources and services and build out applications to visualize and operate on that data.</p>
<p>In our case, we took the real-time location data originating from the mobile devices being managed by Stream's IoT-X and ARM's mbed Device Server platforms and routed them through the wot.io data service exchange to our visualization, or mashup application, in ThingWorx.</p>
<p>We also routed traffic camera and traffic sign data from the <a href="http://data.london.gov.uk/">London Datastore</a> through wot.io and into the same ThingWorx mashup.</p>
<p>To make the data useful, in our mashup we included a Google Map widget and then in real-time, we plot each mobile device, camera, sign with a different icon based on their current locations.</p>
<p>Users can interact with any of these data points: clicking on a camera icon, for example, will display an image of what is actually being captured by that traffic camera at the given intersection. Below, I selected a camera that is located on the River Thames and has the Tower of London with Big Ben in its view!</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/Screen-Shot-2015-11-30-at-4-56-20-PM.png" alt="" /></p>
<p>While it's fun to sight see around London, in a Smart City, we can also imagine ways to use these cameras and digital signs to help us efficiently move assets (usually vehicles!) through a congested downtown area. For example, if we zoom into a traffic heavy portion of London, we can view the camera feeds and digital roadsigns in an area. Here, we can see that this sign's text currently displays a message that this route is closed for resurfacing.</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/Screen-Shot-2015-11-30-at-5-01-01-PM.png" alt="" /></p>
<p>And the camera in the area even shows how traffic cones are being set up to move traffic away from the roadwork!</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/Screen-Shot-2015-11-30-at-5-01-06-PM.png" alt="" /></p>
<p>And since we already know that with wot.io, messages can be routed to multiple data services as easily as to a single service, displaying the messages on a map is hardly the end of the story. Just as one trivial example, imagine correlating the timing and text and locations of digital signs with the resulting traffic disruptions to optimize how best to announce construction work.</p>
<h1 id="elasticsearchkibana">Elasticsearch &amp; Kibana</h1>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/Screen-Shot-2015-12-08-at-9-31-59-AM.png" alt="" /></p>
<p>Finally, we also routed the telemetry messages from all those cellular, satellite, and LPRN-based mobile devices embedded in vehicles traveling around the city of London through wot.io and into an instance of <a href="http://elastic.co">Elasticsearch</a> and <a href="https://www.elastic.co/products/kibana">Kibana</a> to create a real-time heatmap visualization of the number of managed devices by geographic region.</p>
<p>Elasticsearch is a powerful, distributed, real-time search and analytics engine. Traditionally applied to numeric or textual data (as we have discussed <a href="/tag/elasticsearch/">previously</a>), Elasticsearch also shines in geospatial indexing scenarios as well. In this case, our histogram is colored based on the number of devices currently reporting in each geographic subregion.</p>
<h1 id="conclusion">Conclusion</h1>
<p>As London and other major cities begin to connect, open, and share all the data their IoT devices collect, wot.io allows for the creation and extraction of real, actionable business value from that data.</p>
<p>Whether through its many options for device management platforms from the likes of <a href="http://www.arm.com">ARM</a> and <a href="http://www.stream-technologies.com">Stream Technologies</a>, or its support for any of the hardware devices through numerous protocol adapters, or its support for web-based data feeds like the <a href="http://data.london.gov.uk/">London Datastore</a>, or its ability to flexibly route data to multiple data services like <a href="http://scriptr.io">scriptr</a>, <a href="http://bip.io">bip.io</a>, <a href="http://www.thingworx.com">ThingWorx</a>, or <a href="http://elastic.co">Elasticsearch</a>, wot.io is clearly <em>the</em> data service exchange&trade; for connected device platforms.</p>
<p><em>London Knightsbridge Street Photo Credit: By Nikos Koutoulas [<a href="https://creativecommons.org/licenses/by/2.0/">CC BY 2.0</a>], via <a href="https://flic.kr/p/ea2jy1">Flickr</a></em></p>