Skip navigation
1 2 Previous Next

In the Air Design Challenge

24 Posts authored by: xever


Before anything else, I would like to personally thank the organisers and sponsors of this challenge, and kudos to doctorcdf for the great support and ironing out issues around some duties on the kits.  This challenge has been really an exciting and productive experience.


Previous Posts

Setting up the development environment

MSP430 Development in VisualStudio

CC3200 Development in Visual Studio

BeagleBone + node.js + Visual Studio


Carbon Footprint Monitoring - Architecture

Carbon Footprint Monitoring - Sensor Nodes

Carbon Footprint Monitoring - Data Flow


Carbon Footprint Monitoring - Hardware Design

Carbon Footprint Monitoring - Printed Circuit Boards

Carbon Footprint Monitoring - Power Supplies

Carbon Footprint Monitoring - Hardware Mods

System Components

Central Hub

Carbon Footprint Monitoring - BeagleBoneBlack Quick Recipe

Carbon Footprint Monitoring - CC3200 Remote Debug Console

Emission Sensor

Carbon Footprint Monitoring - Emission Sensor

Carbon Footprint Monitoring - Emission Sensor Firmware

Carbon Footprint Monitoring - Calculating Car Emissions

Outdoor Sensor

Carbon Footprint Monitoring - Power Meter CT

Carbon Footprint Monitoring - Outdoor Sensor Enclosure

Carbon Footprint Monitoring - Interpreting Collected Data

Smart Plug / Smart Switch

Carbon Footprint Monitoring - Smart Switch/Plug

Carbon Footprint Monitoring - Smart Switch/Plug Test

Carbon Footprint Monitoring - Remote Switch/Plug Mobile Test

Cloud Platform

Carbon Footprint Monitoring - [kNow] more AirVantage

Carbon Footprint Monitoring - AirVantage REST Library

Mobile Application

Carbon Footprint Monitoring - Mobile Application

Carbon Footprint Monitoring - Mobile Application Auto Launch


Around four months ago, this design competition was kicked off with the objective of creating a solution using Internet of Things technology to sense the environment we live in and how IoT can help us build a cleaner and less polluted world. 

Reflecting on the question:

"How would you use the amazing products below to help create a cleaner, more breathable world?" -from link


And so I thought one possible way to achieve this goal is for everyone's little contribution in reducing greenhouse gas emissions. 

Currently , there are already a number of initiatives and regulations promoting the reduction of carbon footprint that mostly adopted by commercial/industrial companies around the globe.  However, it should not stop there.  With all the advancement in technology, it is now more economical to build devices that can be installed for residential applications, such as the one being proposed here: a real-time carbon footprint monitoring system, to provide awareness about the households carbon footprint and is the first step towards the reduction of CO2 emissions.  Then we can all contribute to this goal of transforming our world into a healthier place to live in.


As with anything that is to be built, the blueprint for the system was first laid out, followed by foundation laying, then building the design closely to the initial plan but allowing for modifications and slight detours along the way.  This approach has always been the practice I've used in creating a working minimum viable product.  This approach will be discussed into a bit more detail in the next sections.


During the first few weeks of the challenge and while waiting for the development kits to arrive, I started off thinking about the high level architecture which is simple and straightforward.  The image below depicts the high level architecture of the system.  Also, during this period, and since knowing the key components of the system, the software development environment were installed and configured.



From the high-level architecture, the features for each component were drafted and again another thought process about how to build a solution given the constraints of the challenge, i.e. must use provided kits and tools, limited time and budget, and the like.  For this process, pen and paper works best for me.  


Hardware Design

Pen and paper design yields to some hardware blocks and from each block the key components are identified and checked if they would meet the requirements for the system.  Datasheets, application notes and reference schematic diagrams are used to draw the schematic and design the PCB.  While the waiting for the PCBs to be manufactured and delivered, the task was shifted into some software development.



Software/Firmware Development

The key components for the system (firmware) are from Texas Instruments: CC3200 Launchpad XL, MSP430FR5969 Launchpad, and the Beagle Bone Black.  This is the first time I've worked on the CC3200 and MSP430 devices.  The very good documentation and lots of sample programs made firmware development a breeze.  It was more like building a Lego house and merely selecting which block components are necessary.  For the firmware, this was mostly the GPIO control, ADC sampling, I2C and SPI sample programs.  However for the CC3200, the TCP Socket was the most useful as it was the key for the sensor node talk to the central hub (Beagle Bone Black).


For the central hub application, this is not the first time I've used the BBB, but feeling a bit adventurous, I decided to use node.js as the coding language.  This was outside my comfort zone but thought that this is one of the unique features of BBB and was a good opportunity to brush up some node.js skills.


For the cloud platform, Sierra Wireless' AirVantage was also new to me.  The documentation is comprehensive and very much helpful.  Although, I was stuck at one point and almost gave up on AirVantage, thanks to the guys, they helped me out resolved the blocking issue.  This was a really great experience with this whole challenge, and I commend both amgalbu and tomaja for reaching out.  To give back to the community, I wrote two helper libraries to easily connect, send and receive data to AirVantage.  These libraries and other source code put as attachments hopefully will become useful to someone at some stage.


Lastly, the mobile application was written to close the loop (of a minimum viable product).  During a series of test and use of the mobile app (CO2 emission tracking), an issue was identified such that manually launching the app may be forgotten and the trip will not be monitored or will be monitored late in the trip.  This was resolved by automating the process.  That is, using a pre-programmed NFC sticker placed in the phone holder, the mobile app is automatically launched and started when the phone is placed in the holder.  This was never planned out in the beginning but imo was a great feature creep. 


Challenges and Limitations

There are a lot challenges along the way that some of them ended up into frustration and uninspiring.  Challenges such as delayed components, hardware failures, missing information, buggy software and drop date deadline are typically experienced even in larger companies.  To me though, time management is the greatest challenge.  I have to balance the time between family, work, Christmas holiday, and this project.



I am quite happy with the outcome of this challenge.  With the limited time, I was able to build a basic yet functional prototype that would monitor my daily carbon footprint.  Knowing how much is the start for me to identify areas where I could reduce this footprint.  As an example on how to reduce the footprint, idling is a big waste of energy and is usually caused by heavy traffic.  Thus, it becomes more economical and more environmentally friendly to travel when traffic is light (already a known fact).  However, using historical data, we can create algorithms to "learn" and forecast when traffic is lighter in a given week.  i.e. Mondays always have heavy traffic from 7-9 but on Tuesdays through Thursdays, traffic is only heavy from 6:45 to 8:30.  We can then adjust our daily routines and be able avoid traffic on most days of the week.

Also, with the current data set recorded in the span of one week, I have few other ideas to make this even work better, i.e. base from the power usage data, it is possible to identify the activities inside the house at any given time.

Sierra Wireless' AirVantage is a big platform and I feel like I only scratched the surface and have not gone deep into its key features.


Not all features were implemented with the given time frame and even if they were, the system has a lot of areas which it can be improved on that are detailed below:

Emission Sensor Node

    • It would be nice to make use the MSP430, BLE and CO2 sensor as initially planned to measure actual emission.  Further research is needed to accurately relate the ppm value of the sensor to CO2 emission.
    • Install a digital fuel meter or connect through the CAN bus to accurately measure fuel consumption.
    • As an additional feature, using the recorded distance traveled and CO2 emission level (via sensor), the system can send notifications to the user that the vehicle must be serviced.

Smart Plug and Smart Switch

    • The power monitoring feature (via ACS712) needs to be implemented
    • Implement ambient light sensing for the smart switch implementation
    • Report humidity and temperature sensing to AirVantage
    • Re-spin a smaller hardware that will fit inside standard wall socket flush box

Outdoor Sensor Node

    • Re-spin hardware to support additional CT sensor (i.e. for monitoring hot water power usage)
    • Report rechargeable battery state/condition
    • Report BQ25504 charging status

Indoor Sensor

    • To be fully implemented
    • Add microphone and implement some sort of voice detection to identify presence

Central Hub

    • Create additional capes for the Beagle Bone Black to support additional communication mediums, i.e. ZigBee or RF, to support additional off-the-shelf sensors

Cloud Platform

    • This improvement is more for Sierra Wireless, some of them might be implemented but I haven't had the time to dig deeper, regardless these are nice to haves
    • It would be nice to support more data series on monitoring charts, atm, it can only do 3 series max
    • It would be nice to support other charts aside from the line chart, i.e support for bar graph and pie charts
    • It would be nice for charts to support presentation of DateTime or Timespan in charts
    • Possibly the most important one, it would be ideal if there are downloadable libraries that can be used for ease of interfacing with AirVantage.

Texas Instruments

    • My personal experience with TI has always been great and the plethora of documentation and samples is just the best, and can only think of a couple improvements
    • (1) have an alternative package for the HDC1000 sensor.  It being a BGA is a real challenge to for prototyping and reworking (if even possible without destroying the chip).  Another note about this sensor, I think at its price and performance ratio, it is one of the best out there.  Well done on this one TI!
    • (2) possibly a light-featured and cheaper version of the CC3200 that can compete strongly with other WiFI SoC just wishful thinking...


For the short period of time, a working Carbon Footprint Monitoring System has been designed and developed for this challenge and to end this post (but NOT the project, as development will continue outside the scope of this challenge)  I would like to answer the posed question:


"How would you use the amazing products below (TI, Wurth Electronics, Sierra Wireless etc) to help create a cleaner, more breathable world?"

By using the amazing and awesome products and parts in this challenge and build a carbon footprint monitoring system within the realms of IoT technology, can indeed help create a cleaner and more breathable world.  With this sort of system placed in every house across the globe, we will all be aware and become cautious on our carbon footprint.  Being aware is the first step towards changing our daily routines and habits.  The smallest reduction in CO2 emission will have a great contribution in this goal.


As an example, given the 7 billion world population, and if each individual would save roughly 1kg of CO2 per day (which is roughly about 6km of travel on a 12.5l/km car efficiency) results to 7 trillion grams (7 million metric tons) of CO2 reduction per day.  To put this into perspective, using the data presented in earlier post, if each ton roughly costs $336.01 then that would be roughly $2.352 quadrillion saved per day!!! That's a lot of zeros...

Today I took down the outdoor sensor to work on the smart plug and smart switch modules.  I've ordered a few more CC3200 modules but may not arrive in time, especially that this challenge ends tomorrow, but that does not mean further development stops with it as well.


Anyways, back to this post.  My goal is to be able to remotely turn on/off an appliance from my mobile, or be able to set some triggers, i.e. power usage goes above a specific threshold, that it will turn off non-critical appliances.  Another use case, would be to schedule when certain appliances are completely turned off (no more vampire appliances at night time).



Test videos embedded below.



(Above) testing using DHC tool to validate REST command.  (Below) testing using mobile application.


AirVantage Data



The stuff presented here is just the ground framework for the smart switch and smart plug modules.  Current monitoring and reporting using the ACS712 module needs to be implemented.  The module also needs to be enclosed, for safety as it controls AC supply.  Hopefully, the demo presentation is enough to illustrate the capabilities of the Smart Plug module.

The outdoor sensor module has been collecting data for the past few days now and am quite happy with the results.



From the graph of mains power consumption, aside from knowing how much electricity is used and the carbon footprint is, I was able to observe the following.

  • The peak on the 23 Feb at about 7pm was actually around dinner time and that peak would be possibly caused by the preparing the food and having a few friends come over.  At around 8pm that night, the consumption began to drop as people started leaving.
  • From 10pm of 23 Feb to about 5am then next day, power consumption is lower and has somewhat flat, indicating not much activity, we were all sleeping at this point.
  • 6 am 24 Feb, there is this spike again, people are awake and are getting ready for work and school.  After that, its pretty much flat across the day,  No one is at home during this period.
  • Last two days (25 and 26 Feb) are possibly our typical consumption.  25 Feb, consumption starts to drop around midnight, that's when I usually hit the bed and sleep, the power consumption drops and stays for while until around 4am, time to wake up and do a bit more design challenge stuff. 



By monitoring and analyzing power usage, we can identify causes of peaks, helping us in our decision making on how to further reduce energy consumption and lowering carbon footprint.  At the same time, from this historical data, the household behavior can be mapped out.


Mapping the household behavior can be a double-edged sword. The best part is knowing and relating what could possibly be happening at home while at the office, i.e. seeing some spikes around 3-4pm could mean the kids have arrived home from school.  But at the same time, if this data has been tapped by malicious individuals, it can be used to determine patterns at which the house is usually quiet (i.e. no one is at home) and posts security threats.

Continuing from the last post, I created a (Windows Phone) mobile application that is largely based from this article and modified for use with the proposed system.  The UI will be very simple and will display the core metrics as defined in AirVantage application model.



The key metrics that I wanted to capture are :

  • Current Speed
  • Distance traveled
  • Travel Time
  • Idle Time
  • CO2 footprint


The code logic for the application is pretty straightforward as outlined below.

mobile app.png

And translated as code below:

private void UpdateMetrics(Geocoordinate geocoordinate)
    int thisTick = Environment.TickCount;
    /* Update travel time */
    int tickLapsed = thisTick - _timeLastPositionChanged;
    _travelTime = _travelTime.Add(TimeSpan.FromMilliseconds(tickLapsed));

    double speed = geocoordinate.Speed.HasValue ? geocoordinate.Speed.Value : 0;

    /* Speed is reported in meters/sec */
    if(geocoordinate.Speed.Value < MIN_SPEED || geocoordinate.Speed.HasValue == false)
        /* speed is below minimum speed or has not been reported, this could indicate we are at idle */
        _idleTime = _idleTime.Add(TimeSpan.FromMilliseconds(tickLapsed));

    double travel = Haversine.Distance(
                        new Position() { Latitude = geocoordinate.Point.Position.Latitude, Longitude = geocoordinate.Point.Position.Longitude },
                        new Position() { Latitude = _lastGeocoordinate.Point.Position.Latitude, Longitude = _lastGeocoordinate.Point.Position.Longitude },

    _distanceTravelled += travel;

    double co2 = ((_distanceTravelled / KM_PER_LITER) * CO2_KG_PER_LITER);
    _co2 = co2;
    /* Update UI components */
    Map.Center = geocoordinate.Point;
    Speed.Text = "Speed: " + (speed * 3.6).ToString("0.0") + " kph";

    TravelTime.Text = "Travel Time: " + _travelTime.ToString(@"hh\:mm\:ss");
    IdleTime.Text = "Idle Time: " + _idleTime.ToString(@"hh\:mm\:ss");
    Distance.Text = "Distance: " + _distanceTravelled.ToString("0.0") + " km";

    if (co2 < 1)
        Co2Level.Text = "CO2: " + (co2 * 1000).ToString("0") + " gms";
        Co2Level.Text = "CO2: " + (co2).ToString("0.000") + " kg";         

    double distanceSinceLastRender = Haversine.Distance(
                new Position() { Latitude = _lastGeoPoint.Latitude, Longitude = _lastGeoPoint.Longitude },
                new Position() { Latitude = geocoordinate.Point.Position.Latitude, Longitude = geocoordinate.Point.Position.Longitude },

    /* add data point to map line */
    if (distanceSinceLastRender > 0.010)
        _mapLine.Path = new Geopath(_geoPositions);   
        _lastGeoPoint = geocoordinate.Point.Position;             

    _timeLastPositionChanged = Environment.TickCount;
    _lastGeocoordinate = geocoordinate;


As you may have observed, idle time starts ticking when the speed is below the minimum value of 10kph.  The distance traveled is calculated at each geographical position changed using Haversine formula.  CO2 level is calculated as described in previous post where KM_PER_LITER and CO2_KG_PER_LITER are set as 12.5 and 2.22 respectively.


When the Stop button has been tapped, the monitoring flag is reset and the data is sent to AirVantage.  Immediately after writing the code, I tested it by driving around the block, and verified the data has been successfully saved in AirVantage.


road test.PNG










Fascinated by the data, I started using the app today and monitored how much my footprint is when dropping the kids to school.

school drop off.PNG

Looking at this data, I spent almost 44% travelling in idle (10kph or less) most of it is due to traffic.  My average speed is 16.85kph on a 50kph road, seems like its better to cycle (if possible) during this time than travelling on car.  Also, 1.35kg of CO2 was produced for that particular trip, given 5 days of school x 2 trips per day x 10 weeks (ave) per term x 4 terms a year ends up 540 kg of CO2 annually!



As I was not able to track a couple trips to work using this app, I thought of automating the process such that the app will auto-launch when the phone is placed in the cradle.  This ensures that the application starts immediately at the beginning of each trip.  This was done by programming an NFC sticker that will launch the app and pass an argument.  The app has to be slightly modified as well to handle the argument.  A short clip has been added in this post to see how it works.



The other major contributor to Carbon dioxide footprint is transportation accounting for the 13% of global emissions in 2004.


For a typical household, transportation would be the second main contributor for carbon footprint and part of this system is to quantify and monitor how carbon dioxide we are emitting from our daily routines.


Measuring Carbon Dioxide


There are a number of ways to determine the amount of CO2 emissions, from simple approximations to actual measurements.  The simplest I found is just a multiplier of the vehicles' CO2 emission rating, usually in gram/km.  For my specific case, I am driving a Toyota Blade, and has a rating of 191 gram/km.  However, I am not quite satisfied about this method since the car can be idling most of the time, resulting in a shorter distance travelled but would actually emit more CO2 than a car travelling long distance but with minimal idle time.


Alternatively, but still using the vehicle information, this time labelled as L/100km, or the amount of fuel used (in Litters) per 100kms.  My car has this rating specified to be approximately 3.8L/100km or 26.3157 km per Litter of petrol used.  These values are mostly likely measured in controlled conditions and does not reflect the car's actual efficiency.  In reality, the efficiency is just 12.5 km/l as shown in my dashboard.


WP_20150223_001 (Medium).jpg


This link has a scientific method to calculate the theoretical value of how much CO2 is emitted during combustion arriving at 2.22 kg of CO2 per liter of Petrol.  By using actual vehicle efficiency of 12.5km/l and 2.22 kg of CO2 per liter of Petrol, we can resolve how much CO2 per distance travelled (in km), and call this as the CO2 emission factor:


CO2 Emission Factor = 2.22 kg/l ÷ 12.5 km/l = 0.1776 kg of CO2 per kilomter or 177.6 gram/km.


Carbon Footprint and Idling



The infographic on the left illustrates the effects of idling into the carbon emission formula.  For the proposed system, we will measure how long we have been idling for each trip, and attempt to translate this into tangible savings.


CO2 Concentration to CO2 Emission

Using CO2 sensors, such as the MQ135, can measure the amount of CO2 in ppm.  I initially thought of using the collected data to determine carbon footprint.  However the relationship between the two metrics is inconclusive at this stage and further research is required.



Better estimation of CO2 emission is through measuring amount of Petrol consumed than distance traveled.  To determine actual fuel consumption per trip, one must install a digital fuel gauge (for older vehicles) or tap into CAN bus and listen for fuel gauge value as reported by the vehicle MCU.


The next post will be about the implementation of a mobile application using the information gathered in this research.



Global Emissions | Climate Change | US EPA

TOYOTA BLADE [IMPORT] (2005-2011) - Search Cars and Vehicles Ratings by RightCar NZ

CO2 Emission Ratings for your Car provided by RightCar NZ

Toyota Auris - Wikipedia, the free encyclopedia




For those of you who have been following this post, I had experienced some difficulty accessing data from Sierra Wireless' AirVantage Cloud platform.  Most of the topics posted in this challenge used MQTT protocol to send data to their AirVantage application.  However, it is not possible to use MQTT in retrieving data from AirVantage, and the only way to get retrieve data back is by using AirVantage's REST API. Some very good post from amgalbu and tomaja have covered on how to do this in their posts AirMobile - 12 - AirVantage REST API and In the Air Design Challenge - Pollen & Allergen Sensing – Post 3 (AirVantage Intro).  Again, thanks to you guys who helped me out during that time.  They did a great job and actually offered their helper classes (available in Java, JavaScript and C++).  I now feel its my time to share the love by sharing my versions.  A node.js implementation, that can be used on the BeagleBoneBlack and a C# .NET implementation that can be used in almost all applications using the C# .NET 4.5 Framework.  However though, this library is at its infancy stage and only the basic REST API to send and retrieve data has been implemented, but should make things a lot easier.




If you do not have an AirVantage REST application yet, follow the tutorial Using REST API for devices.


Using node.js


Add the attached airvantage.connection.js file in your workspace.  This particular implementation requires restler, so install it using the npm package manager.  This can be done by typing npm install restler in the bash window.  Once that is installed, modify the airvantage.connection.js file with your credentials.

/* set system credentials here */
var username = "username";      /* username used to log in AirVantage */
var password = "password";      /* password used to log in AirVantage */
var client_id = "use_api_client_id";
var client_secret = "use_api_client_secret";

var serialNo = "SERIAL_NO";     /* this is the SN set when creating a new Gateway */
var connPassword = "CONNECTION_PASSWORD";   /* credential set when creating new System */

/* systems uid */
var system_uid = "system_unique_id";    /* UID found in Systems Details */
var machine_name = "asset_id";          /* as defined in */


There are three main functions to use this library.  (1) connect, (2) send_data and (3) get_data.  These exported functions are self-explanatory, refer to snippet below on how to use these functions.


var airvantage = require('./airvantage.connection.js');
function airvantage_connected()
    /* comment/uncomment lines of code to test */   
    /* retrieve data from the AirVantage platform */
    /* upload data to the AirVantage platform */
    //airvantage.send_data("temperature", 22.4);
    //airvantage.send_data("threshold", 10);






Using C# .NET


This particular implementation is a bit more advance and magical than the node.js implementation.  I created this helper library for use with the planned mobile application. Nice features of this version includes:

  • support asynchronous calls
  • built-in serialization and deserialization
  • portable (just one file) although, it requires references to RestSharp.Portable and NewtonSoft.Json  which can be installed using NuGet package manager


To use this library, add it to your C# project then refer to Program.cs file (as attached) for usage. The key to serialization/deserialization lies within the representation of the AirVantage Application model into a C# class.  Given the sample below:


<?xml version="1.0" encoding="ISO-8859-1"?>
<app:application xmlns:app="" 
        name="DEMO Application"

   <protocol comm-id="SERIAL" type="REST" />
   <encoding type="REST">
    <asset default-label="Demo Machine" id="machine">
     <variable default-label="Temperature" path="temperature" type="double"/>
      <setting default-label="Threshold" path="threshold" type="int"/>



This has been translated into the following C# class:

public class DemoMachine : SierraWireless.AirVantage.IAppModel
    [DataMember(Name = "machine.temperature")]
    public List<AirVantage.DataPoint> Temperature { get; set; }
    [DataMember(Name = "machine.threshold")]
    public List<AirVantage.DataPoint> Threshold { get; set; }

    public DemoMachine()
        Temperature = new List<AirVantage.DataPoint>();
        Threshold = new List<AirVantage.DataPoint>();


The important things in this class are, and should be observed when using this library:

  1. Class must inherit from SierraWireless.AirVantage.IAppModel interface
  2. Add [DataContract] class attribute
  3. Add [DataMember] property attribute and ensure that the Name value matches the asset id and data path as defined in the model application.




Sierra Wireless AirVantage data can only be retrieved using REST API.  The two implementations presented in this post are bare minimum but provides a good starting point.



The code presented (attached) in this post has been shared as is, and is meant for educational purposes only.  I have not thoroughly tested the code and is not intended for any production use.

Recently, I updated the CT sensor post with the current test and power measurements done on bench.  In this post, I will run through the enclosure design process.  The enclosure design is intentionally made simple and really is used to conceal any hazardous voltages that the user might touch accidentally.


For the enclosure design, I used AutoDesk Inventor Fusion and using it is quite intuitive.  I started by measuring the dimensions of the CC3200 Launchpad with the outdoor sensor module connected.  From the measurements, I sketched the base in Fusion, adjust the base sketch with an offset to draw the wall.  Once the base was sketched, I applied the extrude on the drawn planes, this immediately resulted to be the shell of the enclosure.  Examining the CC3200 Launchpad board, the PCBoard is actually raised from the base because of the female 20-pin connector.  To prevent the Launchpad from tipping and have it more stable, the walls were extended to provide some sort of a rise.  Below is a screenshot of the modeled enclosure.


enc design.png


The next part of the enclosure is a frame for the solar panel.  Again the process was mostly the same, that is, measure the solar panel, use the dimensions to sketch the base and extrude.  To be able to mount the solar panel, I added a few screw holes.  See model below.


panel frame.png

The files were then saved and exported in STL format ready for printing.  WP_20150214_002.jpg

Solar panel frame being printed (above).  Printed enclosure (below).


Then assembly and installation.


Btw, I drilled a few holes for the CT sensor and solar panel wires, a couple more holes on each side for airflow to the humidity and temperature sensor (currently not fitted in these pictures).





Then installed inside the meter box.


The wiring inside the box is already in spaghetti state, and was hard to route the cable safely.


I will leave this box collect some data for a day or two while I will be working on the other parts of the project.


Lastly, how I wish I incorporated in the design a quick way to reset the system.  Taking the top assembly off tends to be quite challenging as the box is too tight.


Next post, I will share some Sierra Wireless AirVantage helper libraries that you might find useful.

This is a continuation of the last post and highlights a quick guide on how to have a quick remote debug console for the CC3200.  One can use UART connection for debugging or can use a socket to send debug messages to a remote console server.


Starting from the TCP Socket CC3200 sample project, I have decoupled the WLAN and TCP Client parts inside main.c and encapsulated them into a more portable and reusable code fragments.  The main.c has now been transformed as:


void main()


    /* WLAN Connect */

    /* We are connected to the network, setup a TCP Client
    * and connect to the server
    ConnectToTcpServer(IP_ENDPOINT, IP_PORT);

    while (true)
        /* Send some data to remote server */
        TcpClient_Write("Can be debug message...", 23, 0, 0);
        /* stall for a second */



The remote console is really a TCP server running on a Desktop machine or Beagle Bone.  For the TCP server running on the Desktop, a quick Google search will result in a few TCP tools for Windows, MAC or Linux, or you can roll your own using C# .NET with this sample program ready to go.  Using the Beagle Bone is quite easy as well by writing a simple nodeJS script in Cloud9 IDE of the Beagle Bone.

Remote Debug.PNG

Using the files is quite straightforward and hope the API are self-explanatory.  One thing to note though, when connecting to a TCP server, the IP address argument is of an array of 4 bytes representing the endpoint IP address.  i.e. to connect to a TCP server with address on port 40000, you can do the following:


uint8_t endPoint[4] = {192, 168, 1, 60};
uint16_t port = 40000;
TcpClient_Connect(endPoint, port);



The attached code in this blog post is shared to the community as is.

This post is more about updates on the hardware state than anything else.  Since my last post, I have spent the time to completely populate the custom boards and test them.  As most of my requirements rely on the ADC peripheral, I first tried out CC3200 ADC sample application found in the SDK library toolkit.  I must say that the sample programs packed in the SDK are all well documented and relatively easy to follow.  The sample setup suggests to use a signal generator which I do not have, instead I used a rudimentary voltage divider circuit with a maximum output voltage of 1.4Vdc and connected it as below.




Doing this exercise revealed a stumbling block.  I could not get any reading from ADC Channel 0 on the CC3200. This channel is quite important for this system, as this is used for current sensing.  The main CT sensor of the outdoor module block is on this channel as well as the ACS712 output of the smart plug and smart switch modules.




I did further investigation around this issue and learned that I was not the only one who had similar issue. janisalnis also experience the same issue during his IoT Backyard of Things. This led me to re-route the CT sensor to use ADC Channel 2 instead and re-route the ACS712 output as well.


Re-routing was quite simple, thanks to the R0's in the schematic, I did not have to cut any tracks.  This ended up with the following mod (see red wire).




Finally, the boards with connected to the CC3200.



Outdoor sensor + CC3200 Launchpad



Smart plug / Smart switch + CC3200 Launchpad



I only have one CC3200 Launchpad atm, and in the process of acquiring a few more, hopefully they will arrive within the next two weeks or so.  However, this should not stop me from completing the software.

Household energy consumption could be the highest contributor in one's carbon footprint.  By measuring how much energy we consume each day we may be able to adjust our usage patterns to save.  There are several ways to measure household energy, both invasive and non-invasive methods.  In this project, the focus will be on non-invasive method, specifically using a split core type current transformer sensor to create a power meter.  Hall-effect is another type of non-invasive method, such as using the ACS712 chip, which will be blogged another time.


(Current transformer) CT sensors are used to measure alternating current.  As any transformer, it has a primary winding, a magnetic core and secondary winding.  Split-type CTs can be clamped around the supply line of an electrical load to tell how much current is flowing through it.  It does this by acting as an inductor and responding to the magnetic field around the current carrying conductor.  In this case the primary will be the live or neutral wire (not both) and passed through the hole of the CT sensor.  The secondary is made up of multiple fine wires enclosed inside the transformer.  By reading the amount of current being produced by the coil, we can then calculate how much current is passing through the conductor. 

The CT sensor used in this project is a current output type and for this data to be useful, the induced current needs to be converted to voltage using a burden resistor.  This specific sensor has the following characteristics: 30A nominal, 60A maximum rated primary current and 2000 turns ratio.


The blog post in this link has a good explanation in the circuit design process and will be used as a guideline in designing a power meter for Texas Instrument's CC3200 Launchpad XL.



First, we need to know the maximum measurable peak current as:

Imax_measured = √2 * Imax_rms = √2 * (60A) = 84.8528 A

The current at the output would be proportional to the turns ratio, 1:2000.

Isensor = Imax_measured / no_of_turns = 84.8528 / 2000 = 0.04243A


The CC3200 ADC recommended maximum input level should be less than 1.45V, thus 1.4V will be used in this instance.  For maximum measurement resolution, the maximum voltage at the burden resistor will be half the maximum ADC input level.


Vburden = Vadc_max / 2 = 1.4V / 2 = 0.7 V


Given voltage and current values, we can derive the value for the burden resistor as:


Rburden = Vburden / Isensor = 0.7V / 0.04243A = 16.49 Ω


The ideal burden resistor is 16.49Ω, we will use the standard 16.5Ω value for this specific application.  We now have a basic circuit as shown in figure below.  Simulation was ran through Texas Intruments' TINA-TI Spice based program.


Remember that the voltage signal across the burden resistor is still AC (see right image above), and the ADC is not capable of measuring negative voltage.  So we have to add this AC voltage by 0.7V to make the voltage measurable between 0 and 1.4V.  This can be achieved by adding a clamping circuit as shown below.  The resistor values where calculated using the voltage divider equation to achieve 0.7V across R2 set at 10kΩ.


This completes the electronic design part of the power meter.

For the software, we will be porting EmonLib an Arduino Library from to a more portable C library.  Using the ported library, we can calculate the apparent power.  With the apparent power now known we can average the samples over a period of a second to resolve energy in Watt-sec which will determine the carbon footprint usage where 1KWh = 1.52 lbs CO2 (estimated EPA).  Snippet below.


static float aveS = 0;          // average apparent power
static uint32 n = 0;
float Irms = EmonC_CalculateIrms(1480);
float S = Irms * VAC_MAINS;    // S - apparent power, VAC_MAINS 230Vac

WEIGHTED_AVE(&aveS, &n);

  float co2 = CONVERT_TO_KWH(aveS) * 1.52f;
  DEBUG_LOG("co2: %3.2f\r\n", co2);
  ReportCO2(co2);          // send data to central hub  
  newSecond = false;



Attached partially ported energy monitor library.  Only RMS current calculation is ported atm as there is no hardware support for VI calculation for this project.

Update 2:

Its just now that I was able to verify this feature.  After some calibration and including the power factor (set at 50%), I got the power usage close enough to match a power meter.  There is a bit of difference but I guess that is caused by the resolution of calculation and that the meter would probably be calculating the actual power factor as well.  Anyways, I think its good enough for now.



Next posts will be about the enclosure, installation and actual testing.


Current monitoring with non-invasive sensor and arduino | Homautomation

How to build an arduino energy monitor - measuring current only | OpenEnergyMonitor

1 kilowatt-hour · BlueSkyModel

WP_20150117_003 1.jpg

Since most of the foundation software for this system is functional, the next posts will be more on the hardware aspects of the system starting from the power supply.  As previously mentioned, the board design is more of a development platform than anything else, and so has a lot of provisions for alternative circuits and ease of modifications.  The board was also divided into two main parts, power supply and peripheral.


The supply block can be of any four power sources: (1) Battery, (2) Solar (3) 12-VDC vehicle battery and (4) AC-mains power. TI's TPS767D301 is used to provide regulated 5Vdc and 3.3Vdc.  Aside from having two output channels, this particular LDO regulator was chosen because of the high output current capability (up to 1A per regulator) yet an ultra low quiescent current.  The adjustable regulator can easily be set via external resistor divider.  See programming the TPS767D301 adjustable LDO regulator section page 17 of the datasheet.


The outdoor sensor module utilises harvested solar energy to charge the CR123A rechargeable battery while providing power to the sensor module.  Battery is managed by TI's BQ25504, an ultra-low power boost converter with built-in battery management unit.  This is the ideal power management IC solution for the outdoor sensor module.  The circuit used for this project was adopted from the Solar Application Circuit as described on page 18 of the datasheet. This section also has an example on how to calculate the R values for a specific application.  One would find the spreadsheet calculator to be very useful in the design process.


A couple lessons I've learned during the design process for this power source.


(1) if you are going to do/copy the schematic from the sample application, assume the OC and OK resistor values to be greater than 10MΩ, because


(2) the resolution of standard values above 10MΩ is low and would require a couple resistors to achieve the desired value.  i.e. 15.6MΩ would realistically be 10MΩ and 5.6MΩ in series and this should be noted in the design of the schematic and laying out of components in the PCB design.


I was not mindful initially when I designed this section of the board, and it can be obviously seen on the R35, I only had a place holder for a single 0402 resistor.  At least it was not that bad of a mod as there was room in the left side to accommodate two 0603s connected in series.




Below is the circuit in action connected to a solar panel MC-SP0.8-NF-GCS - MULTICOMP - SOLAR PANEL, 0.8W, 4V, NO FRAME | element14 New Zealand



Next one would be the supply block derived from AC mains.  This supply is the second simplest power circuit (simplest one is the straight connection of battery to the dual LDO).  Since this supply uses AC mains, and could potentially be dangerous, extreme care is fundamental during testing.  The core component for this power block is the compact single output AC-DC converter from Vigortronix.  VTX-214-005-105 - VIGORTRONIX - AC-DC CONV, FIXED, 1 O/P, 5W, 5V | element14 New Zealand.  The compact size and 5W output are the key features for this module.


Initially, I thought of implementing a transformer-less power supply because I do not want to use a bulky and costly transformer.  However, that can only provide low DC current and quite dangerous as there is no isolation from the high side.  This compact AC-DC converter ticked the supply requirements for the smart switch and plug modules.

Lastly, the emission sensor module will be mounted somewhere in the vehicle and will be powered from the vehicle battery.  For this specific module, TI's TPS62153A buck converter has been selected.  This power management silicon has the following key features which were considered key aspects in the component selection:

  • can provide up to 1A of continuous current at 5V output
  • low quiescent current
  • over temperature protection
  • short circuit protection
  • rated for automotive applications

WP_20150119_002 1.jpg


Hope you enjoyed this post as much as I enjoyed populating and testing the boards, 'til next update. 

Over the couple weeks or so, I have been focused on the central hub application where I have been successfully sending device information and sample data to AirVantage.  However, I couldn't seem to retrieve the data from the cloud-platform on to another device or even on the same device.  This is a major road block for the system, since data from the central hub needs to be updated with the information sent by the mobile application.  Likewise, the mobile application will have to retrieve the central hub's status so it can be presented on the app.




Looking through the AirVantage documentation, there is the concept of tasks, a way to receive messages from AirVantage server.  However, tasks can either be initiated from the AirVantage dashboard, or scheduled, but not from the remote device.  Although, there are two types of tasks, read and write, these are actually equivalent to request current status and set device parameter.  Again, a feature that does not satisfy the system requirements, which is to (iterate again), system information to be stored on a cloud-platform which can be retrieved by any remote device.  I'm thinking within the lines of a hosted database but without having to configure the server and write API's to access the information.  AirVantage fulfils half the requirements and perhaps it does provide a mechanism to access the data, through alerts and web hooks to another webby enterprise application.  Taking this route though would require more development time, a resource that is slowly becoming unavailable for this project.



It is possible to retrieve data from AirVantage from any device using REST api.  amgalbu and tomaja have covered on how to do this in their posts AirMobile - 12 - AirVantage REST API by Ambrogio and In the Air Design Challenge - Pollen & Allergen Sensing – Post 3 (AirVantage Intro) by Dragan.  After reading through their examples, I found what caused my troubles.  I used the following API from the documentation as is:


where in should've been





As an alternative solution, I will be using Parse, a backend service provider.  I have been using this platform for a number of applications and have found it to be the best BAAS atm.  The service is FREE for a generous cloud resource, see below.




This framework is also backed up with a thorough documentation and you will have your application (embedded, mobile, desktop, or cloud) fully integrated within an hour.

Other alternatives include Firebase, Buddy, etc.


Not All That Bad At All


AirVantage is not all that bad after all.  IMO, AirVantage has not just been designed for [remote] device management but is a good backend platform as wellA little polish on the documentation though would be nice to be explicitly clear with their examples.  AirVantage will be good for tasks like:

  • monitoring device status which would trigger an alert when it is in trouble
  • geo-locating mobile devices
  • remote deploy
  • delivery of firmware/software updates
  • integration with ERP systems or other customed enterprise applications




AirVantage is the cloud platform suggested in this design challenge.  However, with proposed Carbon Footprint Monitoring System, AirVantage as a backend platform is not suitable for this particular application and will be using Parse as the alternative back up solution, and will be switching my API calls to this service when my AirVantage 6-month trial expires.  I've got the code for both platforms working anyway.


The current application using AirVantage is not going to be scrapped. AirVantage will still play a role in this system.  AirVantage's tasks and alerts will be used to send scheduled reports and notification to an assigned email.  It will also be used to remotely configure the device, i.e. update Carbon Budget settings, which can be done through the 'Write Task'.


Final Notes


If anyone in this group who have been able to retrieve data either via MQTT or REST protocol or through some other approach, sharing this bit of information may help not just me but others who are experiencing the difficulty as well.


Thanks to amgalbu and tomaja for the help.

Earlier this challenge, I have been setting up the development environment using Visual Studio and in one of those posts, I did mention on how to configure Visual Studio to develop Linux applications using VisualGDB.  SysProgs has a very good tutorial here.  This is very much useful if writing apps using C/C++, as the debugging experience in Visual Studio is exceptional.  However, my initial plan to use C/C++ for the Linux application on the BeagleBone Black has changed and have been using node.js for application development.


By default, node.js is not a one of the available JavaScript templates in Visual Studio.  This blog post will walk you through on how to get node.js development on Visual Studio for the BeagleBone Black.  To do so, just follow the steps below.


  1. Before starting, ensure that the latest updates on Visual Studio are installed.  You can get the latest update here.
  2. Next, install WebEssentials extension, download it from here.
  3. Then, install node.js from their site.
  4. Lastly, install NTVS (node.js Tools for Visual Studio) as the main component to transform Visual Studio into node.js development environment.


Now, from the New Project window, you can select Node.js application template.

vs new project.PNG

Run and start debugging the node.js application as you would any other VS application.


Installing node.js Packages


Since MQTT is vital in this design challenge, we can install node.js modules through the built-in npm (node.js package manager).  To get the MQTT module, expand the node.js project, then right-click on npm, which will then bring up the npm install window (see below).


npm install.PNG

Just type the module name in the search bar and click on Install Package to add the specific node.js module in the project.


Transferring Files to Beagle Bone Black


Once you have done enough coding and debugging and would like to do testing on the target machine, the Beagle Bone Black in this case, simply copy the files from the Visual Studio project directory to BeagleBoneBlack's cloud9 directory ( /var/lib/cloud9 ) using FileZilla or similar tool.


js transfer.PNG


There we have it, node.js development using Visual Studio which targets the Beagle Bone Black.

This week I have been mostly busy around the design of the flow of data in the system.  Working from the high-level architecture presented from this post, the diagram below presents how data flows within the different component of the system.


From the left, the Emission Sensor will transmit CO2 levels and accelerometer over Bluetooth Smart connection to a smartphone application.  The accelerometer information will be used by the Smartphone app to determine the vehicle's state (off, idle, running).  Using the accelerometer data and GPS information from the smartphone, the mobile app can determine travel time, idle time, and distance travelled, which will then be sent to Sierra Wireless AirVantage application.  This defines the first AirVantage application model:


  <encoding type="MQTT">
  <asset default-label="CarbonMobile" id="mobile">
   <variable default-label="TravelTime" path="travelTime" type="double"/>
   <variable default-label="IdleTime" path="idleTime" type="double"/>
   <setting default-label="DistanceTravelled" path="distanceTravelled" type="int"/>
   <setting default-label="CO2Level" path="co2Level" type="double"/>
   <setting default-label="VehicleState" path="vehicleState" type="int"/>


On the right side of the diagram, data from the environment (indoor/outdoor) sensors, smart plug, and smart switch metrics are transmitted to the Central Hub via WiFi.  Some of the metrics include power consumption in Watt-sec, environment conditions.  Power consumption will then be translated into equivalent carbon footprint as 1.52 lbs for every kilowatt-hour (references below).  The application on the central hub then deducts this carbon usage against the set carbon budget.  This defines the second AirVantage application model:


  <encoding type="MQTT">
  <asset default-label="CarbonHub" id="hub">
   <variable default-label="IndoorTemperature" path="indoorTemperature" type="double"/>
   <variable default-label="IndoorHumidity" path="indoorHumidity" type="double"/>
   <variable default-label="OutdoorTemperature" path="outdoorTemperature" type="double"/>
   <variable default-label="OutdoorHumidity" path="outdoorHumidity" type="double"/>
   <variable default-label="CarbonBudget" path="carbonBudget" type="double"/>
   <variable default-label="CarbonUsage" path="carbonUsage" type="double"/>
   <variable default-label="SwitchState" path="switchState" type="boolean"/>
   <variable default-label="PlugState" path="plugState" type="boolean"/>


The downlink arrows on both sides represents the data being sent to smartphone and central hub apps respectively.  Each app subscribes from the events and updates of the other.  Central Hub metrics will be used by the mobile app for display, while the mobile app data will be used to determine the carbon footprint of the vehicle and counted against the budget.





There are a lot of resources available online to setup the Beagle Bone Black and connect it with AirVantage.  This post will be a quick start guide to get your BBB talk to AirVantage in under an hour (assuming all things going well).


A Bit of Intro

Beagle Bone Black is yet another powerful development Single Board Computer running on TI's AM335x processor with an ARM Cortex-A8 at its core clocked at 1GHz.  One of the main features of the BBB is its embedded MMC that is preloaded with a Debian (Linux) Image, which takes the hassle out of setting up an SD-card and flashing an operating system.  BBB has taken a plug-n-play approach.  More info can be found in their main website.    Enough with all this introduction and let's get the BBB ready. 

Ingredients (still feeling festive)

To start off, we will need

1    BeagleBoneBlack

1    Ethernet Cable

1    USB mini cable or 5V power supply

IP Scanner (i.e. Advance IP Scanner)

Telnet/SSH Client (i.e. PuTTY, SmarTTY, OSX Terminal)

Web Browser (i.e. Internet Explorer, Chrome, Firefox, Safari, etc.)





  1. Connect the BBB to your home network by plugging the ethernet cable to your router.
  2. Power the BBB by plugging the USB mini cable to a USB power supply (I'm powering mine from the USB port of my router).
  3. If you haven't installed the software tools, now is the best time to do so while BBB is booting up (takes about 10secs for the boot process to complete).
  4. Run Advance IP Scanner, to retrieve the IP address of the BBB.  Sort by Manufacturer and take note of the device from Texas Instruments.  This will be the IP Address of the BeagleBoneBlack. 


   5. Next we will update the system.  Using an SSH client, connect to the BeagleBoneBlack, username is root with an empty password.  I usually setup a password as some SSH clients do not connect with remote devices with an empty password.  To change/setup the password, type the command passwd.  To update the system, type the following commands:

                    apt-get update

                    apt-get upgrade

   6.  On a web browser, enter the IP address to retrieve the board's serial number to be used later on.


   7.  Now, we are ready to setup a connection to Sierra Wireless' AirVantage.  Login or register a trial account to AirVantage if you haven't done so.  Follow this guide to setup an AirVantage application.  Half-way through the page, there is a specific guide for the BeagleBoneBlack.  Stop at that point and proceed to the next step before following AirVantage's BBB guide.

   8.  Back to the web browser, connect to the Cloud9 IDE at port 3000, i.e.


   Cloud9 IDE is yet another great feature, you can delve into development immediately without installing a separate IDE.


   9. In the Workspace (right pane), create a new folder for development.  In the bash pane (lower section), change the directory to the newly created folder and install the MQTT library.

install mqtt.PNG

   10.  After that's installed, you can proceed with the Beagle Bone specific guide.


This is the basic setup to get you up and running the BBB with AirVantage.  As an additional reference, you can look at Node.js v0.10.35 Manual & Documentation.  If you are going to use the CC3200 with the BBB, have a look at the net module.


'Til next post, HAPPY NEW YEAR everyone!!!