Meet KaaIoT at Google Cloud Next 25
Kaa Documentation

How to connect STM32

In this tutorial, we will look at how to connect an STM32 board to the Kaa platform using Kaa Arduino SDK. You will learn how to create a digital twin of your device, connect it, send telemetry and receive commands.

#Overview

Our STM32 board will represent an endpoint in the Kaa platform, report its built-in LED state and allow to control it from the Kaa UI.

#Prerequisites

  1. You have installed the Arduino IDE.
  2. You have a STM32 Nucleo board and Ai-Thinker ESP8266 ESP-01 module with Ai-Thinker AT firmware.
  3. You have a Kaa Cloud account.

#Playbook

#Connect your device

1. Go to the “Device management” dashboard in your Kaa Cloud account.

Device management dashboard

2. Choose the application version from the drop-down menu and register a device digital twin by clicking “Add Device” button. It’s called an “endpoint” in Kaa.

3. Enter the desired endpoint token and click “Create”. Tokens are used for device identification in communication with the Kaa platform.

Adding a device. Step 1

4. Copy and save the endpoint token in some file because you won’t be able to see it again in the future. We will use the token in a bit to connect the simulator.

Adding a device. Step 2

5. Open the below sketch in the Arduino IDE and fill out the connection parameters:

6. Install STM32duino Arduino_Core_STM32. You may do it via Arduino Boards manager (search for “STM32 Cores”)

Boards Manager

After the installation, choose the correct board. In this example, we will use Nucleo L476RG, but it should work with other boards, too.

Choose board

Also install Kaa Arduino SDK, TinyGSM and ArduinoJSON libraries using Arduino library manager.

7. Connect ESP8266 to STM32 as shown in the below diagram.

ESP8266 to STM32 connection

The resulting set-up must look like this.

ESP8266 to STM32 connection photo

8. Upload the sketch file to your STM32.

Arduino upload

After the upload, open a serial monitor. If everything is ok, you will see the following output:

Serial monitor 1

In a few seconds, the device connects to the Kaa Cloud and starts sending data.

Serial monitor 2

#Visualize data from the device

1. Enable the time series auto-extraction from data samples for the previously created Kaa application. For that, go to “Device management” / “Applications” / your application / epts.

Edit EPTS configuration

Enable the auto-extraction.

Enable time series auto extract

With this function enabled, Kaa will automatically create a time series for each numeric field it encounters at the root of data samples submitted by your endpoints. You will then be able to view these time series in Kaa UI, no extra configuration is required.

2. Go to the “Device management” page and open device details of the recently created endpoint (by clicking on the corresponding row in the device table). Here you can see all the device telemetry and metadata. Our board is sending one value output_1 that represents a state of an onboard LED. The platform prefixed its time series name with the auto~, meaning it was auto-extracted.

Device telemetry data

You can control the LED directly from this page. Scroll down and find the Command execution widget. Fill out the Command type field with OUTPUT_SWITCH and Command body in JSON field with { "number": "1", "state": "1" } to turn on the LED.

Command execution

"number" is an output number and "state" is the LED state. We have one output pin with the LED connected to it, so we named it the first output or output number 1 in the device firmware. If we have more outputs, we may refer to them in a similar way. To turn off the LED, change "state" to zero: { "number": "1", "state": "0" }.

#Resources

  • All tutorial resources are located on GitHub.
Get Microsoft Silverlight