Skip to main content
search

© 2021 Excellerate. All Rights Reserved

“If you think that the Internet has changed your life, Let’s think about it again. The Internet of Things is about to change it all over again!” Brendan O’Brien, an American record producer, mixer, engineer, and musician, said this. If we observe the Internet’s history from 20 to 30 years ago, we realize that everything is now changing due to the Internet. Everything is under the control of the Internet. That’s the same will happen with IoT.

Two or more people can connect and share information and knowledge on the Internet. But what about the other things, hardware, home appliance, software, applications, your home, car, mobile phones, and other gadgets? We can see the data transformation on a specific platform from one thing to another.

Choosing a good IoT platform is tricky, with several parameters that need careful consideration. I came across the Kaa ToI platform through peer discussions and readings, and I will share my knowledge about the Kaa IoT platform in this post.

Why Kaa?

Kaa is a multi-purpose, highly flexible, 100% open-source middleware platform for implementing complete end-to-end IoT solutions, connected applications, and smart products. Kaa offers a set of out-of-the-box enterprise-grade IoT features that can be easily plugged in for a quick start. The Kaa platform features include data collection, configuration management, device management, messaging, etc.

When choosing the platform, customers expect to get things easy. Primarily they don’t want extra coding to connect devices to set alerts. In too many cases, customers don’t have such expertise to work with heavy platforms. Keeping this in mind, Kaa is a good platform. We can see too many things in the Kaa platform one by one, but this was the first reason I realized in my exploration to choose Kaa as an IoT platform.

Start with Kaa

  1. Connect your first device with MQTT and HTTP.
  2. Collect data from a device
  3. Sending commands to the device
  4. Data visualization on the Kaa platform
  5. Create Alert
  6. Decision Engine in Kaa

Connect your first device to Kaa with MQTT and HTTP

Kaa automatically generates a new immutable UUID in creating a new endpoint, which is nothing but an endpoint id. To register an endpoint in Kaa, you need an application and version. You can manage them in the Kaa UI under the “Applications” section. Navigate there and use the “Add application” button.

Once an application is created then you can create an application version.

Both, applications, and versions, have:

An auto-assigned and immutable name that usually look like – 8bfvv4b9-ff45-9096-a5dc-23c0r6f653 and an immutable 7bfvv6b9-ff55-4098-a4dc-86c0f5r4f693–v2.

You will use these for client integration, API calls, etc.

Create endpoints

On the Kaa IOT dashboard, go to the “Devices” and add an endpoint. You can also pre-populate the endpoint metadata with values, as shown below,

Connect a client

You will need the endpoint token and application version name to complete the integration with Kaa platform with HTTP and MQTT. These tokens form part of the HTTP URL and MQTT topic. The platform is then able to identify your endpoint and the supporting application version.

You can find the currently registered endpoint application version from the endpoint dashboard. Go to the “Devices” dashboard and click on your endpoint record.

Run the MQTT client from your device terminal. This will initiate a connection from the device to the Kaa platform. The following screenshot shows a sample output after running the client on the device.

Once we connect the device with MQTT, we can see the device metadata on the Kaa platform.

For now, the Kaa platform only supports MQTT and HTTP protocols.

Collect data from a device

We need data samples to provide to the device that will occur on the platform. We can send dummy data for test purposes, or we can send real data generated by the device.

Data sample

Think of a data sample as a block of data in JSON format that a client sends to the platform for data collection.

Let’s consider an example.

Suppose you monitor a greenhouse station that contains three sensors monitoring light, temperature, and humidity sensor. All sensors are connected to one gateway (e.g., an Arduino). Every one minute the Arduino collects the sensor’s values and formats them into JSON format,

{
  "humidity": 40,
  "temperature": 20
}

To send data samples to Kaa hit the Arduino must issue the following command,

curl --location --request POST 'https://connect.cloud.kaaiot.com:456/kp2/<app-version-name>/dcx/<endpoint-token>/json' \
--data-raw '{
  "temperature": 20,
  "humidity": 40
}'

You can see the auto humidity and auto temperature time series points appear on the right side of the “Device telemetry” chart and the chart is filled with data points.

Sending commands to the device

From the Kaa UI, the user issues a command on the device to connect to the platform over synchronous HTTP protocol. At the time of command execution, the platform cannot push commands to the device. There is no way to push such commands to the device as Kaa persists the command and waits for the device to request it for execution. This means that the device with a synchronous protocol must periodically poll the platform for new commands.

Now let’s issue a few commands and make them available for execution by an endpoint. Go to the endpoint’s dashboard and find the “Command execution” widget.

Create Alert

Kaa is integrated with Open Distro for implementing data collection. Open Distro is open-source distribution of Elasticsearch with SQL Support, automatic index management, advance security, alerting and performance analysis.

All data coming from the endpoints need to be automatically ingested with the Elasticsearch index which is attached to your tenant. The Kaa and Open Distro integration makes this possible.

Push telemetry data

The data form the endpoints needs to be pushed into Kaa for defining the Open Distro monitor. To achieve this, execute the below command.

Note: replace app-version-name and end-point-token with your application token and version.

curl --location --request POST 'https://connect.cloud.kaaiot.com:564/kp2/<app-version-name>/dcx/<endpoint-token>/json' \
--data-raw '{
  "co2": 1100
}'

Create monitor

Now, let’s create an Open Distro monitor that will continuously look for data from the endpoints. Open Distro queries the Elasticsearch index for the endpoints telemetry data on a defined schedule. Open Distro results are used as inputs to trigger alerts in Kaa.

In the Kaa UI, click on “Alerts” to access the dashboard in Kibana.

Click “Create monitor”

  • Give the monitor a name (e.g., CO2 alert monitor).
  • In the “How do you want to define the monitor?” field, select “Define using visual graph”
  • Give your tenant ID followed by an asterisk *. The field must look like {your-tenant-ID}*. You can find your tenant ID in the user account information pop-up on the Kaa UI.
  • Select the @timestamp time field from the dropdown.
  • Create the below query in the “Create monitor for” field,
WHEN max()
OF dataSamplelevel.co2
OVER all documents
FOR THE LAST 1 minute(s)
WHERE dataSamplelevel.co2 is greater than 1001

If CO2 is greater than 1001 then we calculate the maximum value across all documents.

Leave the other fields as is and click “Create”.

Create trigger

Once the monitor is created, you will be auto redirected to the trigger page. Open Distro monitor includes specific conditions and when met, the alerts generate, and a few some actions are performed by Open Distro monitor.

Give the trigger a name (e.g., CO2 trigger); leave severity level as is and define “Trigger condition” as IS ABOVE 1001.

Then click “Create”.

Create destination

Once alerts creation is successful, it is time to create a destination. Destinations are used by triggers to reach a specific condition. It is a point where specific action must be executed by the trigger. Destination can be an email address, Slack ID or a webhook URL.

To create a destination, click on the Alerting dashboard, then click on Destinations where you’ll see a button for “Add destination”

Specify the name for your destination (e.g., slack or email ID); In the “Type” field, paste a Slack webhook URL.

Then click on “Add action”.

Report high CO2 level

We have now defined an alert that sends alerts about CO2 level. If the CO2 level is greater than 1001, it should send a notification on Slack. Let’s set CO2 level as 1200 to test this alert.

Run the following command for setting the CO2 level to 1200. Replace app-version-name and end-point-token with your application token and version.

curl --location --request POST 'https://connect.cloud.kaaiot.com:546/kp2/<app-version-name>/dcx/<endpoint-token>/json' \
 --data-raw '{
  "co2": 1200
}'

Once you set the upper value for CO2 level then within a second you should receive a notification in your Slack channel:

View Alerts history

If you want to see the Alerts history, then click on dashboard.

Decision engine in Kaa

It is possible to implement decision logic or decision tree with the Kaa platform in the current experiment. We have the data for the CO2 level, and we created a monitor to send a few alert messages if the CO2 level is high. In this next step, if the CO2 level remains constant then we need another alert that tries to achieve a specific decision logic.

We can create a second monitor to check the constant value for the co2 level. And send an alert on Slack.

About the author

Gayatri Uparate

Gayatri is a machine learning engineer with Synerzip. She is actively involved in developing ML models and has done work in text and image processing and data extraction using Python. Gayatri is well versed with Python and Javascript and holds an M.Tech degree in Computer Science from Rajaram Bapu Institute of Technology Islampur.