I have things, and I have Internet. Now I want to Internet my things…
I recently started playing with Azure Event Hubs and wanted to do a basic IoT sample with a real device and learn lots of new stuff. If you haven’t heard of Azure Event Hubs before, ¬†Event Hubs is 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.”
In this post, the objective is to analyze Kinect sensor readings in real time using Azure Event Hubs and monitor meaningful events in a website.
I want to know in real time(ish) when a security breach is produced. In my fictitious scenario, a security breach is produced when someone gets too close to a person (have you seen The Island?) or a guarded object (if movies teach us anything, is that a laser grid alone won’t cut it. I don’t have access to a laser grid, either). Ok, so basically, I need to walk around with a Kinect strapped to my chest or strap a Kinect to a Faberg√© egg).
I set out to do the following:
- Dump the Kinect’s depth sensor readings in an event hub.
- Analyze the stream of events using a worker role in real time (using the EventProcessorHost approach) and produce a proximity alert whenever I get too close to the sensor (say, 50cm).
- Display the proximity alerts in a monitoring website as they occur.
You can checkout the progress¬ here. It will require that you have a Kinect, the Kinect SDK (1.8) and a Microsoft Azure account.
The big picture
The Sample Solution
I’ll make a brief overview of the projects in the sample.
The DepthRecorder project: It is actually the Depth-Basics sample of the Kinect SDK with a little twist. Every time a frame is received, I obtain the known distance of the closest pixel of the frame, prepare a new KinectEvent object and send it to the¬†event hub. At roughly 30fps, it¬īs fun to watch how events quickly start to accumulate. (Checkout the ServiceBus explorer tool, too!)
The Cloud project: This project contains two worker roles. The EventsConsumer worker¬†is responsible for analyzing the stream of events and produce a proximity alert whenever an event reports a depth reading of 50cms or less. As alerts appear, the worker role will dump them in a Service Bus queue. The AlertsListener worker¬†is responsible for reading the alerts queue, and pushing alert messages down to the monitoring website (using SignalR)
The Web project: It’s an MVC project that will display the alerts on screen as they occur. It receives SignalR messages and will display a big red alert. For the time being, it won’t distinguish alert sources, but we’ll work on that
Work in progress
This is probably not the simplest approach, but I wanted to separate and decouple components as much as possible, because i wanted to use queues and because it’s fun :). So probably, for simplicity’s sake, we could get rid of the alerts queue and the alerts listener worker, and push alerts directly to the website.
check out the following links for further reading:
ScottGu’s blog post¬†with links to more information
So there you go. Happy Learning!