Nabto Edge Thermostat Example

Nabto Edge Thermostat is an end-to-end Android application that showcases how a client application may use the Nabto Edge Client SDK to communicate with Nabto enabled devices. Specifically it is an example of using Nabto Edge on iOS for implementing an IoT remote control scenario. The full source code is available in github.

This guide will walk you through step by step until you have a working Nabto Edge Thermostat setup with a client application and a device that can communicate directly with each other. After following the guide, you will be able control your (virtual) thermostat:

The example applications in this guide are all pre-compiled versions to get you started quickly. The source code is available for both the Android app and the simulated thermostat.

Install Android App from Google Play

First, an Android phone is required. Go to Google play and install Nabto Edge Thermostat. After installation, find “Edge Thermostat” on your phone and open it. You should be greeted by the following screen.

Initialize Nabto Virtual Thermostat Device

Next we will download an example device that can run on a desktop platform (macOS, Windows or Linux). The source code is also available so you can build for your exact system or make changes as needed. In production you would run the Nabto embedded device software on a microcontroller or similar.

  1. Go to https://github.com/nabto/nabto-embedded-sdk/releases
  2. Download the latest thermostat binary for your platform (linux, macOS or windows).
  3. Run the binary with ./thermostat_device

The thermostat_device executable will save its configuration and state files in its home dir. The home dir defaults to $HOME/.nabto/edge on Unix and %%APP_DATA%%/nabto/edge on Windows. The home dir can be changed with --home-dir.

Note that you will get an error that tells you to make a device.json file. This file will inform the device executable which product id and device id it should use when connecting to the Nabto Edge platform. How to obtain this information is described in the following.

In Nabto Edge, devices are organized into products, so you need both a product id and a device id. Products and devices can be registered in the Nabto Cloud Console which is the next step.

Create a device in the cloud console

In this step we continue with creating a Nabto Edge device. Go to https://console.cloud.nabto.com/ where you can register and log in to the Nabto Cloud Console. Once you have registered and logged on, you will be greeted with the home page. From here click on the Products link in the sidebar.

Now press New Trial Product to create a trial product. Creating a product will send you to the settings page for your new product. Return to the products page by clicking Products in the sidebar again. Now you should see that a product has been added to the list. Take note of the Product ID column.

Now we need to create a device. Click on devices on your new product.

At the moment there are no devices registered for this new product.

Press Create Single Device to create a device that we can use. You will notice a new device is immediately added to the list of devices below, and the device has a Device ID column. Click on the device to open its settings.

Take note of the Device Configuration section, there will be a JSON snippet containing exactly the information that needs to be in the device.json file of the former section in this tutorial. Do not leave this page yet, we will need to use the Fingerprint section in the next part.

Setup and Run the Nabto Virtual Thermostat

Copy the JSON snippet into a new ./config/device.json file where . (the current directory) is the directory where you put the thermostat_device executable. Now start up the device again with the following command

./thermostat_device

The terminal prints the device configuration - some of the information can be used later when pairing from the client app:

######## Nabto thermostat device ########
# Product ID:                  pr-eofozbji
# Device ID:                   de-rhrhcebt
# Fingerprint:                 1bf49a3a53c29ec42d4d72d08dc85a60bea90fd2feaf9e05e5a41b916c5fd540
# Pairing String:              p=pr-eofozbji,d=de-rhrhcebt,pwd=secret,sct=uYZPmFTTAaR
# Nabto Version:               5.11.0
########

Note that the device will also immediately print errors about a server not recognizing the fingerprint of the device. This is the cloud console that needs the fingerprint of the device before it will allow it to connect. Copy the fingerprint string from the thermostat, ie in the above example it would be the full 1bf49a3a53c... string.

Then paste it to the device settings page from the last section and paste the fingerprint into the Fingerprint input in the settings page.

Now press save and restart the device executable. It should now print Attached to the basestation after a couple of seconds. Congratulations, your thermostat device should now be available to use with the Nabto Edge Thermostat client app. The next section will explain pairing and using the app.

Use Android app with the Nabto virtual thermostat

Once you have your thermostat device up and running, you can use the Android app to control it.

Pairing the app with a device

Open the app on your phone and press the + button to go to the pairing tab.

If your phone is connected to the same local network as the computer that is running the device application, then you can use mDNS discovery to simplify pairing by clicking the upper button:

The alternative is to add pairing information obtained from the device application in the lower field.

Once you are connected to a device, discovered locally or connected using the entered information, you can complete the pairing: Enter a username as you would like on the target device - the default is likely fine, it is derived from your mobile device name (change it if already taken on the target device). And provide a name for the device for your own bookmarks in the app:

Using the device

After pairing, the device is bookmarked and ready for the next time you start the app - for local or remote access. A green icon means the device is online and you have been granted access. A red icon means something prevents you from connecting to the device, e.g. the device is offline (tap the device for details).

Controlling the thermostat

On the thermostat page, you can interact with the virtual thermostat - e.g., set the temperature and the operation mode.