ESP32 Thermostat Example

In this guide we will take a look at an example application that shows how to use the Nabto Edge platform with an ESP32 MCU. The application we will be looking at is the Thermostat example. You will learn to install Thermostat firmware onto your ESP32 board and then connect to it using an Android or iOS phone.

You may want to familiarize yourself with Nabto Edge by going through the Thermostat example guides using a desktop PC in place of an embedded board first.

Both guides walk you through creating a Nabto Edge device in the Cloud Console. The remainder of this guide will assume you have completed one of the two above guides and as such have some familiarity with the Cloud Console.

What you will need

  1. An ESP32 board. For this guide we’ve used a NodeMCU ESP32 board, but the choice is up to you.
  2. An Android or iOS phone
  3. A wifi network.

Setting up your ESP32

First you should set up your ESP32 development tools as described on the Espressif documentation website. In the rest of this guide, we will assume the following things.

  1. Your ESP32 is connected to a computer
  2. You have a terminal with the command available.

Setting up the Thermostat example

Go to the edge-esp32 github repository. This repository contains integration code to enable Nabto Edge development on ESP32. It also includes some example programs, including the Thermostat example that we will need. You should recursively clone this repository onto your computer and cd to the Thermostat folder, e.g.

git clone --recurse-submodules edge-esp32
cd edge-esp32/examples/thermostat

To configure the example, run menuconfig and navigate through to Example Configuration using the menu. You will be greeted with the following screen.

You should change the “Nabto device ID” and “Nabto product ID” fields into your device and product IDs that you can get from the cloud console. You should also type in your Wi-Fi SSID and password to allow your board to connect to Wi-Fi. Thermostat also specifically has Power status LED GPIO number, this is so that the Thermostat example can blink an LED if one is available. Consult your board’s documentation for GPIO numbers. Finally, you will also need to fill in the Nabto raw private key field.

To fill in the raw private key, head over to our edge-key-tool repository. This is a tool that lets you generate a raw private key offline, you can download the latest version from the Github Releases page on the repository. Once you have the tool downloaded, running it will generate a raw private key and an accompanying fingerprint as following.

$ ./edge_key_tool

Generating new key
PEM Private Key:

Raw Private Key:


As you can see you get both a PEM encoded key and a RAW encoded key. For ESP32 you should use the RAW encoding as it is shorter. Copy the string into your raw private key field in the menuconfig. The fingerprint should be entered into the Nabto Cloud Console under your device’s settings. See the Android or iOS guides linked in the first section for reference on how to do this.

Once you have entered the raw private key into your ESP32 config and registered the fingerprint in the Nabto Cloud Console, you can exit menuconfig and run flash to build and flash Thermostat to your board. Once flashing has completed, you can monitor output with monitor. When the example is up and running, it should output the following line:

I (44705) device_event_handler: Attached to the basestation

Connecting with a phone

Once the example is up and running, it is very simple to connect and play around with the Thermostat example.

For Android you will want to install the Edge Thermostat app from Google Play

For iOS you will want to install the Thermostat app from the App Store

Note that to make it easier for yourself, your phone should be connected to the same network the device is on. This is not a strict requirement as Nabto Edge supports remote connections from separate networks, but it will enable your phone to automatically discover the device using mDNS, which will simplify pairing significantly.

The app pairing procedure is outlined in detail in the thermostat guides for iOS and Android, respectively.