Radio silence

When I started this blog, I wanted to write regularly with at least a blog post per month, but October has been a really quiet month from me. The reason for the radio silence is that I moved between suburbs in Sydney. I also moved between continents, between Malaysia and Australia. I have also re-joined Microsoft as a Technology Solutions Professional for IoT in the Asia Incubation team. Fun times ahead and the passion for anything IoT related continues.

A recent announcement that got me stoked about was the Microsoft Band. It’s more than just a fitness tracker because as this blog post rightly puts it, it’s the power of IoT on your wrist. I can’t wait to wear one on my wrist.

This device would be a great addition to my Project GetFitY’all. It’s really about the internet of my things when I began this project, and the more devices connected to this project, the merrier it is.  Over time I intend to connect more devices, or sensor gadgets. I also need to replace the mems sensor board because the temperature stopped working. I think I might have “killed” the function. All it returns now are the following:

MPL3115:        Alt. 0.0        Temp: 0.0
MPL3115:        Alt. 0.0        Temp: 0.0
MPL3115:        Alt. 0.0        Temp: 0.0
MPL3115:        Alt. 0.0        Temp: 0.0

No worries, I probably will buy a few other boards just as backup. Meanwhile it’s back to work. Let’s rock on!

Sending sensor board data from Raspberry Pi to Intelligent Systems Service (ISS)

I have been mucking around with the Xtrinsic-sense board which is an add-on to my Raspberry Pi. In my previous post, I had executed the Python scripts that came with the sensor library that I cloned out of this github. There is a good article that explains about how to enable Xtrinsic-sense board in Raspbian.

However my aim is to get the Intelligent Systems Service (ISS) sample C application to invoke the sensor board shared library to retrieve the altimeter and temperature values, assign that to a string property within the data model, then send it to ISS. The sensor board library comes in the form of a shared library called

Hence I started on a journey to try to invoke the functions within the out of mirroring the Python code, but in the sample C application. Now I must admit that Python coding skills is non-existent, and my C coding skills were really rusty. The last time I wrote a C/C++ application was in 2000/2001! What’s surprising is that I haven’t completed forgotten C, it’s like riding a bike, suddenly remnants of makefile, linking with dynamic/static libraries, include files, and function pointers in C slowly came back to memory.

But I’m still hopeless in Python, I gave up because I didn’t understand what the following code does except that it does some byte shifting, but for what reason, it beats me.

def getTemp(self):
    t = self.readTemp()
    t_m = (t >> 8) & 0xff;
    t_l = t & 0xff;

    if (t_l > 99):
        t_l = t_l / 1000.0
        t_l = t_l / 100.0
    return (t_m + t_l)

I knew there has to be an easier way to invoke the sensor board library in C, but where’s the sample code? After much searching, I found a reverse-engineered with C source code! How amazing, thanks to this bloke named Lars Christensen. It was just hot off the oven, to be specific just last Saturday 13 Sept. To get started, all I had to do was to clone his source from github. In my raspberrywifai SSH session, I issued the following command (provided you have already installed git too).

git clone

There was a slight problem. The mpl3115a2.h header file was empty. No worries, just go to the github repository at, click on mpl3115a2.h, copy the content, and paste it in the file in your working directory on RaspPi.

You also need to download and extract the bcm2835 library. Then just follow the steps on how to make it. This creates a static library called libbcm2835.a. Next, make the reverse-engineered sensor board library so that you create a new, and libmemssensor.a. I was only interested in the static libraries of libbcm2835.a and libmemssensor.a so that I can compile test.c. There wasn’t a proper make statement for test so I just issued my own gcc command.

gcc -Wall -I /home/pi/rpi-mems-sensor  -L. -lmemssensor -lbcm2835 -static test.c -o test libmemssensor.a libbcm2835.a

Do not just run ./test because initializing bcm2835 requires elevated permission. If you do that you will get the following error:

pi@raspberryfai ~/rpi-mems-sensor $ ./test
bcm2835_init: Unable to open /dev/mem: Permission denied

So do this instead:

sudo ./test

And voila! I get the altimeter and temperature reading.

raw alt = 11968
alt: 46.750000, temp: 23.812500
raw alt = 11968
alt: 46.750000, temp: 23.812500
raw alt = 11968
alt: 46.750000, temp: 23.812500
raw alt = 11968

The Python code which I just couldn’t comprehend is the equivalent of the following C code:


double getTemp() {
    int t = MPL3115A2_Read_Temp();
    int t_m = (t >> 8) & 0xFF;
    int t_l = t & 0xFF;
    if (t_m > 0x7f) t_m = t_m - 256;
    return t_m + t_l / 256.0;

It still beats me what it does, but that’s alright, I just wanted this code to work within the ISS sample C application. Next I embedded this code within the DATAPROVIDER_RESULT DATA_PROVIDER_INIT function. I didn’t want to create a new data model so I reused the sample data model, and chose to assign the altimeter and temperature reading to the stringProperty, as shown in the following code:

// setting StringProperty which contains the alt and temperature
char tempinfo[1024];
snprintf(tempinfo, sizeof(tempinfo), "alt: %f, temp: %f\n", getAlt($
stringProperty = tempinfo;

Compile (also includes modifying the makefile to ensure the sensor board header files and static libraries are correctly linked), and then run the ISSAgent app, and wait for it……..

Info: Microsoft Intelligent Systems Agent Console
Info: Using device endpoint:
Info: Registering device: Name=raspberrywifai, FriendlyName=raspberrywifai, ModelName=Contoso.Device, Description=raspberrywifai
Info: x-ms-activity-id: 557374f8-2342-4bfb-bb7b-ce19199fa77e
Info: Getting endpoints for device raspberrywifai
Info: x-ms-activity-id: 229227bf-483b-4914-a613-e447bb7caca5
Info: Got ingress queue, name=getfityall/raspberrywifai
Info: Got commands queue, topic path=DeviceBank1, subscription name=raspberrywifai
Info: Got per device token=[secret]
raw alt = 11152
Info: Uploading message 2e5f2634-bee2-4e88-b1c3-3ed991f25f41 for device raspberrywifai (payload={"@iot.devicename":"raspberrywifai", "value":[ {"@odata.context":"Contoso\/$metadata#Device\/$entity", "":"Device('raspberrywifai')", "@Microsoft.IntelligentSystems.Vocabulary.V1.Timestamp":"2014-09-17T00:34:41Z", "structProperty":{"simpleField":17, "structField":{"int32Field":10, "int64Field":34, "doubleField":40.000000000000000, "stringField":"Wed Sep 17 10:34:40 2014\u000A", "guidField":"0F1E2D3C-4B5A-6978-8796-A5B4C3D2E1F0", "binaryField":"AAAA", "dateTimeOffsetField":"2014-09-17T10:34:40Z", "booleanField":true}}, "stringProperty":"alt: 43.562500, temp: 22.812500\u000A", "dateTimeOffsetProperty":"2014-09-17T10:34:40Z"} ]}) ...Info: Success

Or more specifically:

"stringProperty":"alt: 43.562500, temp: 22.812500\u000A"

Woo hoo! I got it. Now moving on to the next steps. This opens up other possibilities such as sending temperature as an event on a pre-determined interval, and also set up alarm when temperature falls below or goes above a certain value. The fun begins! :)

RaspberryWiFai getting mobile

Raspberryfai has transformed into RaspberryWiFai, and it is can’t wait to go out there under the spring sun! I’d procrastinated for awhile in opening up the clear case and plugging in the Xtrinsic-Sense board that I purchased together. Initially I wanted to buy a downgrade GPIO cable from 40 pins to 26 pins so that the cable could nicely slip out of the clear case. I could order from Adafruit but this means that it would be an international shipment and it would cost me more than the inexpensive cables. I checked out a local electronics mart, but they didn’t sell it. Searched more online stores that would deliver fast around here, and none sell this cable.

Now that RaspberryWiFai is more mobile due to a working WiFi USB adapter, why not power it up using my 19,200 mAh power bank, open up the clear case top, plug in the Xtrinsic -Sense board, and will it out for a drive tomorrow. Here’s how RaspberryWiFai looks like with the dropped top.


However the funny thing was that I didn’t know which was GPIO PIN 1. The Xtrinsic-Sense board has 26 pin to work with the older RaspPi A and B, but RaspPi B+ has 40 pins. It wasn’t labelled on the RaspPi. I looked through GPIO layout diagrams for the RaspPi B+ but couldn’t find anything until I came across a comment from Matt the author of this blog, who said “if you look on the reverse of the PCB Pin 1 has a square pad and the others have round pads.”. Got it!

Without further ado, I executed the Python script for getting the temperature/pressure. The sun was up, and still is so it would be pretty good to show how temperature changes when I moved RaspberryWiFai  from inside my unit to the balcony which is baking hot from the spring sun. Here’s the output showing the temperature rising (I’d condensed the output for brevity sake here):

pi@raspberryfai ~/rpi_sensor_board $ sudo python
MPL3115: Alt. -59.888 Temp: 23.176
MPL3115: Alt. -60.04 Temp: 23.192
MPL3115: Alt. -60.776 Temp: 23.176
MPL3115: Alt. -59.888 Temp: 23.16
MPL3115: Alt. -57.872 Temp: 23.192
MPL3115: Alt. -58.824 Temp: 23.208
MPL3115: Alt. -58.0 Temp: 23.192
MPL3115: Alt. -54.2 Temp: 23.16
MPL3115: Alt. -54.68 Temp: 23.144
MPL3115: Alt. -57.856 Temp: 24.16
MPL3115: Alt. -58.808 Temp: 24.64
MPL3115: Alt. -58.824 Temp: 24.8
MPL3115: Alt. -57.84 Temp: 24.96
MPL3115: Alt. -58.84 Temp: 24.128
MPL3115: Alt. -57.84 Temp: 24.16
MPL3115: Alt. -58.792 Temp: 24.176
MPL3115: Alt. -57.808 Temp: 25.0
MPL3115: Alt. -57.84 Temp: 25.32
MPL3115: Alt. -57.2 Temp: 25.48
MPL3115: Alt. -57.2 Temp: 25.64
MPL3115: Alt. -58.888 Temp: 25.8
MPL3115: Alt. -58.04 Temp: 25.96
MPL3115: Alt. -58.856 Temp: 25.112
MPL3115: Alt. -57.84 Temp: 25.128
MPL3115: Alt. -57.84 Temp: 25.144
MPL3115: Alt. -57.2 Temp: 25.16
MPL3115: Alt. -54.856 Temp: 25.208
MPL3115: Alt. -54.84 Temp: 25.192
MPL3115: Alt. -54.52 Temp: 25.224
MPL3115: Alt. -54.68 Temp: 25.24
MPL3115: Alt. -55.0 Temp: 25.0
MPL3115: Alt. -55.856 Temp: 26.16
MPL3115: Alt. -55.856 Temp: 26.32
MPL3115: Alt. -56.76 Temp: 26.48
MPL3115: Alt. -55.36 Temp: 26.64
MPL3115: Alt. -55.04 Temp: 26.8
MPL3115: Alt. -55.2 Temp: 26.96
MPL3115: Alt. -55.856 Temp: 26.112
MPL3115: Alt. -55.2 Temp: 26.128
MPL3115: Alt. -55.36 Temp: 26.144
MPL3115: Alt. -56.808 Temp: 26.16
MPL3115: Alt. -59.872 Temp: 26.112
MPL3115: Alt. -60.76 Temp: 26.8
MPL3115: Alt. -60.76 Temp: 26.64

Indeed RaspberryWiFai was basking in the sun, from a low of 23.176 degrees C, it went up to 26.96 degrees C under the hot sun. Smoking hot! Time to wire it up to my ISS, and do some cool things like raise an alarm when it is too hot.

How to get Raspberry Pi to work with TP-Link TL-WN721N USB Wi-Fi adapter

Wow! It’s taken me over a week to find just the right combo of advice from a number of really helpful blogs to help me setup raspberryfai with mt TP-Link TL-WN721N USB WiFi adapter. I tried so many different steps that I couldn’t remember what I’d done. I thought that the wicd-curses utility would work like a charm but it hung my RasPi a few times.

Now that it’s setup, I shall call it raspberrywifai. :)

The blog which was most helpful was this post written almost 2 years ago. Just follow the steps especially on how to get the firmware for the TP-Link USB adapter. The only exception was that the following command didn’t work in my case,

pre-up wpa_supplicant -Dwext -i wlan0 -c /etc/wpa_supplicant.conf -B

Instead I just have to change it to the simpler form of (my wpa_supplicant.conf file is kept in its own folder):

wpa_conf /etc/wpa_supplicant/wpa_supplicant.conf

In order to get the psk value, you can’t just type in your WPA2 passphrase, you need to run the following command:

sudo wpa_passphrase ssid passphrase

To be sure that it is indeed connected and seen as a USB device on my RasPi, I run lsusb, a command I learned from  this post.

Now that raspberryfai has become raspberrywifai, I can bring it out for a spin this weekend.

Intelligent Systems (at your) Service

I was really excited that my application for the Microsoft Azure Intelligent Systems Service (ISS) Limited Public Preview (LPP) had been approved (my apologies for all the 3-letter acronyms which I will be repeating all over my posts from now on). What the ISS LPP entitles me are the following:

  • Access to the ISS service which is enabled for use with my Azure account. The ISS service icon is now available in the list of services (on the left in my Azure Management Portal) and it looks like this:


  • Download the ISS SDK along with a couple other utilities such as DeviceMonitoring and the Contoso Home Automation -part 1 sample/demo (to be checked out soon)
  • Participate in a private forum.  According to the welcome email, “You are more likely to get a response in a reasonable timeframe, since you are not reliant on an individual being online and able to answer your question”, which sounds great.

I went ahead to create an ISS service for GetFitY’all. However I could not share too much details and the screen clipings because according to confidential information clause in the EULA,  the software and service, including the user interface, features and documentation, are confidential and proprietary to Microsoft and its suppliers.

The real fun happens inside my raspberryfai. The RPi runs Raspbian, a customized version of Debian used to run on the RPi. I used scp to copy the ISSAgent_C_Samples folder into my raspberryfai. Then I compile the sample ISS agent and run it. The agent sends messages to my ISS account. My next step is to embed the ISS managed library into my GetFitYall device gateway, which was implemented as a WebJob described in one of my previous posts, and do the same in sending the activity data points to my ISS account. Previously I implemented a simple message pump functionality in the WebJob to send activity data points (pulled from Fitbit and Strava APIs) asynchronously to an Azure Event Hub via AMQP. Then I have Azure Worker Role instance(s) to ingest the event hub messages by persisting into respective Azure Storage Tables.

To waste or not to waste

Since a young age, I had been taught by my mother not to waste, especially precious resources like water, power, food and yes money too (she still thinks that I’m a spendthrift) . I reckon that my mother understood well about the importance of minimizing waste before carbon footprint appeared in our vocabulary. Up to today, I cringe whenever I see people wasting. As a case in point I once saw a guy leaving the water hose running at his front porch, he was presumably watering his plants, except that there were no plants there and he was doing something else. Although water was free and remains so in my birth state of Selangor, there is absolutely no excuse to leave the tap running for no reason.

While the case above was very much about with social behavior and civic mindedness (or the lack of it), I believe that technology and product innovations around our everyday things, be it appliances, devices, gadgets, wearable devices, or just about anything you own could provide positive implications in conserving resources. The Internet of Your Things could provide means to improve efficiency and minimize waste.

If things could communicate real-time information to each other or via an intelligent systems service, there is a real possibility that power and fuel consumption could fall. The Nest learning thermostat is one such product innovation that helps you save on your energy bill by learning your usage patterns. It could interact with other things too. In my previous post I mentioned a scenario that I would like to cater for which is to alert my family once I’d finished my ride in the trails and when I’m riding or driving home, including my ETA. If it’s winter, it may be good to get that heater warming the bathroom so that it’s all nice and warm when I take my shower or a hot tub bath. It is possible with the Nest and drum roll please… a Mercedes.


No pun intended but I doubt that I would buy a Mercedes just so that my car could tell Nest that I’m on my way home and make it warm and comfortable as soon as I get home. If I did, then this would just prove that my mother was right, that I’m a spendthrift and this negates the reason why I should minimize waste. Hence I’ll try to build my own thing, and application on top of an intelligent systems service to try to enable this scenario. Maybe there are some projects readily available out there, which is great!

Meanwhile I’ll put on my “pastry chef” hat and see what I could do with “raspberryfai” being at my service. I trust there are umpteen scenarios in this uncharted territory of smart things. Do comment and please let me know.

Note: This post was originally posted on my LinkedIn. I still haven’t decided how I will segregate the musings and the technical posts. Meanwhile I’ll just repost every thing I wrote.

raspberryfai at your service

My apologies for the corny title of this post, but since Fai rhymes with Pi, I couldn’t resist not naming my li’ juice fruit as RaspberryFai. See my SSH session below:



I lost a couple days of precious time in tinkering with my Raspberry Pi (RPi) because I got some internet connection issues but it’s been resolved since yesterday. First thing I did was to ensure I could make an SSH connection to my “headless” Pi that’s sitting next to and connected to my ADSL router. Next on the list is to download all the essential packages that I need to get started. The apt-get tool works like a charm once you have internet connection. No need to hunt for all the dependencies, just know what I want and apt-get install away.

I’d installed the following packages so far:

  • wicd-curses – easy way to get WiFi enabled on my raspberryfai. My TP-Link TL-WN721N WiFi USB dongle works well with RPi. It’s not exactly compact in size but then I don’t want to get more gadgets yet so this will suffice at the moment.
  • mono
  • C# interactive shell – both mono and this from
  • build-essential
  • node-js – by following this setup tutorial.
  • node-red: while i’m at it, I may as well check out node-red which is presumably the simplest form of an open source visual editor for wiring the internet of things produced by IBM

Before I end up downloading a bunch of non-essential packages, I better start wiring a quick IoT scenario using raspberryfai.


Unboxing my Raspberry Pi B+

Like a delighted child upon given some candies, that’s was me yesterday, just better. The day started when I went to the post office for an early collection of a parcel which contains a hand-picked tasting selection composed of three Grands Crus Nespresso, two of which I had not tasted before. I’m more of a morning person these days, so this is much appreciated for my early  morning tinkering with Project GetFitY’all.

2014-09-02 07.08.06

Then another pleasant surprise in the afternoon, my Raspberry Pi B+ was delivered. I ordered it from Element 14, a nice reference to silicone in the periodic table. I think this would be a good start to me being a “pastry chef”. I always liken mucking around with technology akin to being a cook. And technical demos are just like a cooking show, my favourite phrase is “and here’s one I prepared earlier…. “. So in this post, I will be using the analogy of being a pastry chef, aptly linked to my new juicy fruit, the Raspberry Pi. :)

Here’s the unboxing of my delicious pi, and the pastry ingredients I got were a Raspberry Pi B+ with and 8GB SD card with NOOB, a clearcase, a MEMS Sensors Evaluation board, and a charger.

2014-09-01 16.11.46


The Pi was small, credit-card sized.
2014-09-01 16.11.55

2014-09-01 18.10.51


2014-09-01 18.22.21


Then nicely protected in the clear case.

2014-09-01 18.21.41


More to come at a later post which I’ll boot up NOOB to install Rasbian, enabling XBMC perhaps, and then connecting with the sensor board to start mucking around my project extension.


VoluntaryTracking.Enabled = true;

If you’ve been using Google Maps on your phone, you probably know there is a setting within that allows Google apps to use your device’s location any time it is on, or maybe not.



Or if you prefer the conspiracy theory version, you can read this.

The way I think of this is simply in a geeky way which is the title of this post. Since I had enabled voluntary tracking of my whereabouts, why not make good use to mash it up all in my Project GetFitY’all.

To get your location history in a timeseries of lat/long data points, go to the Google Maps Location history page. You have to sign in using your credentials first of course, so you are only seeing your own location history.


  1. Select the date/time range from the drop down list.
  2. To have a comprehensive list of location data points, click the link that says “Show All Points”.
  3. Click “Export to KML”. You would have downloaded an XML file in the Keyhole Markup Language (KML) format.

To make sense of these location history data points, the best means is to import this in PowerQuery. The steps were described in my previous posts about mashing the data in PowerQuery. The only exception is that I would open an XML file and use the KML file I downloaded. It’s supposed to be a simple step of expanding the 2 columns in PowerQuery which represent the <when> and <coord> elements but for some reason it expands the tables within those 2 columns in a weird way. Weird in the sense that for each <when> element it expands all of the <coord> elements for it. So if I have 1000 data points, I ended up having a total of 1000 X 1000 = 1 million rows. I referred to this blog post to try to expand the tables within the columns, but to no avail in my case.

Hence I did a workaround, a manual way of retrieving all the <when> rows and <coord> rows in two separate queries, then copying and pasting the combined data in a separate spreadsheet, finally saving it as a CSV file. Then I go back to PowerQuery to import the CSV file.

Next I need to retrieve my Fitbit data points. Good thing I already have a REST endpoint which does that for me. The REST API was implemented as a node.js app published at I pass in the query strings which consists of the date and time range and VOILA!

Create a PowerMap, and I get this slightly different visualization below.

googlochistmashup So there you go, the results of VoluntaryTracking.Enabled = true; and then mashing your Google location history with Fitbit data.

The Internet of Things – drawing parallels between the past and now to predict the future

When I was dabbling with the Internet of My Things in my little hobbyist project, GetFitY’all, there were many tell-tale signs that I had experienced this before, like déjà vu. It prompted me to ask questions like what are the differences between the past and now, and could I possibly predict what the future lies for the IoT ecosystem in my most honest and humble opinion.

Devices had  always been connected one way or another. My earliest experience of mucking around with devices transports me back over 13 years ago during a time when I had a payphone sitting on my work desk. It was a big green device, so much so that it obscured the view of me dozing off behind my desk (how nice to doze off in office to get inspiration on how to get things right with the payphone :P). The payphone had IP connectivity, and my work as the tech lead in this project was to repurpose my company’s own pride and joy, a WAP browser called WAPman from being client-side to a server-side implementation that could send commands to the payphone and also listen to events from the payphone (such as key presses and when the handset is hung up). The communication protocol under the wire was ASN.1. The only way to debug the payload was to eyeball the  data structure which was encoded in hexadecimal numbers. *phew* am I glad I didn’t have to wear glasses after that project. I was treating the LCD display on the payphone as a remote display, I was rendering bitmaps and displaying text through specific data structures encoded in ASN.1 to be sent to the payphone. Some of the optimization involves sending the commands in batches so as to reduce network latency. My biggest issue in my server-side implementation was SCALABILITY!


Scalability was an issue because I had to learn within a very short time frame how to repurpose a WAP browser which was essentially a client app written in C++ and then to expose an API implemented in a socket server. The socket server must handle multiple connections from the payphones and scale out processes on-demand to meet the demands of the payphone connections. I certainly did not have any internet scale back then. I only had 2 Sun Solaris servers powering this up in the customer’s datacenter (DC). The good news was that the project was launched and I lived to tell the tale now. It may be a little exaggeration but I still remember the night when I almost froze in the customer’s DC. What happened was that the customer’s PM said there is no time to deploy my code to the servers the next day, I had to do it that night, so he swung by my office at Amoy Street in Singapore, and off I went in his MPV to their DC at Tai Seng Drive.

Fast forward to now, if I look at the state of things from a macro level, what remained the same is the following: we still have “things”, connectivity, server-side processes and people. However the pace of doing things are a lot faster. Let’s look at this and I’ll try to draw parallels at each of those perspectives

  • “Things” – devices have gotten a lot smaller and personal. From a communication device standpoint, who uses a payphone these days anyway? Do you even have a land-line phone at home? Things are very mobile, and the biggest challenge is battery life.
  • Connectivity – IP connectivity is king, but it is not to be taken for granted, connectivity can still be sparse, just accept that “things” could be occasionally connected. Things can connect via other protocols such as ZigBee, Z-Wave and most recently I heard about the Thread consortium. Connectivity could be one-way, or two-way either directly with the server-side processes or through a device gateway.
  • Server-side processes – the order of the day for server-side processes is that it must be scalable, secure, robust . It only makes sense to have less reinvention of the wheel here because a horizontal platform could make things easier and faster time-to-market for an ISV or SI to build a IoT vertical solution. If I had a good cloud-scale IoT horizontal platform, I could easily repurpose my WAP client app as the logic behind command & control module within a horizontal IoT platform/framework.
  • People – ultimately we are the reason why “things” exist, “things” to be connected, and “things” to be managed and “ruled” through some server-side processes. People pretty much determine if we want our “things” to be connected and produce insights and productivity in many ways to make our lives better. Along with that some of our resistance of course.

There are much more parallels that one could draw between the past and now. As for predicting the future, I’ll keep my humble opinions to a later post. What follows this post is a more technical post about another way in which I am mashing location history data points with my Fitbit activity data points.