WinCoder Blog

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.

Ingredients:

Instructions:

  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”

Conclusion:

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.


Leave a Reply

Your email address will not be published.