Tutorial on setting up Sierra Wireless Air Vantage with your Custom IoT Device

Prelude

The challenge is to create a system for air quality sensing which can operate without human intervention. My idea is to create a system that can measure air quality indoors and outdoors and log this data to the Sierra Wireless System. For the indoor unit, I have a CC3200 power unit which can measure temperature and an MICS5524 sensor which can measure air pollutants and connects to the cloud over wifi. It is powered by the TI Fuel Booster Pack and charged wirelessly with the Wurth Electronics Wireless Charging System. All parts are TI and Wurth Electronics.

The second outdoor unit is made up of the FR5969 Launchpad and uses the Alphasense Sensor for SO2 measurements and a Dust Sensor to measure particulate matter. This data is transmitted via CC2500 modules wirelessly to the BeagleBone Black which also has a CC2500. The BBB acts like a gateway device and sends the data to the Sierra Wireless Cloud via Wifi. This can be expanded to include more nodes to connect to this gateway and will allow future work to be done.

In addition to this functionality, I created a small board that can harvest solar energy and store it in a Li-Po battery. BQ25504, TPS61200 and TPS62740 are used to create a power harvesting circuit and the details are explained.

In this post I present a tutorial on how you can get started with using Sierra’s Air Vantage Cloud Storage system.

Introduction

One of the sponsors is Sierra Wireless who provide cloud based services for embedded devices and gateways. In the world of IoT, devices connected to the Internet can be easily managed using platforms like Air Vantage where devices can send their status like health, signal strength and other diagnostic info and a bulk of devices can be monitored easily from a single online point. Alerts can be generated as well as action can be taken for IoT Gateways. As a thanks to our sponsors, I wanted to create a graphical tutorial which lets ‘developers’ and ‘hackers’ to create their own little system and I found out a little late that there is already a tutorial on the subject at https://doc.airvantage.net/display/USERGUIDE/Using+MQTT+with+AirVantage

A lot of discussion has also happened on the topic as well so I offer my two cents worth here.

The objective is to setup Air Vantage Cloud services for MQTT and then connect to it via an embedded device. In this tutorial I use NodeJS BUT the script runs on my PC to demonstrate portability of the code. I have been able to run the same code on the BeagleBoneBlack and the snippets have been modified according to the instructions given at https://doc.airvantage.net/display/USERGUIDE/Enable+BeagleBone+Black+With+AirVantage+using+MQTT

Setting up Air Vantage

This tutorial is very graphic hence viewer discretion is advised What that means is that most of the tutorial is in screenshots and quite self explanatory.

Setup the App

When you login for the first time, you see…

556e97919a6fb05277dd025062b4cdb7.jpg

The first thing we need to do is create something called an APP. This will basically define how data is communicated which in our case is via MQTT. Additionaly we define variables that will be used in the communications.

In my case, I am sending temperature, Dust and Hydrogen Sulphide Concentration in this instance. I have a different system which sends temperature and VOCs but that’s a different tutorial since the code is in cpp. Here is how you do it.

e8c50d3360f6a4d392aaf6951f83a583.jpg

Next we need an APP. I am attaching mine at the end of the tutorial but feel free to type up yours or modify the given file which looks like.

0af38b33595882a5c42bd9f2bb9f2f1c.jpg

In the data section, remember to note the asset ID and variable paths. These will later on be used like…

BeagleBoneBlack.temperature etc where BeagleBoneBlack is my ‘id’ specified here. Put it in a zip file by any name. Next…

3a2d60ac620e4581c8e015b08a1d047b.jpg

And then…

306eeafd7e742ddd1ff809e411dc62fb.jpg

And then…

f749f434869e3d635e00573849c76755.jpg

And then…

871e998f1f988f034dcacaa3d28e19cf.jpg

And then…

e01b54199eabd57e5ee5b2fa38fe262a.jpg

And then…

c99ef1f9c7612b353c2bff629c31da75.jpg

And then…

c2e944a650ca7bec81df04e0760ad88a.jpg

And then…

aad733fadd34fc2d24870b30fa6cbcc1.jpg

And then…

e928c2e9161de97232a932cc708fe70e.jpg

And then…

fe14fe264e6542aa1e13d48988707591.jpg

And then…

You are done with setting up the basic APP! Great

Setup the gateway

The next thing to do is set up the gateway. The app is released but not published hence we need to create credentials to allow login and post data. This is pretty simple.

In the inventory section we currently have no systems… so click click click

6197d9dcad9e9a4527304c9886247bd4.jpg

And then…

d0d0cd8462668bf95dbcd856c9748e6a.jpg

We need a name and in the gateway section enter your BBB serial Number. This is just a unique identified and since I am using a PC, I just used a random sequence. For the Applications, we already have one and when you select the drop down, you should see some familiar name(s).

77f2a11e27a8b692a140dabacc4922ab.jpg

If you did not add credentials then it will ask you for em. Enter a password to be used with MQTT.

4ab92cd1423bd2f0ea4cc2689ea4a7af.jpg

You should be able to see the above.

Next we need to activate it…

7757aa752d91491f8cdb6e84244bd4c5.jpg

0d6734b1271206013c25ef0bf05be33a.jpg

Click click click and then…

You should end up with somthing like this…

1328b0e4e1d05ed7cb6f58f16dc531e2.jpg

Clicking on the app will take you to…

d9e34868fe28e92e4ba83c893177d28b.jpg

So we have no data. BUT we can see our variables. Excellent. Now to push some data onto it.

Meet NodeJS

For those who don’t know what NodeJS is, it javascript that runs without a browser. You can run simple scripts and with the help of libraries you can access GPIOs and connect to the internet. With more libraries, we can even create a webserver entirely on NodeJS(See NodeJS and Express if interested). All we want here is to use MQTT with a little JS since the BeagleBoneBlack can run JS from the Cloud9 IDE. I want to do my development on my 100year old PC since it generates a lot of heat and its still winter here

I have installed NodeJS on my PC and have created a folder to work in.

In a NodeJS Command Prompt with NPM setup, I navigate to the folder where I want to develop the things.

Step 0.

This is not mandatory but I create a NodeJS package so that every time someone uses it, the dependencies are automatically installed as well. Type..

npm init

Enter the name and revision and author name. The entry point is by-default the name of the folder but make sure you name your .js script with the name entered here. Leave the rest blank and enter yes at the end.

Step 1.

Install mqtt if not already installed by typing..

npm install mqtt –save

the –save saves the version of mqtt library being used.

Step 2.

Create the script with the name used as entry point. Mine looks like this…

73ef4a9c8a28d7a003614efaf0d173ea.jpg

Save and in your node command prompt…

5b3b9957b47c7396fff5c8d2739271f6.jpg

That worked… right?

On the airvantage site, we refresh and then…

d011d9b7b1af79e88312c85167141194.jpg

Click on one of the buttons to see a graph like…

f95f6b2392a10a4b6fd0a62772dc51fb.jpg

Success!

Conclusion

This is just the tip of the iceberg and I just took longer to do a simple thing. I hope this tutorial is helpful for those who wish to use the airvantage platform and they get a running start. If it was helpful, say hi and gimme a pingback. If there is something I missed, lemme know and I will do the needful.

Thanks,

IP

The BBB.app code is

<?xml version="1.0" encoding="ISO-8859-1"?>
<app:application xmlns:app="http://www.sierrawireless.com/airvantage/application/1.0"
        type="com.wordpress.embeddedcode.bbb"
        name="In The Air App for BBB"
        revision="0.0.2">
  <capabilities>
  
    <communication>
      <protocol comm-id="SERIAL" type="MQTT" />
    </communication>
    
    <data>
      <encoding type="MQTT">
        <asset default-label="BeagleBoneBlack" id="BeagleBoneBlack">
          <variable default-label="Temperature" path="temperature" type="double"/>
          <variable default-label="Dust" path="dust" type="double"/>
   <variable default-label="HydrogenSuplhide" path="hydrogensulphide" type="double"/>
        </asset>
      </encoding>
    </data> 

  </capabilities>
</app:application>

And the code for the NodeJS script is

var mqtt = require('mqtt');
var port = 1883;
var server = "na.airvantage.net";
var serialnumber = "3713BBBK7777"; //serialnumber
var password = "Make your own password";

var mqtt_options = {username: serialnumber, password: password};


// I know 'createClient' is depreciated but it has a lot of examples for it. 
var client = mqtt.createClient(port, server, mqtt_options);

console.log("Client started");


//Send values
console.log("Sending value");

//Publish a message on the right topic
var payload= {};
var timestamp = new Date().getTime();

payload[timestamp] = { "BeagleBoneBlack.temperature": 16.2, "BeagleBoneBlack.dust": 10.0, "BeagleBoneBlack.hydrogensulphide": 2.0 };
client.publish(serialnumber + '/messages/json', JSON.stringify(payload));


console.log(payload);
console.log('Done');
client.end();
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s