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.

So I want to be an IoT device maker….

So far so good, I’m pretty happy with the Internet of My Things (IoMT) as I got my wearable devices, and a smartphone packed with sensors through good fitness apps installed within. I’d been able to visualize it on a PowerMap. But my curiosity expands because wouldn’t it be good if I could “make” my own thing? I’d been reading, watching and hearing a lot about enthusiast DIY projects which are about programming your own electronics board. Sounds like a whole lot of fun. I’d been hearing Arduino, Raspberry Pi, Intel Galileo (I found out about the free giveaway board at Windows Developer Program for IoT a tad bit too late). So before I plunk in $50 of my hard-earned savings into a board, I must make sure I have the right board for my GetFitY’all project extensions. This article sums it up pretty well.

At this point, I’m more inclined towards a Raspberry Pi B+ board, but then there would be external sensors that I need to buy. Perhaps more important than this is I’m also thinking what would be a good extension to my project. Here are some of my initial ideas:

  • Extend from the world’s smartest bike light project. You can read about it here. When I ride it’s less about the speed, but more about watching my heart beat rate (HBR) so that it doesn’t exceed the so-called maximum HBR for my age which is a simple calculation of 220 – my age. There are other methods to calculate this but I usually set my max to be around 180, have some safe buffer just in case. I want to enjoy biking a lot longer than fainting and potentially killing myself faster, that’s one thought, though there are other reasons that could harm myself too. Other indicators that I like to see is elevation, and it would be good to find out how much I had climbed since the last moment that I almost gave up and wanted to just get off my bike to push. Knowing how much higher I’d climbed would be a good encouragement for me to continue pedaling to the top.
  • Have my board programmed to automatically alert my family that I’d finished my ride and that I’m riding or driving home, including 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. :)
  • Project turn-by-turn navigation on the ground as when I bike. But then this really works when I’m navigating at night, doesn’t it? So not too sure how practical this is yet.

Let’s pause for a while here while I gather more thoughts about the ideas and what seems more practical and fun to extend Project GetFitY’all!

IoT is an ecosystem play between partners

As I was alluding in my previous post about my thoughts about moving up the IoT value chain, the opportunities are aplenty in the IoT space because there is a healthy ecosystem of  different players from the device manufacturers, to SI/ISVs who provide the vertical solutions to the platform/infrastructure providers. Ultimately it is an ecosystem play. I’m not saying that there is no competition, surely competition exists to make the ecosystem a much more vibrant place. The best players I know are inspired by their competitors (as opposed to being delusional about their competitors) because it helps them to get their own act together and be serious in producing valuable innovation.

I have the pleasure of partnering with many great software players within my previous life as a technical evangelist. One of the earliest adopters of IoT was this ISV. The COO of this ISV was a visionary. He wore many hats so he’s not your typical COO who just wanted to focus on scorecards, KPIs, and traffic light indicators (oh I have a good joke about the watermelon effect but let’s save this for another post). He wanted to build an IoT practice. This was back in 2009, not that IoT didn’t exist then, but it was like something I read of some conference or symposium, I have not seen any solutions in this space at all.

He was super excited when he told me about the tones of devices out there that needs to be connected and sounding pretty philosophical about the Internet of Things. He talked about getting his engineering team to focus on building firmware for devices which essentially were agent software that connects to his IoT middleware. I was pitching the idea to him to leverage some Platform-as-a-Service (PaaS) offering in the cloud, and just focus on the core assets of his IoT practice; an IoT middleware and a buzzing professional services unit. Coincidentally I had a colleague from the product team who was coming to run a workshop and a few partner architectural sessions for my partners and he’s really an expert and guru in middleware, messaging systems and how to scale it out really well on the cloud. He was no other than the bloke behind this blog which I am following, Clemens Vasters. Mr COO was delighted and he had one and only request, we needed an NDA before we sat down in front of a white board! Woah this got exciting. I happened to be really good at getting partners to sign NDAs so we got one signed in no time! LOL

The session was intense I must tell you, sparing the details. But the stuffs which we were talking about, it’s all nothing new NOW. What’s available NOW is that a lot of infrastructure and platforms are horizontal in nature, and this allows an IoT practice to focus on their vertical solution’s time-to-market.

When I was building my IoT PoC, GetFitY’all, I was pleasantly surprised how much I could achieve in such a short time. I was able to connect to my devices and sensor apps, and harness the data through friendly self-analytics tools. I am missing other pieces for sure such as the ability for command & control of my devices, configuring the services via rules and workflow. That’s alright, I look forward to all the good stuffs I could leverage along the way as I extend the project.


PowerQuery invokes a GetFitYall API endpoint, and fun with PowerMap

Is that even possible? Yes and I’m talking about invoking that from within the PowerQuery add-in in Excel 2013, and then mucking around with the data which is represented in JSON. Pretty awesome I would think. To the layman, don’t worry about what’s this JSON thing, it’s all transparent to you, just consume the date.

In my previous post, I wrote about the REST API which I had exposed and it allows mashup on-demand which is perfect in the case of self-analytics using PowerBI. Here’s how you could consume this API from within PowerQuery specifically. It’s just another source of data like how I had retrieved the data from Azure Table Storage. Here are the steps:

1. From the PowerQuery ribbon, click “From Web”. Then enter the URL. The URL I’m entering is the REST endpoint I have. It should be HTTPS but then this is just a PoC so I’m keeping things simple here. I pass some query strings in the URL too.


2. Click List which contains an array of mashed up activity data points. Do NOT click “Into Table”, at least not yet.



3.  Now that you have expanded the List into a row of records, click “To Table”.powerquery-step2

4. Then you see the following dialog box, just click OK. No worries, it’ll be fine.


5. Select All Columns.


6. Fix the data type for the fields you care about, especially those you want to be used to visualize in PowerMap. Start with datetime. Click the column header, then at the ribbon, select Date/Time as the Data Type.


7. Fix Steps column as well. Choose Whole Number. This is because you don’t have a fraction of a step, just steps. :)


8. Fix Calories column, and set Data Type as Decimal Number.



9. At the ribbon, click Close and Load To. Then this dialog box pops up. Be sure to tick “Add this data to the Data Model”. The data needs to be in the Data Model in order for PowerMap to work on it after this.

powerquery-step810. The results are a number of rows retrieved from the REST endpoint. Look man, no JSON :)


11. If you want to look under the hood, I happen to be “tailing” the log of my node.js Azure website. Here’s proof that it’s the same 3,014 rows being returned. It took some 7 seconds to execute, this is what I mentioned in my previous post that I might not have optimized the mashup logic.


That’s it on the part of PowerQuery. Let’s do the fun stuff of visualizing this on PowerMap.

1. Map the geography and map level by selecting the lat and long fields.



2. Select the columns which we want to visualize in the PowerMap.powermap-step2


3. Change the width of the “skyscrappers” and the colors of course, and VOILA, you get this birds eye view of where the “action” happens. In this case, I walked the most around the Sydney CBD area. I attended the Mobile Monday Sydney meeting a couple weeks ago. powermap-step3


When I showed this to my wife the other day, she asked why were calories burned even when I was sitting idle in the bus. But then she answered her own question when she said “oh yeah we burn calories so as long as we are breathing!” LOL 😀





This API exposes a singular function at the moment which is to do the following:

  • Mashup on demand – Let client apps consume a mash up of fitness activity data points from different target APIs based upon user ID and time period for a specific date. Note: User ID is not implemented right now because my authorization website is not implemented fully yet.

Common usage of GetFitYall API
1. Self-service analytics tool such as PowerQuery and PowerMap pulls activity data points from HTTP/S endpoint(s) based upon query parameters such as user ID, date, and time period.

1. Get activities mash up




Gets a mashup of activity data points from different fitness APIs based upon user ID and matching timestamps. Currently supports Fitbit intraday API and Strava API. In order to get activity data points down to 1-minute detail level, this API function only works for a specific date as required by the Fitbit intraday API.

Query parameters
userID The Fitbit user ID which has been authenticated and authorized by Fitbit OAuth API
date The specific date from which to pull the Fitbit activity data points. This works with 1 specific day because the Fitbit Get Intraday Time Series function only allows fetching a time series for a specific day but the data points would be down to 1 minute detail for the day. See
afterTime The start of the period, in the format HH:mm
beforeTime The end of the period, in the format HH:mm

Returns: Content-type = application/json
HTTP status codes
200 – OK
400 – Error in request
500 – Error in processing

Example response:

…. omitted for brevity….

This API is implemented as node.js app and deployed into a free/basic Azure website from WebMatrix. The reason why I had chosen node.js is mostly to learn a new server-side technology. The other reasons are:

  1. More programmable for mashup logic.
  2. Leverage many third-party Node.js modules such as node-strava, node-fitbit to rapidly develop prototypes of the GetFitYall API.
  3. Scalable as I configure this as an always on  basic Azure website and scale out accordingly.
  4. Due to the lightweight nature of node.js, the node.js app can handle a large amount of traffic with low overhead

Obvious Bottleneck

One potential problem is the sheer number of mashup requests. When I invoked this endpoint from PowerQuery,  I saw that there were 3 requests for each query, kind of weird but I’m not keen to find out why. Multiplied by thousands if not tens of thousands of users, it is pretty obvious that this would become a serious problem. Recommendation to address this bottleneck as follows:

  1. Cache the HTTP Response

A simple solution is to cache the response for similar requests (based on the same query parameters). The main benefits of caching response are reduced latency and network traffic.

2.   Mashup On-demand Optimization

The node.js app makes asynchronous calls to the Fitbit API to retrieve steps, calories out, floors, and elevation because this is how the Fitbit API works. A Javascript promise is used to determine when all calls are returned before processing the next step. This is another benefit of using node.js and by further using a 3rd party module such as Q, the callbacks hell can be avoided.