Communicating with Azure IoT using Python

Home - Uncategorized - Communicating with Azure IoT using Python

During last Christmas’ project (the Poor Man’s IoT – read more about it here and here) I wanted to build a small Proof of Concept communicating my home freezer sensor to Azure IoT. However, if you’re not a C# dev, the steps to set up this ‘small’ Proof of Concept can be quite daunting – especially if you’re a data dude used to languages like Python.

“Just” building an easy Field Gateway using some online C# samples required me to install Visual Studio 2015 (as a data guy, all I had was SSDT and SSDT-BI, which is technically Visual Studio but not enough to build a Field Gateway), download the Azure SDK, and some more libraries. Around 7 GB of downloads and several hours later, my laptop was stuffed with awesome libraries I didn’t need, but q.e.d.: it’s cheap and kinda easy (conceptually speaking, or if you code C# on a regular basis) to set up your own IoT proof-of-concept.

Still, what I really wanted was communicating with Azure IoT using my Python prototype application. After all, that was the code I[ref]not being a Xamarin developer[/ref] could test on any laptop, (Android) phone, Raspberry/Banana/Orange Pi, etc.

So. I spent some time figuring out how to do exactly that, stumbled upon an incredibly useful library from Štěpán Bechynský (@stepanb) on Github[ref]https://github.com/bechynsky/AzureIoTDeviceClientPY. Although it’s an earlier version of the API, it still works like a charm[/ref], forked & altered the code a small bit for my own Sensor Hub, and started writing a blogpost.

Then, reality kicked in. When I did my first commit (on March 27th) I already was 11 days late, for the “official” Azure IoT samples on GitHub were updated … with a Python client.

So, two lessons for me personally:

  1. If you don’t have a library, you can always use the web API (which is what @stepanb’s library does)
  2. Double-check your itch before scratching it, you stupid. Pretty sure the release cycle of those awesome Azure devs is waaaaay faster than yours[ref]As a Power BI developer / user, you know what I mean :-)[/ref]

Still, if you’d like to see my code – it’s out there at https://github.com/vstrien/python-sensor-hub. I’ll soon update it to let my Python code use the “official” Python client.

Share

Latest Posts

Categories