Wifi Thermometer with Azure Backend

How I built some small low cost wifi enabled thermometers to monitor the temperatures in rooms and staircases of our airbnb holiday rental

Jannik Weyrich
The Smart Holiday Rental
3 min readDec 10, 2017

--

One of our our airbnb holiday rental apartments

We recently bought and renovated an old house from before the year 1900 where we offer two rooms for rent (mainly via Airbnb). Since we are currently not living in the house I try to automate as much as possible to ensure our guests have a nice, friction-less stay while minimizing maintenance for us as Airbnb hosts.

One important part of automation is analyzing the situation to find room for improvements or to base automation scenarios on. The first home automation application I build was a network of wifi enabled thermometers which report their sensor data to Microsoft Azure IoT Hub. From there we can pull the data to do more automation stuff later on.

The Hardware

The bumblebee: esp8266 & the DHT11 temperature and humidity sensor without case

As I wanted to go with reliable and customizable but low cost hardware I chose the awesome NodeMcu esp8266 and the DHT11 temperature and humidity sensor. If you buy them in bulk you pay around $3,90 for the esp8266 and $1,30 for the DHT11 sensor which is about $5,20 for a full blown wifi thermometer. Remember that you need a micro USB charger for the esp8266.

Later on we want to 3d print a nice case for the thermometer. I will keep you posted on that as well.

The Software

Azure Setup

First you need an Azure account and create an IoT Hub. There is a very nice and detailed tutorial from Microsoft. Here’s the condensed version of it:

  1. Sign in to the Azure portal. I you are new to Azure you can go grab some benefits over here at VS Essentials
  2. Inside the Azure portal select New > Internet of Things > IoT Hub
  3. In the IoT hub pane, enter the information you are asked for
  4. Your IoT Hub takes a few minutes to create
  5. Register a device in the IoT hub for your device.
  6. Click Device Explorer here click “Add” to add a device to your IoT hub.
  7. Device ID: Enter the ID of the new device
  8. Authentication Type: Select Symmetric Key.
  9. Auto Generate Keys: Select this check box.
  10. Connect device to IoT Hub: Click Enable.
  11. Find the device connection string here. We need this later

esp8266 Setup

We want our DHT11 sensor to measure temperature and humidity and send the data via the esp8266 to our Azure backend. First thing to do is to install the development environment for the esp8266. Since the esp8266 is Arduino compatible there is great community support. To get started with the esp8266 and VSCode check out this article by my friend and college Philipp. Once you have your development environment running you can copy the application code over here and paste it into Arduino IDE or VSCode whichever IDE you want to use. Note that you have to install a couple of dependencies for the code to compile. The required dependencies are:

  • AzureIoTHub
  • AzureIoTUtility
  • AzureIoTProtocol_MQTT
  • ArduinoJson
  • DHT sensor library
  • Adafruit Unified Sensor

After you installed all the requirements you should include your Azure IoT Hub connection string and your wifi credentials within the code at the appropriate places.

Then deploy the code to your esp8266. It should now send data to the Azure IoT Hub. The thermometer is now basically plug-n-play. Meaning you can just unplug it and plug it into a power socket within reach of the wifi router you configured within the code and the temperature will be transmitted to Azure IoT Hub.

To monitor the messages which are being sent you can install the iothub-explorer CLI:

npm install -g iothub-explorer

An the open your terminal, bash or shell and run:

iothub-explorer monitor-events <device-id> — login “<IoTHubConnectionString>"

In part 2 of this article I will show you how to store, read and visualize the temperature and humidity data collected by IoT Hub.

--

--