How to connect Arduino (MKR-1010 + MKR-ENV)

In this tutorial, we will look at how to connect an Arduino MKR-1010 board with MKR-ENV shield to the Kaa platform using the default MQTT-based protocol. You will learn how to create a digital twin of your device and connect it to the platform, collect device telemetry, and view telemetry in the Kaa web interface.

Overview

We will simulate a greenhouse solution, which will allow us to monitor temperature, humidity, and lighting levels. Our MKR-1010 will represent an endpoint in the Kaa platform and report all sensor data. Also, we will interact with the Kaa Web Dashboard to create a digital twin of the Arduino MKR-1010 and view telemetry data.

NOTE: MKR-ENV shield has more than temperature, humidity, and lighting; additionally, it has an ultraviolet(A and B wavelengths) and atmosphere pressure sensors, the data from which will be also reported in our solution.

Playbook

Create Kaa Cloud account

For the tutorial completion, we will need an account in the Kaa Cloud. To obtain it, register on [kaaproject.org][kaaiot.com].

Then go to the free trial page and click “Go to cloud”. A Kaa Cloud account will be automatically created for you.

Create application

Before creating any device, you need to create at least one “Application”

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

Path to "Application" dashboard

2. Click “Add application”.

"Add application" button

3. Fill out the “Display name” and “Description” fields; then click “Create”.

Fill application information

4. Create at least one version of your application. For that, expand the created application, click “Add version”, fill out the fields, and click “Create”.

create application version

Connect your device

1. Go to the “Device management” dashboard and click “Add device” to register a digital twin for your device. It’s called an “endpoint” in Kaa.

add new device

2. Choose the application version from the drop-down menu. You can bump application versions in the application administration page as your devices evolve. Choose and enter an endpoint token.

NOTE: Tokens are used for device identification in communication with the Kaa platform. They are non-empty strings that do not contain the following reserved characters: +, #, /, and .. A token will be autogenerated if you leave this field blank.

NOTE: Metadata is simply key-value attributes that provide certain information about a device, e.g. its location, owner, customer, model, etc.

Click “Create”.

Adding a device. Step 1

3. 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 Arduino MKR-1010.

Adding a device. Step 2

4. Open the sketch_MKR_1010_KAA_integration_tutorial.ino file with the Arduino IDE and fill out the connection parameters:

const char* ssid = "";          // your WiFi network SSID
const char* password = "";      // your WiFi network password
const String TOKEN = "";        // the endpoint token from the previous step
const String APP_VERSION = "";  // the application version name you are working with

5. Upload the sketch_MKR_1010_KAA_integration_tutorial.ino file to your MKR-1010 board.

Now the device can send telemetry data with the temperature, humidity, pressure, illuminance, ultraviolet type A, and ultraviolet type B values. The data payload is a UTF-8 encoded JSON array as below.

[
  {
    "temperature":26.86638,
    "humidity":47.11707,
    "pressure":99.8,
    "illuminance":17.74194,
    "uva":3,
    "uvb":2
  }
]

More details about the payload format are here.

Visualize data from the device

Before visualizing the data, you should edit application configuration for the Endpoint Time Series service (EPTS). EPTS is the Kaa platform’s component that is responsible for transforming raw data samples into well-structured time series. It also stores the time series data and provides access API for other services, including the Web Dashboard.

1. Go to the “Applications” dashboard

Path to "Application" dashboard

2. Expand your application and click on EPTS

Edit EPTS configuration

3. Enable the time series auto-extraction from data samples.

Enable time series auto extract

That’s it, now we can visualize the data.

Each device has a built-in visualization (telemetry chart) widget, which we can use to check incoming data from the MKR-1010 board.

Go to the device details page of the recently created endpoint (by clicking on the corresponding row in the device table). See the data from your MKR-1010 board on the DEVICE TELEMETRY widget.

Device telemetry data

Customize vizualizations

The Kaa platform has many widgets to visualize the data. Users can choose among those widgets to organize their own custom dashboards.

Let’s create a dashboard for a “mushroom greenhouse”. This type of greenhouse requires tracking of temperature and humidity data.

1. Go to “Solutions” section and select the created solution.

select solution

2. Click “Edit”.

edit home dashboard button

3. Set “mushroom greenhouse” for the “Title” field and click “Update”.

edit home dashboard

4. Select the “mushroom greenhouse” dashboard.

5. Click on “Edit mode”.

add widget button

6. Click on “Add widget”.

add widget button

7. Select “Gauges” -> “Radial 180” widget.

8. Click on the “Edit” button on the just added widget (RADIAL 180 GAUGE).

edit widget button

9. Fill out the header form.

edit header form

10. Fill out the “Data source” form

edit widget button

11. Fill out the “Value ranges” form.

edit value ranges form

12. Select the endpoint ID.

select endpoint id for widget

13. Click “Save” to save changes.

14. Click “Publish changes” to save and publish changes.

publish changes

Our widget for temperature tracking is ready.

NOTE: A widget for humidity tracking can be created in a similar way, so it will be skipped in this tutorial.

Custom visualization for a “mushroom” greenhouse is done.

widgets

Manage device settings

Kaa allows you to not only collect (observe) device data but also interact with remote devices by using commands or configurations. We will use the configuration functionality provided by Kaa to maintain optimal light intensity inside our greenhouse. Our Arduino setup has a light sensor, which monitors ambient light intensity in lux, and a LED module for compensating a potential lack of sunlight. We will create a widget that sets the target light intensity level for our Arduino device so that there’s always enough light in our greenhouse no matter what time of the day.

1. Click on “Edit mode”.

add widget button

2. Click on “Add widget”.

add widget button

3. Select “Configuration management” -> “Configuration form” widget.

4. Click “edit” in the right upper corner of the just added widget. The widget’s configuration form will open.

5. Fill out the form.

configuration widget setup

6. Click “Save” to save changes.

7. Set the desired light intensity value (in lux), and click “Save”.

configuration widget

Now the platform will send a new configuration to the device and the device will maintain the light intensity on the desired level.

Congratulations, you have connected, set up, and visualized data from your Arduino MKR-1010 board with MKR-ENV shield in Kaa Cloud!

Here’s a short video of how this setup works.

Resources

  • All tutorial resources are located on GitHub.

Next steps