The Internet of Things with the Azure cloud, Netduino, Windows Phone, and lots of other buzzwords

Tweet about this on TwitterShare on FacebookShare on RedditShare on Google+Email this to someonePin on Pinterest

If you haven’t heard, “the cloud” is kind of a big deal right now. Microsoft Azure is Microsoft’s slice of it  (with 54% of Fortune 500 companies running on Azure today), and is the reason that when you take a photo on your phone it magically appears on your PC (amongst other things). No one understands the cloud, but we know it is powerful Winking smile.


At BUILD 2014, Microsoft announced their plan for allowing everything from your teddy bear to your traffic light (because people totally have these) to connect to Azure. And yes, this includes connecting up a full sized traffic light…

What does that mean? Well, you could hook up your sprinkler system and a soil-moisture sensor to Azure and water your plants from half-way across the world. Or get a push notification to your phone when your significant other raids the cookie jar. Or just about anything else that involves moving data from one place to another without needing to setup any infrastructure.

That also falls in nicely with some stuff I’ve been working on with the team at SecretLabs (the Netduino and AGENT makers) to make it really easy to hook up their devices to Azure, and to get things like sensor reading into the cloud with minimal effort.

So to create a nice little illustration of the IoT running on NETMF, I created a simple demo.  This is based off Netduino and Windows Phone Bitcoin tracker on Azure.  [Steve Teixeira’s awesome traffic light demo at BUILD 2014 was based off of this code.]

(The traffic light demo starts at around 15 minutes)

There are 2 variations (well, 3 if you include the one that was used in the presentation which is very similar to the latter):

BTC + Netduino standalone
In this demo you connect an Ethernet cable to a Netduino, which then pulls the latest Bitcoin price from an Azure service. To display the result (price up/down/steady), we use a traffic light (or some LED’s if you don’t have one handy).

WP + BT + BTC + LEDs
In this demo you pair a Windows Phone with a Netduino (via a Bluetooth module on the Netduino). By tapping any of the first three circles it will tell the Netduino to change the color of the traffic light/LED. By tapping the bottom circle (the BTC one), the Windows Phone will automatically send color commands based on the BTC price.

To start with, let’s look at the Azure service which is common across both variations.

Azure service

For a detailed description of creating the Azure service, check the previous post. The main difference here is that we are using Bitstamp instead of MTGOX (for obvious reasons).

The first step is creating the model for Bitstamp. So open up in your browser and copy the result. In the ASP.NET MVC project, create BitstampTicker.cs in the Models folder. Remove the class in that file so you’re just left with the usings and namespace definition, then press Edit > Paste Special > Paste JSON as classes. A class should be created representing the ticker structure. Rename RootObject to BitstampTicker.

Next we need to create a controller for the Windows Phone app and the Netduino to connect to. For the purposes of this example, we don’t need any other information besides the latest price, plus that saves on bandwidth and on-device computation.

All the controller does is download from the Bitstamp API and return the last value. There is a limit of 700 calls per 10 minutes, so in a real world situation you’d need to cache the result for a few seconds if multiple devices are connecting.


BTC + Netduino standalone

The Netduino code isn’t too complicated. It basically just constantly downloads the latest price and then changes the state of the LEDs. If the price goes down it will show red, up shows green, and stable/no change shows yellow/orange. When the LEDs change to red or green, there is a 30 second delay before it will switch back to yellow – this is to make it clearer because else it would just flash for a second.

Each time a new value is received the onboard LED is flashed to show activity.

If the connection fails then all three colored LEDs will flash a few times and then it will try again.


The red/yellow/green LEDs are wired up to digital ports 8/9/10. The cathode pins each have a 330 ohm resistor and then connect to GND.



WP + BT + BTC + LEDs

In this variation the Windows Phone connects via Bluetooth to the Netduino. Wire and code it like in this post on Bluetooth with Netduino and WP8.

The UI on the Windows Phone app is pretty straightforward, and uses a bunch of visual states to control which circle is selected.


The WP app will do much the same as the Netduino above, and will download the BTC price constantly. Each time it gets a new price it will plot it on a little graph, plus will send the correct color over to the Netduino (via BT) if the Bitcoin circle is selected.

This is the code that does the bulk of the work:


All the Netduino has to do then is check whether it received “r”/”o”/”g” and light up red/orange/green accordingly.



So although these were pretty trivial examples, they’re a good introduction into using external services on anything from a consumer phone/tablet, to a programmable microcontroller.

Note that nothing here is using the new SDKs I talked about above – but once those launch it will be considerably easier to hook your Netduino into the cloud.

Download source for both projects (~47MB)

Tweet about this on TwitterShare on FacebookShare on RedditShare on Google+Email this to someonePin on Pinterest
  • Darren

    Always enjoy reading your articles! Often makes me want to go back to Microsoft.