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...
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.
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.
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...
And then...
And then...
And then...
And then...
And then...
And then...
And then...
And then...
And then...
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
And then...
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).
If you did not add credentials then it will ask you for em. Enter a password to be used with MQTT.
You should be able to see the above.
Next we need to activate it...
Click click click and then...
You should end up with somthing like this...
Clicking on the app will take you to...
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...
Save and in your node command prompt...
That worked... right?
On the airvantage site, we refresh and then...
Click on one of the buttons to see a graph like...
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
EDIT1. Since I could not attach a .js, the script is given below.
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();
The BBB.app 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>
Top Comments