Sorry, you need to enable JavaScript to visit this website.

You are here

Home IoT Project using Azure

BY Trent Steenholdt 10 November 2020

In this blog series, I’m going to write about how Internet of Things (IoT) enabled my gate, garage door and garden irrigation system using Azure IoT Hub, ESP32, IFTTT, .Net Core and much more. 


This blog was originally posted here in a series of DIY IoT blogs by Trent Steenholdt, Managing Consultant at Telstra Purple on 03 Nov 2020. 


Custom IoT solutions are relatively new to me. Of course, IoT is everywhere these days, but I’ve never worked with my own micro-controllers and utilised services and protocols like Azure IoT Hub, and MQTT. This blog series will not be about best practices in how to do this, but more about my experience and learnings.

Introduction to the project

When COVID-19 lockdowns started in Australia around mid-March 2020, I like many others, ended up having a bunch of free time. With this free time I embarked on some big DIY projects, including putting up a driveway gate and wiring up a motor to it, so it opens like a garage door with a remote. The gate was fantastic, but now, I was all of a sudden stuck with two remotes, one for the gate that used a unique frequency and one for the garage that used a rolling code. At this point, I was wondering what I could do to fix this as there is no universal remote out there to do it all! Trust me, I looked!

A few ideas came to mind, like wiring up the normally open (NO) loops of both gate and garage together. This, however, created the issue if I just wanted to open one, I couldn’t. At this point, I knew the option I had to go down was something entirely custom, so here we are.

Let's get started

First, we need some hardware to run this custom solution. Something like an Arduino, Rasberry Pi, ESP8266 or an ESP32. I wanted something cheap and did all the things, so here is where I made my first mistake and brought a custom ESP32 PCB from eBay. Within 5 minutes of having the PCB, I had killed the ESP32 chip!

My recommendation if you’re starting with IoT, buy a hardware option from a known manufacturer with lots of documentation. Custom PCB’s, while sounding like a great idea (“Hey, this does everything, I can’t go wrong”), are very lacking in the detail. My mistake by sending 5 volts somewhere I shouldn’t have on the PCB was ultimately because the PCB schematic was wrong. Turns out I got a different iteration of the PCB from the documentation they sent me.

What I ended up doing is buying from a local store my second ESP32 development board that had integrated USB and a separate 4-ch relay controller. Not only did I have documentation of the pin layouts, but the people at my local store were super helpful about how I should tackle the project.

So with the hardware, I started putting it all together. Thankfully, following the tip from the guys at my local store and some great videos on YouTube, I was able to get started really quickly.  I did spend some time however getting my IDE set up correctly, so I’d encourage you, learning from my second mistake, to start very small with an example sketch in say Arduino IDE or VSCode and build on from there. 

With everything right to push code from my local PC, I had wired up the first relay to the appropriate GPIO. I had compiled the C++ sketch/code to make use of all four relays with a simple web server front-end. Sure, I only have the gate and garage to control, but why not think big!

I was pretty excited at this point. I could control my gate with just going to an IP address on the network and presto, no more need for two remotes!

The real-world test the very next day

Having this all set up, I learnt something quickly, when not on the network, a web server is no good to me! A bit more back story here, the gate I’ve installed blocks any access to the front of the house and subsequently, the meter boxes. This design decision became a sticking point when the meter reader rang my Ring doorbell on the gate, and I couldn’t let him in because the ESP32 web server was inaccessible. At that point, I knew I had to connect my ESP32 to something like IFTTT so I could control it remotely. 

Now, this is where Azure IoT Hub and the power of MQTT come in. Essentially, I needed my ESP32 to be subscribing (listening) to Azure IoT Hub for it to do a thing when I triggered a change. 

The way I describe MQTT subscribing is that the ESP32, the nagging child, is continually nagging mum, the Azure IoT Hub for the chocolate bar! When Azure IoT Hub finally says yes after persistently saying no, as in changes from 0 to 1, little child ESP32 gets their chocolate (opens the gate).

Setting up the subscribing and publishing of values was relatively straight forward. In my C++ sketch, all I needed to do was to connect to the Azure IoT Hub and set up a function in the loop() that checked if the value had changed, do the function to open the gate and then, have another function then publish back a 0 again.

  void publishAzuredata(char* event, unsigned int value){
  client.publish(event, value);
  void subscibeAzuredata(char* event){
  void reconnect() {
  while (!client.connected()) {
  Serial.print("Attempting MQTT connection...");
  if (client.connect(iothub_deviceid, iothub_user, iothub_sas_token)) {
  } else {
  Serial.print("failed, rc=");
  Serial.println("try again in 5 seconds");
  // Wait 5 seconds before retrying
  void callback(char* topic, byte* payload, unsigned int length) {
  if (String(topic) == "device/deviceID/gate") {
  if (value == "1") {
  digitalWrite(gatePin, HIGH);
  client.publish(topic, 0);
  digitalWrite(gatePin, LOW);
  else if (value == "0") {
  //do nothing really
  //digitalWrite(gatePin, LOW);
  void setup(){
  client.setServer(mqttServer, mqttPort);
  void loop(){
  if (!client.connected()) {
view rawgistfile1.txt hosted with ❤ by GitHub

To interface with Azure IoT Hub itself and change the value of 0 to 1, I had a few options like a Logic App or Function App in Azure. However, to keep it simple, I decided to stick with what I know and write a PowerShell script hosted in an Automation Account Runbook that I could call with a WebHook. That way I could do an HTTP Post with a JSON body that could say open the gate or garage or even both at the same time.

Now that I have the WebHook, I could theoretically call it from anywhere in the world, but I wanted to have a nice way of doing it besides using Postman. Here is where I leveraged IFTTT applets, one for my phone (push notification with IFTTT app when Ring Doorbell rung), and another for Google Assistant.

The result is the ability to control my gate and garage from anywhere in the world, securely and quickly.

Presto, open sesame! 

In the next part of this series, I’ll dive into how I integrated my ESP32 with my Bluetooth enabled garden irrigation system so I can now trigger garden watering from anywhere and using data from the Bureau of Meteorology! Stay tuned


Related Blogs

anonymous's picture

By Tiana Fong


  • iot
  • platform

Telstra's IoT Platform

The Internet of Things (IoT) is a network of physical objects which collects data from the environme...
anonymous's picture

By Michelle Howie


  • messagingAPI
  • Tutorials

Get Started with the TelstraDev Messaging API

Have you ever wondered what an API is and why you should care? Have you ever had a mid-career cri...
anonymous's picture

By Brendan Myers


  • arduino
  • mkr

Introducing the Arduino MKR NB1500

Last year we were proud to announce our partnership with Arduino to help create an (read more about...
anonymous's picture

By Christy Daguia


  • messagingAPI
  • replyRequest

Conversation via Telstra Messaging API

Creating a message thread can be done via Telstra Messaging API, whereby you can continue sending an...
anonymous's picture

By Rajeev Ramani


  • MMS
  • performance

Fine-tuning MMS performance on Telstra's Messaging API

  Here at TelstraDev, we strive to make the best possible developer experience, from the recen...
anonymous's picture

By Marcus Kennan


  • callbacks
  • Messaging SDK

Understanding Messaging API Callbacks - Part 2

Welcome to the second in a two part series on understanding the messaging API callbacks. In our firs...
anonymous's picture

By Marcus Kennan


  • callbacks
  • postman

Understanding Messaging API Callbacks - Part 1

The callback functionality of the messaging API is a great utility allowing you to track the deliver...