Overview
I have been running my private IoT network in a simple setup for more that one year. In the time of writing first script, Azure IoT hub was in beta and it was too complex for simple playing with sensors. The network consists of:
- One RPi1 (just celebrating 4.5 years in 24/7) with climate sensors (temperature/humidity)
- One RPi2 with climate, PIR sensor (movement) and camera (for timelapse).
- These devices are communicating with custom Azure Service via REST API. They just push and pull data to it.
The service itself does some data pre-processing :
- Cleaning of the data and transformation for Azure table storage used for presentation
- Asynchronous generation of thumbnail image of incoming photo for photo gallery)
- IM notifications from movement sensor
- …
RPis are running Raspbian distributions and sensor apps are written in Python because there are powerful libraries for GPIOs management with excellent manuals and tutorials.
From Custom Solution to IoT Hub
Azure IoT Hub is complex and powerful service with ability to consume and produce data to Azure Service Bus, Azure Streaming Analytics Jobs, MS Power BI, etc. With all these services together is it possible to establish a robust micro-service system. So let’s try it.
I found various good tutorial how to connect all this stuff, but what I didn’t find was a simple way how to send data to IoT hub, no SDK or tutorial. But after a little bit of searching, I was successful with some existing solutions hidden over the internet and sum-up all into one toolkit that provides:
- Management of IoT device (listing , registration, removing)
- Library for sending and receiving (device-to-cloud, cloud-to-device) data to/from IoT Hub
AzureIoTRegistryManager
It is a simple console application (C#) that helps you to manage your IoT device, because every device has to have a key to be able to connect to IoT Hub.
Just set a connection string that can be found in IoT Hub instance setting in Azure Portal and run it.
I’m planning to rewrite it to Python lib to have ability to auto-setup IoT device itself.
PythonTools
This project contains a library that can send and receive data from IoT hub via HTTP protocol. A sample usage can be found in main.py. It was tested with Python 2.7.x, but with some little updates (encoding stuff) it should work with Python 3.x too.
Source Code
A source can be found on GitHub. Enjoy!