<h2 id="setup">Setup</h2>
<p>For this tutorial you will need to sign up for a set of accounts:</p>
<ul>
<li><a href="https://shipiot.net/">Ship IoT</a></li>
<li><a href="http://control.littlebitscloud.cc/">LittleBits Cloud Control</a></li>
<li><a href="http://slack.com">Slack</a></li>
</ul>
<p>You will also need to acquire a <a href="http://littlebits.cc/bits/cloudbit">CloudBit</a>, based around a Freescale i.MX23 ARM 926EJ-S processor, from <a href="https://littlebits.cc">LittleBits</a>. The parts we will use for this tutorial are:</p>
<ul>
<li>a 5V 2amp USB power supply</li>
<li>a micro USB cable</li>
<li>p3 usb power</li>
<li>i3 button</li>
<li>w20 cloud</li>
<li>o9 bargraph</li>
</ul>
<p>They should be assembled in series as follows:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/littlebits.JPG" alt="" /></p>
<p>Instructions for connecting the Cloudbit to your local WiFi network for the first time can be found on the <a href="http://littlebits.cc/cloudstart">Cloudbit Getting Started page</a>. If you have already setup your Cloudbit, you can change the WiFi settings by going to <a href="http://control.littlebitscloud.cc/">your Cloudbit's page</a> and going to Settings and selecting the following option:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/Screen-Shot-2015-07-21-at-4-46-56-PM.png" alt="http://control.littlebitscloud.cc/" /></p>
<p>If you don't already have a Slack account, you can <a href="https://slack.com/create">create a new team</a> and setup your own #littlebits channel for testing:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/Screen-Shot-2015-07-21-at-4-50-57-PM.png" alt="" /></p>
<p>So by now, you have signed up for <a href="https://shipiot.net/">Ship IoT</a>, have a <a href="http://littlebits.cc/bits/cloudbit">CloudBit</a> sitting on your desk, a <a href="http://slack.com">Slack</a> channel, and are wondering <em>what's next?</em></p>
<h2 id="creatingourfirstbip">Creating our first Bip</h2>
<p>When you first <a href="https://shipiot.net">Sign In to Ship IoT</a>, you will encounter a friendly green button that looks like this:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/Screen-Shot-2015-07-21-at-5-00-43-PM.png" alt="" /></p>
<p>Clicking that button will take you to a blank canvas onto which you can install an Event Source:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/blank.png" alt="" /></p>
<p>By clicking on the target in the middle, you will be presented with an Event selection screen:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/eventsource.png" alt="" /></p>
<p>We'll select "Incoming Web Hook" to provision a URL to which our CloudBit will send messages. In the field that say "Untitled":</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/Untitled.png" alt="" /></p>
<p>Enter a path of "littlebits" for our Event Source, and we <br /> should now have an event trigger on our canvas:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/trigger.png" alt="" /></p>
<p>Next we will "Add An Action" which will bring us to an action selection screen:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/actionselect.png" alt="" /></p>
<p>If you scroll down a bit you will find a Slack pod which we can activate. Your first time through, it will request you to sign into your Slack account and authorize Ship IoT to access your Slack account. In the background it will provision a new access token and send you an email notifying you of that. In the future, you can deactivate this token through the Slack interface.</p>
<p>After you have activated the pod, you will be asked to select an action to perform:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/postmessage.png" alt="" /></p>
<p>In this case, our only option is to "Post to Channel". Selecting this action will result in another node in our bip:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/two.png" alt="" /></p>
<p>Double click on the Slack icon to open up the action's preferences:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/options.png" alt="" /></p>
<p>We can give the bip.io bot a name of "LittleBits":</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/botname.png" alt="" /></p>
<p>We can select the "Channel ID" either using the "Use Preset" button which will attempt to discover the list of channels you have created, or you can supply a custom channel id:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/customchannel.png" alt="" /></p>
<p>Finally, we need to specify the "Message Text", and for this we will send the full message sent by the CloudBit by selecting "Incoming Web Hook Object":</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/msgtxt.png" alt="" /></p>
<p>After clicking OK, we can now link these together by dragging and dropping from the purple Event Source to the Slack action:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/draganddrop.png" alt="" /></p>
<p>Now whenever a message is sent to <a href="https://yourname.api.shipiot.net/bip/http/littlebits">https://yourname.api.shipiot.net/bip/http/littlebits</a> it will be sent to our "Post to Channel" action!</p>
<p>Well not exactly. We still need allow LittleBits to send us messages. Under the "Auth" header, we can change the authentication type to "None":</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/none.png" alt="" /></p>
<p>Turning off auth makes our URL a shared secret that we should only share with LittleBits. Anyone with that URL will be able to send messages to our Slack channel, so some care should be taken not to share it!</p>
<h2 id="configuringalittlebitssubscription">Configuring a LittleBits Subscription</h2>
<p>Configuring your CloudBit to talk to bip.io requires using the command line for a little bit. First we will need a little information from our <a href="http://control.littlebitscloud.cc/">Settings panel</a>:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/cloudbitsettings.png" alt="" /></p>
<p>We will need to record both the Device ID and the AccessToken. These are needed to setup the subscription to our bip.iob application.</p>
<p>To setup a subscription requires a bit more black magic on our part. The <a href="http://developer.littlebitscloud.cc/">CloudBit API Documentation</a> describes how to make a HTTP request to register our device with a 3rd party subscriber. In our case, we would like to register our Incoming Web Hook URL as a subscriber to our CloudBit. To do so, we'll write a small bash shell script use <a href="http://curl.haxx.se/docs/manpage.html">curl</a> in a script we'll name "subscribe":</p>
<blockquote>
<p>#!/bin/bash</p>
<p>DeviceID=$1</p>
<p>AccessToken=$2</p>
<p>URL=$3</p>
<p>EVENTS=$4</p>
<p>curl -XPOST \</p>
<p>-H "Accept: application/vnd.littlebits.v2+json" \</p>
<p>-H "Authorization: bearer $AccessToken" \</p>
<p><a href="https://api-http.littlebitscloud.cc/subscriptions">https://api-http.littlebitscloud.cc/subscriptions</a> \</p>
<p>-d publisher_id=$DeviceID \</p>
<p>-d subscriber_id=$URL \</p>
<p>-d publisher_events=$EVENTS</p>
</blockquote>
<p>To use this script we need only make it executeable and run it:</p>
<blockquote>
<p>$ chmod u+x subscribe</p>
<p>$ ./subscribe yourDeviceId yourAccessToken yourUrl "amplitude:delta:ignite"</p>
</blockquote>
<p>This will cause the the URL you supply to be contacted each time the amplitude changes from low to high. If you want to have the value periodically reported instead you can just use the value of "amplitude" to get a message roughly every 750ms.</p>
<p>If the script works you will get a message back like:</p>
<blockquote>
<p>{"publisher<em>id":"xxxxxxxxxx","subscriber</em>id":"<a href="http://yourname.api.shipiot.net/bip/http/littlebits">http://yourname.api.shipiot.net/bip/http/littlebits</a>","publisher_events":[{"name":"amplitude:delta:ignite"}]</p>
</blockquote>
<p>This means your subscription has been registered and events are now flowing through the system.</p>
<h2 id="testingitout">Testing it out</h2>
<p>If you push the button now:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/push.JPG" alt="" /></p>
<p>A message should show up in your #littlebits channel:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/slackoutput-1.png" alt="" /></p>
<p>You can use this same technique to drive any number of workflows through bip.io. All at the press of a button.</p>
Ship IoT with LittleBits and bip.io
Jul 2015/ Posted By: wotio team