Use the Force – Biofeedback Heart Monitor with Particle Photon and Microsoft Band


Today’s hack is an inspired submission for Hackster.io’s Are you an IoT Jedi? Join the Particle Alliance! contest.  The idea around the contest is to build something cool in the realm of Internet of Things using any of the amazing devices from Particle.io.  Having deep familiarity with Particle development and being an avid fan of the Star Wars Universe, this is an awesome opportunity to build something cool and possibly win some cool prizes in the process!

In this post, I plan to explain the creative process that lead to my idea, the serendipitous findings that ended up making it more interesting than I had originally planned, and of course the steps to reproduce the project on your own!

This project will introduce you to the concepts of toy hacking / modification, sourcing hardware components at reduced cost, Universal Windows App / Microsoft Band development, and proxy of communication between external sensors (Microsoft Band) and Particle devices using Particle.function().  Keep in mind, if you do not have access to a Microsoft band, there is a sub-project within this project that will allow you to create a modified lightsaber with programmable LEDs.  The end result will allow us to monitor heart rate visually on a modified Lightsaber using sensor data from a Microsoft Band.


When I saw the initial announcement of Hackster.io’s Are you an IoT Jedi? Join the Particle Alliance! contest, my first instinct was to do something related to the iconic lightsaber.   If you have seen the official trailer for “The Force Awakens“, we see the introduction of a new cross-shaped red-glowing lightsaber wielded by the villainous Kylo Ren.  I really wanted to include this iconic item into my hack, but how?

My initial idea centered around building my own lightsaber, which would have been cool.  However, there are numerous groups literally dedicated to this practice and the costs can be a bit prohibitive for some hobbyists / makers.  After attempting to construct something from inexpensive parts at the local Home Depot, I eventually gave up as nothing I could create looked convincing.  Knocked out, but not defeated, I also had to consider, how does one practically introduce a lightsaber into the Internet of Things, especially in a accurate and usable way?

To gather further inspiration, I started perusing the Particle Platform section on Hackster.io.  To my delight, I came across a project by Barry Nusz for displaying your heart rate using a Particle device and Microsoft Band.  Then the inspiration hit me like a ton of bricks.  I could monitor my heart rate from the lightsaber, perhaps while throwing up weights at my local crossfit gym (Shout out to Alief Crossfit).

But… this would not be the end all of the idea, nor the peak of it’s usefulness.  As with many creative hacks, some of the best features appear after building for a specific use case and presenting to others.  Little did I know, I was about to get a serious lesson in real-life manipulation of the Force, or at least conscious control of a usually unconscious body function.

While showcasing the final build of this project at this year’s CodeMash conference, an attendee and partner at our booth (Mitch Muenster) made mention that he could control his heart rate consciously.  Initially, I was in disbelief and asked for a demonstration.  The skeptic in me then asked for about 50 more demonstrations to rule out any sort of foul play or miscalibration.  After exhausting my disbelief (and Mitch for that matter), I realized I had haphazardly constructed a mechanism that could be used to train individuals to control their heart rate using a scientifically validated method known as biofeedback.  See Mitch’s article on this project for a bit more information.



What might be the purpose of building a Biofeedback Heart Monitor?

First let’s explain what exactly Biofeedback is:

When you raise your hand to wave hello to a friend, or lift your knee to take another step on the Stairmaster, you control these actions. Other body functions — like heart rate, skin temperature, and blood pressure — are controlled involuntarily by your nervous system. You don’t think about making your heart beat faster. It just happens in response to your environment, like when you’re nervous, excited, or exercising.

One technique can help you gain more control over these normally involuntary functions. It’s called biofeedback, and the therapy is used to help prevent or treat conditions, including migraine headaches,chronic pain, incontinence, and high blood pressure.

The idea behind biofeedback is that, by harnessing the power of your mind and becoming aware of what’s going on inside your body, you can gain more control over your health. – Source

And here is a quick bit on how it works:

Electrodes, which look like stickers with wires attached to them, are placed on the client’s skin. The client is then instructed to use relaxation, meditation, or visualization to bring about the desired response, whether it be muscle relaxation, lowered heart rate, or lower temperature. The biofeedback device reports progress through a change in the speed of beeps or flashes, or pitch or quality of the tone. The results of biofeedback are measured in the following ways:

  • skin temperature
  • electrical conductivity of the skin, called the glavanic skin response
  • muscle tension, with an electromyograph (EMG)
  • heart rate, with an electrocardiograph (ECG)
  • brain-wave activity, with an electroencephalograph{EEG) – Source

Essentially, the idea is that by making an unconscious body function, such as heart rate, consciously detectable through sound, light, or other stimuli; one can achieve a level of control over these functions.  Some real-life mastering of the Force if you will =)

Applications of this technique have been cited in various scientific journals:


The Food and Drug Administration has approved a biofeedback device, Resperate, for reducing stress and lowering blood pressure. Resperate is a portable electronic device that promotes slow, deep breathing.

However, many biofeedback devices marketed for home use aren’t regulated by the Food and Drug Administration. Before trying biofeedback therapy at home, discuss the different types of devices with your doctor to find the best fit.

Be aware that some products might be falsely marketed as biofeedback devices, and that not all biofeedback practitioners are reputable. If a manufacturer or biofeedback practitioner claims that a biofeedback device can assess your organs for disease, find impurities in your blood, cure your condition or send signals into your body, check with your doctor before using it, as it might not be legitimate. Source



Note: The pieces above will allow you to create the first part of this hack
(Modified lightsaber with programmable LEDs)

To build the full Biofeedback Heart Monitor you will also need:


  • Soldering Iron
  • Solder
  • Electrical Tape
  • Wire Strippers



 Sub-Project #1 – Building a Modified Lightsaber with Progammable LEDs:


1.) Obtaining a Lightsaber casing

I opted to use a Kylo Ren LightSaber Room Light Kit from Milton Toys (which is actually a pretty sweet toy on it’s own).  Keep in mind, you do not necessarily need this ‘exact’ toy if you are interested in replicating this project.  You may be able to adapt a similar toy, for example any of the options available through Hasbro’s Blade Builder line or you could opt for some of the high-end custom parts available from UltraSabers.  If you want a 100% DIY solution, there are a variety of projects that focus around creating a lightsaber using PVC components.



You will want to ensure that your chosen form factor is capable of housing your Particle Photon, which will be used in later steps.

Particle Photon Dimensions and Weight

Headers Dimensions in inches (mm) Weight
With 1.44 x 0.8 x 0.27 (36.58 x 20.32 x 6.86) 5 grams
Without 1.44 x 0.8 x 0.17 (36.58 x 20.32 x 4.32) 3.7 grams


2.) Fitting and Powering a Photon within your LightSaber

I began by taking apart the blade handle from the Kylo Ren Room light kit and removing all unnecessary components.  I knew I would not need the stock electronic components as they would be replaced with a much cooler Particle Photon.  This is a good time to measure wire by laying it against the blade casing to get a good estimate of how long my wire would need to be for installing the LEDs.


The Photon device will require 5v, which you can achieve using a micro-USB cable or a battery source.  I wanted to create a fully contained solution I sacrificed a Particle Core micro-USB cable to create a short ~5 inch cable that could be fit inside the housing.

Creating the shortened cable is straightforward, simply sever the wires, then connect them back to the way they were originally using solder and electrical tape to seal it up.



There was a plastic piece within the kit that was necessary for connecting the blade ends that also housed the electronics.  While necessary, it took up a bit too much space.  To accommodate, I sawed off the portion containing the electronics to make room for my battery (Notice section where brown, black, and white wire enter).


At this point, you should be able to power the Photon device and keep everything nice and snug within the blade housing.


3.) Sourcing and Wiring Up LEDs

We know we want color options and we want to control them with code.  This means we need individually addressable programmable LEDs, often referred to as “NeoPixels”.

I had the foresight of checking the Particle libraries to confirm that there was support for the popular “NeoPixel” brand of programmable RGB LEDs before taking on the project.  While perusing the source code, I noticed that the library supports the WS2812, WS2812B and WS2811 LED specifications.  This means, we can technically source any of these the named LED components for a low-cost 100%  library compatible solution.  I opted for the WS2812B although the steps should be similar for the other listed components.


After obtaining your components (hint: eBay and Amazon). you will want to peruse your favorite search engine for “<Component> Spec Sheet”.  The WS2812B spec sheet can be seen below:


We can glean everything we need to know for connecting these LEDs using the information contained above.

  1. There is a notch on the face of the LED which marks pin 3, knowing this and using it’s relative orientation, we can deduce the location of the remaining pins 1, 2, and 4.
  2. PIN function is described in the lower table, Pin 1 is Power, Pin 2 sends Data Signal Output, Pin 3 is Ground, and Pin 4 receives Data Signal Input.
  3. We can daisy chain multiple LEDs by connecting Pin 1 to Pin 1 of all LEDs and Pin 3 to Pin 3 of all LEDs to power each LED in series.  We will connect Pin 2 (DOUT) to Pin 4 (DIN) to maintain data communication between all LEDs.

It is suggested to test by wiring a single LED up to the photon and verifying that it can be controlled by the Photon using one of the NeoPixel Library examples before proceeding.

Here is the full wiring for our project diagram:



The assembly should look similar to the following.  Notice that I am soldering directly to the LED solder pads, these are very small and require detail to ensure there is no electrical short.  Be sure that the end result fits in your casing and string it through appropriately as indicated in the pictures.


20160108_124213 20160108_124316  20160108_12422420160108_124237

With everything wired up, you can now flash the LightSaber Light Show code to your Photon device!


Sub-Project #2 – Building a Biofeedback Heart Monitor:

In this next segment of our project, we will leverage our modified light saber to control the LEDs using sensor data from a Microsoft Band.  This will give us the ability to see our heart rate, through a visual pulse and color indication.
We will discuss deploying the code to a Windows 10 device and updating the Particle Photon code in this section.
The client Code for this project is packaged as a Universal Windows Project along with a legacy Windows Phone 8.1 project.  The Universal Windows Platform allows us to use a single codebase across theoretically any device capable of running Windows 10 and meeting the requirement of Bluetooth connectivity.  It has been tested on Windows 10 Desktop (Surface Pro 3), Windows Phone 10 (Lumia 1020).

Note:  Raspberry Pi 2 running Windows IoT Core does not work at this time due to a failure when calling “bandClient.SensorManager.HeartRate.RequestUserConsentAsync()

1. ) Ensure that you have installed:

2.) Pair your Microsoft Band to your PC or Phone running Windows 10


  1. ) On Band : Settings => Bluetooth => Pairing
  2. ) On Device : Settings => Bluetooth => Add Device
  3. ) Follow on screen prompts on Device to successfully pair

3.) Grab the Windows 10 Device Code from:  https://github.com/toolboc/PhotonRGBHeartRateDisplay 

4.) Open the WP10PhotonHeartRate Solution

5.) On lines 32 and 33, you will want to find and modify the PHOTONDEVICEID and ACCESS_TOKEN properties


6.) Obtain the PHOTONDEVICEID @ https://build.particle.io/  => Devices => Select <YourDevice> => Click to expand => Copy <DeviceId>


7.) Obtain the ACCESS_TOKEN @ https://build.particle.io/  => Settings => Copy <Access Token>


8.) Deploy to your Device and you should see the program start


9.) Deploy the following Code to your Particle Photon:

10.) With your Lightsaber assembled, Particle Photon Powered, and and the appropriate code Flashed to your Photon, click “Run” to begin collecting Data from the sensor.  You should see the LEDs begin to pulse according to the heart rate.


How it all works:

The Particle device listens for “function call” events in the Particle Code when we define:

bool success = Particle.function(setRGBHR, setRGBHR); 

Meanwhile, on the Win10 Device Client side we publish the current heart reading from the Microsoft Band to the Particle event in the SetRGBHeartRate method of our Win 10 client code.

A few conversions happen along the way to determine the time between pulses and the current color of the LEDs.

More information on the Particle.function method can be found in the Particle Documentation.







This project was very exciting, mainly due to the facets of creativity involved and the accidental discovery of what ended up being the main use case.  Outside of the contest parameters of “Use a Particle Photon” and “Fit a Star Wars Theme”, the space was pretty much wide open to build anything.  Starting with a lightsaber and some LEDs, I wound up stumbling into the subject of biofeedback.  I haven’t personally developed the ability to control the Force (errr, heart rate), with this device, yet…  But, it was all too awesome to run into someone who could.  In fact, since revealing the concept to a few friends, I have found that controlling heart rate consciously is a bit more common than I though.  To date I’ve found three more friends who can control it up or down on command.  It’s pretty wild to see in person!  Maybe it isn’t a surprise that the end result was cool when you consider the contest rules.  After all, it is Star Wars season and it was all too fitting of a contest to occupy my tinkering time during the holidays.  It also gave me a good excuse to purchase one of the awesome toys that have popped up around the franchise.  Hacking + Star Wars, you can’t really go wrong with that =)

Until next time, Happy Hacking!

Internet of Trees – Soil Saturation Monitor Using Particle, Azure, and Power Bi

20151001_193811_resized WP_20151008_16_13_30_Pro WP_20151008_16_13_59_Pro 20151001_191734_resized_1

The Internet of Things is all about employing physical sensors on internet connected devices to gather information about the physical world, typically storing that information up into the cloud for archival or post-processing (i.e. aggregation or machine learning). Some of the more innovative projects in this space solve very interesting problems (Nest Learning Thermostat) and connect something typically disconnected from the internet (Rainmachine Wi-Fi Sprinkler System) that results in an overall improvement in efficiency, productivity, and / or utilization.

In this project, we will use a Particle Photon, powered by solar energy with a battery backup cell to push soil saturation data for six tree zones up into the Azure cloud for visualization in Power Bi.  The purpose being that we will be able to monitor availability of water for these trees and eventually optimize the watering pattern to ensure optimal growth using the collected data.

The project will familiarize you with the following IoT related concepts:

  • Powering a device using solar power and battery backup
  • Best practices for designing testable hardware interfaces
  • Code tricks for reducing power utilization to a minimum
  • Limiting current draw from active circuitry
  • Building a resilient weather-proof enclosure
  • Storing sensor data into the cloud for archiving and processing
  • Visualizing data in Power Bi

Building out systems like this has become simplified due to breakthroughs in small connected prototyping devices which build on tried and true specifications (Arduino).  For example, take a look at some of the innovative devices offered through Particle.io.  They specialize in creating Wi-Fi / GSM connected, Arduino-compatible microcontrollers that can be programmed through a cloud interface.  Not only that, the product they produce is extremely resilient.  In fact, I have 3 devices running in my home that have been operational without any need for maintenance over a 6 month time period.

These resilient web programmable devices can be augmented with cloud-connectivity.  Using three lines of code and a custom library, we can connect our particle device up to the Azure cloud for storage in a mobile service.  These mobile service may be deployed in a single click and offer an immediate scalable database infrastructure, REST API, Identity Management, and ability to provide push notifications to mobile devices.  Essentially, a full production backend in a box, except you leave the management up to the provider, allowing the developer to focus on code.  Finally, we bring in visualization through Power Bi tools which are created specifically for aggregating large datasets on-prem or in the cloud.






1.) Powering Particle Photon using Solar Power and Battery Backup

Disclaimer: I have no idea how electricity actually works, I’m a software developer first =)

To power the Photon device using Solar Power, I opted for the solution employed in Dan Fein’s Particle Photon Weather Station Project on Hackster.io.  It’s pretty straightforward, connect your SparkFun Sunny Buddy to an appropriate Solar Cell (Volts * Amps = Watts), and a battery source (larger capacity = better ability to run without sun).

2.) Best practices for designing testable hardware interfaces

When building circuity, especially when designed with permanent placement in mind, it is imperative to create a testable interface.  What this means is that I can test the circuit outside of it’s place of intended operation.  To do this, I used the Pi Cobbler to create a plug and play interface.

20151001_183344_resized_120151001_152540_resized_1 20151001_191550_resized_1


This allowed me to create a test environment for the completed project.  Notice that I am connecting the interface to two probes, one in a cup of moist soil and another in a cup of dry soil and monitoring the readings as they are sent into an Azure Mobile Service.


3.) Code tricks for reducing power utilization to a minimum

When testing the device, it became clear that I could extend the life of the device when solar power is unavailable (night time, cloudy days, etc.) by employing certain programming tricks.  The first was taking readings at a minimal interval and putting the device to sleep when not in use.  Since we are dealing with soil readings I found a reading every 30 minutes was sufficient.  In the meantime, I put the device to sleep using System.sleep(SLEEP_MODE_DEEP, ReportAndSleepIntervalInSeconds);  to allow the device to operate at a mere 200uA while in the Sleep state.  I also discovered that a good bit of power is used in making web requests.  In my initial code, I was sending one reading per zone, but found that by consolidating all of the data into a single request, I could obtain much longer operation times from the battery.

4.) Limiting current draw from active circuitry

  It makes sense to disable active circuity (Soil Moisture Monitors) while not in use.  By supplying voltage to the Soil Moisture Monitors off of pin D7 on the Photon, I can turn this active circuitry on and off for reading through code without any additional hardware.

//Turn Saturation Sensors On
digitalWrite(D7, HIGH);
//Turn Saturation Sensors Off
digitalWrite(D7, LOW);

5.) Building a resilient weather-proof enclosure

I found the local electronics store in town stocks Gasket Sealed Polycarbonate Enclosures, which are perfect for outdoor electronics projects.  Make sure that your enclosure utilizes a gasket seal and that any wiring in / out of the device can be sufficiently closed off.  In my design, I was able to run a ribbon cable out of the enclosure by sanding down a portion of the outer lip.

20151001_123616_resized_1 20151001_123630_resized_1 20151001_191641_resized_1

7.) Storing sensor data into the cloud for archiving and processing

For this I leverage the AzureMobileService Library for connecting publishing data from the Particle to an Azure Mobile Service.  Simply create a new Mobile Service, under Data section in the Azure Portal for your service, click to add a new table named “Data” and leave all setting default.  On the Photon side, import the “AzureMobileService” library, then add your MobileService name and Application Key to the MYSERVICE and MYKEY variables in your code.

Capture Capture2 Capture3lib

8.) Visualizing data in Power Bi

Once we get the data into Microsoft Azure, it becomes very simple to create a visualization by leveraging PowerBi.  to be honest, I found the tool to be very intuitive but you may wish to consult the documentation on Getting Started.  After connecting to my Data Source, I simply dragged and dropped components until my data looked appropriate.  The whole process took around 15 minutes with no prior training on the tool.  The best part, not only is my data available for viewing in the PowerBi web dashboard, there are also Windows Store, IOS, and Android apps available for persuing the data as well!

PowerBi powerbi2


Creating this system was really interesting, mainly due to my curiosity around the above sub-problems.  I found that using the code tricks mentioned above, I have been able to run the Soil Monitor system for over a month without charge!  In addition, I now have a cross-platform way of viewing my data across devices that took less than 30 minutes to set up.

The data itself is interesting.  We had two recent floods that I was able to view as spikes within my dashboard, this allowed me to know when to resume watering of my trees through my Rainmachine Sprinkler system.  However, I have noticed that readings do change as temperature changes.  This is due to temperature coefficient effects and could be explored more.

I want to stress that while the main data being gathered in this domain may not be your cup of tea, the techniques may prove valuable for other projects.  I recently assisted three teams who placed at the recent TAMUHack Hackathon using techniques outlined in this post (storing data in AzureMobileService, visualization in PowerBi).

Hopefully this post has inspired a few hackers out there!  Let me know what ideas you might have in the comments.  Until next time, Happy Hacking!



Visual Studio IDE improvements announced at Connect

This year marked the first edition of  Connect(), a live virtual event which took place in New York on November 18 – 19, 2015.  The event focused on a variety of announcements surrounding the popular Visual Studio product line including Visual Studio Online and the Visual Studio IDE.  The topics range from utilizing Azure alongside your build process to  language improvements and even Android emulator support!  You can find the complete series online @ Channel 9.

Today’s post is centered on introducing some of the IDE improvements included in Visual Studio 2015 Update 1, released on November 30, 2015 and announced at Connect().  A full listing of these features may be found @ the Visual Studio Blog.  However, rather than introduce these features as a simple write-up, I though it might be more interactive to show some of these additions in action with a video showcase.


These improvements include:

Syntax Highlighting & Intellisense support for Bash Shell Scripts, CMake, Perl, Go, Groovy, Java, Javadoc, Lua, Markdown, R, Ruby, Swift, and YAML

An Interactive Read, Evaluate, Print, Loop (REPL) for C#

Updated Integration and Support for Git / GitHub featuring a new Pull Request Hub

Nuget 3.3 now supported out of box

For a full list, see the Visual Studio Blog






Windows 10 IoT Core Breathalyzer


Windows 10 IoT Core was created to build powerful solutions on low-powered devices with the potential to bridge the physical world into the nearly endless power of the cloud.  It offers a world of synergistic opportunity within the Microsoft ecosystem, which includes technologies such as Visual Studio, .NET, and Microsoft Azure.  All of this is available on a variety of devices including the ever popular Raspberry Pi 2, a $35 computer with 1 GB RAM, quad-core processor, 4-port USB hub, and HDMI out.  And get this, all of this comes packed on a machine about the size of a credit card at a little over 1.5 inches thick.  This little computer also boasts a GPIO hub or General Purpose Input / Output.  This GPIO hub can allow you to take readings from the physical world and even perform operations on physical devices that create actions in the real-world.

Okay, you get the picture, big opportunity, small package, can perceive and effect the physical world…  How can this change your life or the world for that matter?

That all depends, what is the problem that you wish to solve?

In this case, I decided to pay attention to a problem that is encountered very often, especially in college campuses and in the realm of night-life entertainment.  Have you ever known someone to have too much to drink to where it might pose a problem for yourself or others?  We have kiosks which will display arcade games and such, but that really just passes the time.  What if we had an internet connected device that could track your alcohol consumption?  We could identify those who are at risk, or even on their way to becoming a risk to themselves and/or others and intervene.

In this project, we will look at creating an internet connected breathalyzer with cloud-based reporting and logging.  From a technical perspective, this project will introduce us to using an analog sensor for detecting alcohol and a standalone LCD screen for prompting a user with instructions.  We will tie information gathered from the sensor up to an external interface that logs results and displays them locally while also storing into an Azure Mobile Service.

You may have heard that Windows 10 IoT Core runs Universal Windows Platform apps, meaning that our code should potentially run across any device that supports the Windows 10 Core APIs including Windows Mobile, Xbox One, Windows 10 desktop and potentially Hololens.   As such, this implies that it should be able to support UWP controls offered by third parties.  We are going to include a charting package from SyncFusion to prove that this is in fact possible.

Note: *Accuracy of this device is not guaranteed.  Any replication of this device should be considered as a novelty and not a substitute for more scientifically accurate or legally acceptable methods of measurement

Software Prerequisites:



Circuit Layout:
In this picture, the screen is located to the far left, Analog Sensor (orange circle thing) in center, followed by the MCP3208 ADC chip.


RPi2 Pinout:
The pinout diagram will assist in connecting the components of the project


Connecting the ADC:

By design, the GPIO pins on the RPi2 are digital only, but we can read from analog sensors using the MCP3208 Analog to Digital Converter chip. We need to connect the following pins (left side is MCP3208 , right side is Raspberry Pi):

  • DGND -> GND
  • CS/SHDN -> SPI1 CS0
  • DIN -> SPI1 MOSI
  • CLK -> SPI1 SCLK
  • AGND -> GND
  • VREF-> 5V
  • VDD -> 5V

Connecting the MQ2 sensor to the ADC :


With the ADC wired up, we can now connect our Analog Sensor to one of the channels on the ADC for converting it’s Analog signal to a Digital signal that can be rad from the RPi2

  • Signal (A0) -> CH0 (ADC)
  • – -> GND (Pi)
  • + -> 5V (Pi)

Connecting the 1.8″ TFT Color Display Module:


This piece is optional and the code will work regardless of whether this device is connected.  We need to connect the following pins (left side is 1.8″ TFT Color Display Module, right side is Raspberry Pi):

  • VCC -> 5V
  • GND -> GND
  • SCL -> SPI0 SCLK
  • SDA -> SPI0 MOSI
  • RS/DC -> GPIO 12
  • RES -> GPIO 16
  • CS -> SPI0 CS0



The full project and code is contained as a sample within the Microsoft iot-devices project on GitHub.  You may wish to modify the member variables within MainPage.xaml.cs


As mentioned, this project is intended for novelty purposes only as it simply measure alcohol concentration in the air sampled by the MQ2 sensor.  This does not equate to the popular Blood Alcohol Content measurement.  For more information on how to implement that measure, take a look at this research from nootropicdesign.

Modifying this project to support completely different scenarios:

Technically, this project could be modified to report any analog reading over some predefined ambient threshold.  By simply swapping out the MQ2 sensor with say a light sensor or soil saturation sensor, you could monitor sunlight and saturation in a garden.  An audio sensor would allow you to determine if city ordinance audio levels are being violated in a controlled area.  You could even put in a pressure sensor and build a Strongman game like you see at carnivals.

Publishing Data to Azure Event Hubs from Particle Core using Particle.io Webhooks

Spark.io, creators of the most excellent Spark Core device are now known as Particle!  Please keep in mind as a reader that the following information applies to the Spark Core device as well as Particle Core. 

In a previous post I discussed sending messages from a Spark Core Device to Azure Event Hubs by means of an Azure Mobile Service Proxy.  The solution raises a variety of concerns around security and is a bit cumbersome to implement.  It was then revealed to me that Spark (now Particle) employs a WebHooks service that can allow for triggering a request to a remote endpoint.  I had the experience of working together with David Middlecamp from Particle’s engineering team to create an extension for enabling Azure Event Hubs through this service.  In this post, I will guide you through setting up an Particle WebHook capable of sending data to an Azure Event Hub.



  1. Create an Azure Event Hub and configure a Shared Access Policy with the Send permission enabled
  2. Install the Particle CLI tool on your operating system of choice (You may skip the portion on enabling DFU-Util)
  3. Create a new file named webhook.json with a structure similar to the following (See: Particle Webhooks Documentation):
Note: There is a max send size of 255 characters from the Particle Core Device, please keep this in mind when naming variables!  Also, the “azure_sas_token” is very important as it is used server-side by the particle.io WebHooks service to appropriately forward to your Event Hub REST API.
  1. Launch the Particle CLI tool (Open CMD prompt on Windows) and type “particle login” then login with your particle.io credentials
  2. Navigate to the folder containing webhook.json and type “particle webhook create webhook.json”
  3. Verify your webhook was created with “particle webhook list”
  4. Now in the Particle Web IDE you can send data to your Azure Event Hub using “Spark.publish(“NAME_OF_YOUR_EVENT“, payload);”
  5. Verify your data is sending appropriately from the Particle CLI tool by running “particle subscribe mine”


Particle.io is an excellent device for microcontroller prototyping, especially where web connectivity is required.  I have found my Particle Core devices are extremely resilient, being 100% operational after using non-stop for months at a time.  The device is even smart enough to reconnect if the network goes out.  As a result, I believe this device to be a an excellent contender in the Internet of Things space.  Furthermore, now that the device supports Azure Events Hubs via WebHooks, one can relatively easily craft a scenario involving up to 1 million messages coming in per second for processing via Microsoft Azure.  For a full working example, check out this implementation of Particle WebHooks in the open-source ConnectTheDots project from MSOpenTech.

Streaming Xbox One Games to Windows 10 Preview – Tutorial

Earlier today, a variety of exciting announcements were made from Microsoft at this year’s E3 gaming conference regarding Xbox One.  These include backwards compatibility with Xbox 360, playing Xbox One games on Oculus Rift, and streaming games to Windows 10 devices!  I was unaware that this was already available until it was alluded to by a tweet from XboxQwik.  Having the Preview bits for Windows 10 already installed, I decided to explore and wound up figuring out how to enable Xbox One streaming to your Windows 10 device!




Please keep in mind, Xbox One to Windows 10 streaming is currently in preview and subject to change.  For more information, check the official streaming FAQ from xbox.com.  It is very exciting to see the direction the Xbox team has taken with integrating into Windows 10.  I can’t wait to see the final product when Windows 10 is officially released in late July!  Feel free to post your findings and experience in the comments!

Happy Hacking and Game On!

RPi + WinPhone + MS Band + Azure + Excel + Audio-Controlled LEDs = Hot Tub Time Machine From the Future

Hot Tub Time Machine from The Future – Music Entertainment System

The Internet of Things and Houston weather have one thing very much in common.  They are sooooo hot right now!  Inspired by this, I have been thinking a lot about outdoor projects that interact with the cloud, for example my recent Spark Core powered Hot Tub monitor.  This trend is only just now beginning to take off with plenty of exciting projects forming in the space including Rachio’s IoT sprinkler system and this most excellent homebrew soil monitor running on an Intel Edison.  These examples highlight how we can operate on data to produce interactions and inferences which apply to the physical world.  This, I believe, is the core of IoT’s ability to change our lives in the future.

I propose that if the Internet of Things is the future, then projects which incorporate it bring the future to those “things” involved.  Deriving from my personal passion for music and entertaining, I decided to explore how IoT could assist in amplifying those passions.  As a software developer, there is no better feeling than creatively applying our talent to produce extensions of our interests which serve to enhance our experience.   Today’s project combines an array of seemingly disparate technologies to produce a voice-controlled music entertainment system combined with flashing lights and a good old cloud-enabled Excel report for analyzing playback data.   I call it, “Hot Tub Time Machine From the Future”.



All code with instructions on use and configuration can be found in the MusicNet repository.  Simply follow the instructions in the Readme and deploy the Windows Phone project to your device.

How it works:

We leverage the PiMusicBox project to turn the Raspberry Pi into a network enabled Jukebox.  This project is amazing and allows for playing back from a variety of sources including Youtube, Spotify, SoundCloud etc., in addition to SMB share and local files.  After installing and configuring PiMusicBox, simply plug up some speakers and anyone on your home network can now access the device by ip or using the “musicbox.local” hostname.  We then modify the Last.FM Scrobbler plugin on the PiMusicBox to push the playback result into an Azure Mobile Service Table.  We can then connect to this Data Source via Excel and provide a variety of visualizations by using a pivot table over Artist and TrackName.

The Windows Phone app connects to the the Mopidy service running on PiMusicBox to allow for API level access for controlling things like Pause, Play, Next Track etc.  Using the speech API on the phone we define a series of voice commands that can launch the app from Cortana and speak to the PiMusicBox through the aforementioned Mopidy service.  As a result, this just works from the Microsoft Band with no modifcation needed because the Band supports Cortana out the box!

Finally, the blinking lights connect into the Audio Controller and are mounted.  Make sure to place the LED Audio Controller within reasonable proximity to the speaker system connected to the PI.


Voice-controlled music playback with blinky lights and Azure-powered Excel reporting is awesome!  Now the idea is how to take it further!  What if we took the result of the current playing track and displayed it along with current listener satisfaction on a projector of sorts allowing for dissatisfied listeners to upvote or downvote in real-time?  What if Cortana controlled the hot tub itself?  What if the music genre changed depending on the temperature of the hot tub?  What if the “Hot Tub Time Machine” knew what the best music was for the mood based on weather data?  Feel free to leave your suggestions in the comments.  Until next time, Happy Hacking!


Spark Core + DS18B20 + Azure Event Hubs = IoT Hot Tub / Pool Monitor



Summer is here in Houston and there is no better time to get in the water to cool off or warm up.  I am particularly fond of the latter, especially with a good group of friends, food, and refreshments.  The problem is,  it can be hard to tell when the hot tub is ready without actually getting in or looking at a temperature gauge.

Enter Spark Core, a Wi-Fi enabled micro-controller that can be programmed remotely from  a web-based IDE.  I absolutely love this device for ease of programming, portability, and resilience.  Let me reiterate on resilience.  I have successfully ran my Spark Core devices for weeks at a time with zero downtime.  I think these things are pretty much impervious to breakdown so far.  To give a visual output of the temperature, I added a Spark Button device to glow a specific color in relation to the current reading.

I have had alot of fun getting this device to work with the ConnectTheDots project from MSOpenTech.  This project allows for connecting a variety of sensors either directly or through a gateway, into Azure Event Hubs for real-time Streaming Analytics processing.  The results are then displayed in an Azure Web Portal.  I absolutely love this project for it’s ability to walkthrough a serious end-to-end IoT solution and have enjoyed both contributing and delivering IoT Dev Camps based on the project.

Build your Own!

The hot tub monitor solution leverages my previous post on “Sending messages to Azure Event Hub with Spark over AMS API Proxy“.  All code has been contributed to the ConnectTheDots project.  To replicate, simply follow the instructions for setting up the Spark+DS18B20 documentaion and insert into your pool or Hot Tub!  The only modification I made was to use a portable 5v battery source which could be greatly improved using a 5v solar cell.


He’s heating up!


He’s on FIRE!








You may be wondering, is this really useful?  I actually ended up using the device over the weekend, and was happy to see the ring turn red indicating to guests that Hot Tub was in fact ready!  This no doubt got a lot of questions and spawned some discussion on improving the Hot Tub experience further.  Stay tuned for an update on what we plan to implement.  A few hints, it involves a Microsoft Band, Windows Phone App, raspberry Pi, and audio responsive LED driver!


Microsoft IoT DevCamps Announced!

Microsoft has recently announced a series of Microsoft IoT DevCamps taking place across the United States through May and June with more being planned (stay tuned here for updates) or check the official announcement.


Date                          Speaker                                         Locale

5/12/15 Paul DeCarlo Chicago
5/15/15 Stacey Mulcahy New York
5/29/15 Bret Stateham Sunnyvale


We just wrapped up the first event in Chicago, Illinois with an excellent group of industry professionals and IoT enthusiasts.  The content is very exciting as it leverages connecting the popular Raspberry Pi 2 device + Arudnio + WeatherShield and .NET Gadgeteer to an Azure Event Hub for real-time processing and visualization of data through Streaming Analytics and an Azure Websites front-end.  This is a truly hands-on lab where we outfit attendees with the hardware and Azure services to walkthrough a complete end-to-end Iot solution in the cloud.  The lab content comes from the ConnectTheDots project from MSOpenTech.



Introducing IoT


Hands-On Development


Raspberry Pi + Gadgeteer Kits


Rasp Pi + Arduino



Dots Dots Dots Dots Dots Dots Dots Dots Dots Dots Dots Dots Dots Dots Dots Dots Evvvvvveryboddddddy!

Discover how to use Microsoft Azure services as a full, end-to-end IoT solution.  We’ll put Event Hubs, Streaming Analytics, and Websites to the task of presenting data from a variety of hardware devices.

Sending messages to Azure Event Hub with Spark over AMS API Proxy

In this article, I will describe how to publish data from a Spark Core to an Azure Event Hub for real-time processing using Azure Mobile Services as a message proxy.

Spark OS is a distributed operating system for the Internet of Things that brings the power of the cloud to low-cost connected hardware.  Spark provides an online IDE for programming a Wi-Fi enabled Arduino-like device known as the Spark Core.  Azure Event Hubs are a highly scalable publish-subscribe ingestor that can intake millions of events per second so that you can process and analyze the massive amounts of data produced by your connected devices and applications. Once collected into Event Hubs you can transform and store data using any real-time analytics provider or with batching/storage adapters.

To begin, I took an approach of using the Event Hubs Rest API Send Event.  This seemed straightforward, simply create a request with the appropriate Request Headers over HTTP as HTTP and HTTPS are mentioned as supported in the documentation.  However, when sending this request over HTTP, I received “Transport security is required to protect the security token” when including the necessary “Authorization” header.  This poses a bit of a problem as the light-weight Spark device is unable to perform the computations necessary to send SSL requests.

Azure Mobile Services to the rescue!

I first created a new Azure Mobile Service with a Javscript backend:

1- Create Mobile Service

1.5 - Create Mobile Service

Next, I created a new API within the service named “temp”:

2 - Create API


Finally, create an Azure Service Bus with an Event Hub by following the instructions in Hypernephelist’s “Sending data to Azure Event Hubs from Node.JS using the REST API“.


The idea being, that I could successfully send data to the Mobile Service API as documented in Brian Sherwin’s “Wiring Up the Spark Core To Azure” then forward this data to the event hub using the information provided in Hypernephelist’s “Sending data to Azure Event Hubs from Node.JS using the REST API“.  Essentially creating an Proxy via Azure Mobile Services to get data from the Spark in to an Azure Event Hub.


Let’s begin, by building the Event Hub Proxy in the “temp” API.  This API will require Custom Node.JS packages that can be installed by following Redbit’s “Using Custom NodeJS Modules with Azure Mobile Services“.  Follow the instructions and be sure to run an npm install for https, crypto, and moment as these are required to generate the SAS Key for sending data through the Event Hub rest Service.

The actual API code is below (with heavy reliance on Hypernephelist’s example), you will need to modify this by editing in the Azure API editor within the Azure portal, or modifying on disk after cloning per Redbit’s instructions.  Be sure to edit the namespace, hubname, my_key_name, and my_key variables with the appropriate values from your Azure Event Hub.

3 - Azure API Editor

/************************Begin AMS Code**********************

var https = require('https');
var crypto = require('crypto');
var moment = require('moment');

exports.post = function(request, response) {

function sendTemperature(payload) {
// Event Hubs parameters
var namespace = 'EVENTHUBNAMESPACE';
var hubname ='EVENTHUBNAME';

// Shared access key (from Event Hub configuration) 
var my_key_name = 'KEYNAME'; 
var my_key = 'KEY';
// Payload to send
//payload = "{ \"temp\": \"100\", \"hmdt\": \"78\", \"subject\": \"wthr\", \"dspl\": \"test\"," + "\"time\": " + "\"" + new Date().toISOString() + "\" }";

// Full Event Hub publisher URI
var my_uri = 'https://' + namespace + '.servicebus.windows.net' + '/' + hubname  + '/messages';

// Create a SAS token
// See http://msdn.microsoft.com/library/azure/dn170477.aspx

function create_sas_token(uri, key_name, key)
    // Token expires in one hour
    var expiry = moment().add(1, 'hours').unix();

    var string_to_sign = encodeURIComponent(uri) + '\n' + expiry;
    var hmac = crypto.createHmac('sha256', key);
    var signature = hmac.digest('base64');
    var token = 'SharedAccessSignature sr=' + encodeURIComponent(uri) + '&sig=' + encodeURIComponent(signature) + '&se=' + expiry + '&skn=' + key_name;

    return token;

var my_sas = create_sas_token(my_uri, my_key_name, my_key)


// Send the request to the Event Hub

var options = {
  hostname: namespace + '.servicebus.windows.net',
  port: 443,
  path: '/' + hubname + '/messages',
  method: 'POST',
  headers: {
    'Authorization': my_sas,
    'Content-Length': payload.length,
    'Content-Type': 'application/atom+xml;type=entry;charset=utf-8'

var req = https.request(options, function(res) {
  //console.log("statusCode: ", res.statusCode);
  //console.log("headers: ", res.headers);

  res.on('data', function(d) {

req.on('error', function(e) {



/************************End AMS Code**********************

Finally, we need to set up the Spark Core with appropriate code to push data to the API in our Mobile Service. I leveraged the HttpClient as it has great logging features for debugging and is a bit easier to wield compared to Spark’s lightweight TCPClient. I also import SparkTime.h to generate the timestamp for messages from the Spark itself. Simply flash this code to your spark device, taking care to appropriately modify the AzureMobileService, AzureMobileServiceAPI, AzureMobileServiceKey, and deviceName variables. Note that the payload sent in this particular example corresponds to the expected payload in the Connect the Dots Project from MSOpenTech. This implies that there will soon be support for the Spark Core in this amazing project!

4 - Spark Editor

/************************Begin Spark Code******************

// This #include statement was automatically added by the Spark IDE.
#include "HttpClient/HttpClient.h"

// This #include statement was automatically added by the Spark IDE.
#include "SparkTime/SparkTime.h"

String AzureMobileService = "MOBILESERVICE.azure-mobile.net";
String AzureMobileSeriveAPI = "APINAME";
char AzureMobileServiceKey[40] = "MOBILESERVICEKEY";
char deviceName[40] = "SparkCore"; 

UDP UDPClient;
SparkTime rtc;
HttpClient http;

void setup()
    rtc.begin(&UDPClient, "north-america.pool.ntp.org");
    rtc.setTimeZone(-5); // gmt offset

void loop()
    unsigned long currentTime;
    currentTime = rtc.now();
    String timeNowString = rtc.ISODateUTCString(currentTime);
    char timeNowChar[sizeof(timeNowString)]; 
    strcpy(timeNowChar, timeNowString.c_str());
    char payload[120];
    snprintf(payload, sizeof(payload), "{ \"temp\": \"76\", \"hmdt\": \"32\", \"subject\": \"wthr\", \"dspl\": \"%s\", \"time\": \"%s\" }", deviceName, timeNowChar);
    http_header_t headers[] = {
        { "X-ZUMO-APPLICATION", AzureMobileServiceKey },
        { "Cache-Control", "no-cache" },
        { NULL, NULL } // NOTE: Always terminate headers with NULL
    http_request_t request;
    http_response_t response;
    request.hostname = AzureMobileService;
    request.port = 80;
    request.path = "/api/" + AzureMobileSeriveAPI;
    request.body = payload;

    http.post(request, response, headers);
    Serial.print("Application>\tResponse status: ");

    Serial.print("Application>\tHTTP Response Body: ");

/************************End Spark Code********************

Voila! I am able to verify my Spark is appropriately forwarding data to my ConnectTheDots portal!

5 - CTD Portal

We can also verify / debug by connecting to our Spark Core over serial and monitoring the output of HTTPClient

6 - Putty
I absolutely love developing on the Spark device do to it’s simplicity to update and convenient online IDE. Now with the power of Azure, we can real-time analyze data coming from one of these devices!

You can find the latest code included in this project at the DXHacker/SparkEventHub repo on Github.