How to Integrate Raspberry pi to KAA IoT dashboard?

by Apr 1, 2021IoT Cloud, Raspberry Pi projects

This article illustrates how to integrate devices with the KAA IoT dashboard. We shall see an example of monitoring Temperature and Humidity on the KAA IOT dashboard over paho MQTT.

Pre-requiste: Basics of raspberry pi, Knowledge about MQTT

Introduction to KAA IOT

Kaa is a highly flexible, multi-purpose, and open-source middleware platform for implementing complete end-to-end IoT solutions. Moreover, Kaa offers a set of out-of-the-box enterprise-grade IoT features that can be easily plugged in and used to implement a large majority of the IoT use cases.

Features of KAA

  • Device Management
  • Data collection
  • Configuration Management
  • Messaging and notifications alert
  • Open IOT protocol
  • Data Visualization

Example of remote Monitoring of temperature and Humidity using Raspberry pi and KAA IoT dashboard

  1. Firstly setup the circuit that interfaces DHT11 with raspberry pi.
Credit-Circuit Basics

Pin configuration

DHT11 pinsGPIO pins of Raspberry pi
VCC5v (GPIO 2)
GNDGnd (GPIO 6)
SGPIO 7
Pin configuration of DHT11 with Raspberry pi
  1. Secondly, let’s Install DHT11 package and enter the below command in terminal
Open the Adafruit_python_DHT folder and enter the above command

3. Additionally now, Let’s install Paho Mqtt package by entering the below command

However, if there are any errors found related to the paho MQTT package then you can refer Paho Python Client. Then, enter the below commands in the terminal.

Enter the above command in the terminal

4. Finally, It’s necessary to signup for a free account

Login page of KAA IOT

5. After that, Go to Cloud and select Root account

Select Root account

6. After that, we shall learn how to get endpoint token. Select Device management and choose devices. In Endpoint token status click on the option create.

Copy the endpoint token and paste it in device configuration section

7. Now, select device management and add a device. Finally, enter endpoint token obtained from previous step

Enter Application Name and endpoint token
  1. Moreover, it’s necessary to copy the endpoint token and application version, paste it into the source code.
Copy and paste Application Version and Endpoint token to source code

9. Edit the application configuration for the Endpoint Time Series service (EPTS). EPTS is a Kaa platform component that is responsible for transforming raw data samples into well-structured time series.

Enable time series Auto extraction

10. Run the source code and in addition to it, check if the endpoint token is active or not. Moreover, the active state of the endpoint token can be checked in the dashboard as well.

Successfully connected to server

After connecting to the server

11. Furthermore, now let’s configure the dashboard

Go to solutions and choose your application.Click on dashboard and choose your widgets

Choose the widget from dashboard

12. Thus, after selecting widgets, it’s important to configure it.

Then, select edit on the widgets and enter endpoint token, application name, time series and save.

13. Finally, you can see the data in the KAA IoT dashboard.

Temperature and Humidity data being displayed on dashboard
Data can be verified in python shell

14. Similarly, the data can be observed in device telemetry as well.

Source Code

import sys
import json
import random
import signal
import string
import time
import Adafruit_DHT
sensor = Adafruit_DHT.DHT11
pin = 7

import paho.mqtt.client as mqtt

KPC_HOST = "mqtt.cloud.kaaiot.com"  # Kaa Cloud plain MQTT host
KPC_PORT = 1883  # Kaa Cloud plain MQTT port

ENDPOINT_TOKEN = ""       # Paste endpoint token
APPLICATION_VERSION = ""  # Paste application version


class KaaClient:

    def __init__(self, client):
        self.client = client
        self.metadata_update_topic = f'kp1/{APPLICATION_VERSION}/epmx/{ENDPOINT_TOKEN}/update/keys'
        self.data_collection_topic = f'kp1/{APPLICATION_VERSION}/dcx/{ENDPOINT_TOKEN}/json'

    def connect_to_server(self):
        print(f'Connecting to Kaa server at {KPC_HOST}:{KPC_PORT} using application version {APPLICATION_VERSION} and endpoint token {ENDPOINT_TOKEN}')
        self.client.connect(KPC_HOST, KPC_PORT, 60)
        print('Successfully connected')

    def disconnect_from_server(self):
        print(f'Disconnecting from Kaa server at {KPC_HOST}:{KPC_PORT}...')
        self.client.loop_stop()
        self.client.disconnect()
        print('Successfully disconnected')

    def compose_metadata(self):
        return json.dumps([
            {
                "model": "Dht11",
                "fwVersion": "v0.0.1",
                "customer": "IOTEDU",
                "latitude": 13.019318,
                "longitude":77.595718,
            }
        ])

    def compose_data_sample(self):
        
      
        humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
        print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity))

        return json.dumps([
            {
                "timestamp": int(round(time.time() * 1000)),
                "temperature": round(temperature,2),
                "humidity": int(humidity)
           
            }
        ])


def on_message(client, userdata, message):
    print(f'<-- Received message on topic "{message.topic}":\n{str(message.payload.decode("utf-8"))}')


def main():
    # Initiate server connection
    client = mqtt.Client(client_id=''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6)))

    kaa_client = KaaClient(client)
    kaa_client.connect_to_server()
    client.on_message = on_message

    # Start the loop
    client.loop_start()

    # Send data samples in loop
    listener = SignalListener()

    payload = kaa_client.compose_metadata()
    result = kaa_client.client.publish(topic=kaa_client.metadata_update_topic, payload=payload)
    print(f'--> Sent message on topic "{kaa_client.metadata_update_topic}":\n{payload}')
    
    while listener.keepRunning:
        payload = kaa_client.compose_data_sample()
        result = kaa_client.client.publish(topic=kaa_client.data_collection_topic, payload=payload)
        if result.rc != 0:
            print('Server connection lost, attempting to reconnect')
            kaa_client.connect_to_server()
        else:
            print(f'--> Sent message on topic "{kaa_client.data_collection_topic}":\n{payload}')
        time.sleep(3)

    kaa_client.disconnect_from_server()


class SignalListener:
    keepRunning = True

    def __init__(self):
        signal.signal(signal.SIGINT, self.stop)
        signal.signal(signal.SIGTERM, self.stop)

    def stop(self, signum, frame):
        print('Shutting down...')
        self.keepRunning = False


if __name__ == '__main__':
    main()

Summary of the article

Finally, the output is observed in the dashboard. Similarly, we noted that temperature and Humidity data from Python shell and Dashboard widgets are same. Moreover, the data collected, can be downloaded as a CSV file and can be used for further analytics use.

Creating a multiplication Skill in Alexa using python

Written By Monisha Macharla

Hi, I'm Monisha. I am a tech blogger and a hobbyist. I am eager to learn and explore tech related stuff! also, I wanted to deliver you the same as much as the simpler way with more informative content. I generally appreciate learning by doing, rather than only learning. Thank you for reading my blog! Happy learning!

RELATED POSTS

Creating REST API CRUD with Node.js, Express and MongoDB

Creating REST API CRUD with Node.js, Express and MongoDB

In our previous blog, we explored the fundamentals of creating a REST API with in-memory CRUD operations using Node.js and Express. Now, we're taking a significant step forward by integrating our product data with a database. This transition is pivotal for achieving...

How to create REST API using Node.js and Express?

How to create REST API using Node.js and Express?

In the vast landscape of web development, creating a robust API is a fundamental skill. APIs, or Application Programming Interfaces, serve as the communication bridge between different software applications. Today, we'll embark on a journey to build a simple blog API...

APIs Vs. Microservices: What is the difference?

APIs Vs. Microservices: What is the difference?

You've probably heard two extravagant terms thrown around when discussing software design and integrations: APIs and microservices. Both topics are important in web application development and design nowadays, and their applications overlap. In this article, we will...

Understanding Salesforce IoT and Its Importance

Understanding Salesforce IoT and Its Importance

In this post, we are going to discuss Salesforce IoT. All across the globe, people are connecting to the Internet to access information, communicate with other people, and do business. But it's not just people that are using the Internet: objects use it too....

Best IoT IDEs For Successful IoT Products

Best IoT IDEs For Successful IoT Products

IoT IDEs are the essential tools that we need in developing our IoT projects. They give us the pathway to connect our Hardware and Software and do magical things using IoT. Consequently, they are useful. IoT is the next big thing in the world. It has taken the whole...

Top 5 Databases to store data of IoT applications

Top 5 Databases to store data of IoT applications

Databases for IoT applications The Internet of Things (IoT) produces massive quantities of data, such as streaming data, time-series data, RFID data, and sensory data, among other things. The use of a database is needed for efficient data management. The existence of...

An overview of Google Cloud Platform for IoT

An overview of Google Cloud Platform for IoT

The cloud technologies have revolutionised the niche of Internet of Things. The cloud technologies for Internet of Things offer a one stop solution for securely connecting devices and securely communicating between the devices. It also offers the tools to process the...

VIDEOS – FOLLOW US ON YOUTUBE

EXPLORE OUR IOT PROJECTS

IoT Smart Gardening System – ESP8266, MQTT, Adafruit IO

Gardening is always a very calming pastime. However, our gardens' plants may not always receive the care they require due to our active lifestyles. What if we could remotely keep an eye on their health and provide them with the attention they require? In this article,...

How to Simulate IoT projects using Cisco Packet Tracer

In this tutorial, let's learn how to simulate the IoT project using the Cisco packet tracer. As an example, we shall build a simple Home Automation project to control and monitor devices. Introduction Firstly, let's quickly look at the overview of the software. Packet...

All you need to know about integrating NodeMCU with Ubidots over MQTT

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

All you need to know about integrating NodeMCU with Ubidots over Https

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

How to design a Wireless Blind Stick using nRF24L01 Module?

Introduction Let's learn to design a low-cost wireless blind stick using the nRF24L01 transceiver module. So the complete project is divided into the transmitter part and receiver part. Thus, the Transmitter part consists of an Arduino Nano microcontroller, ultrasonic...

Sending Temperature data to ThingSpeak Cloud and Visualize

In this article, we are going to learn “How to send temperature data to ThingSpeak Cloud?”. We can then visualize the temperature data uploaded to ThingSpeak Cloud anywhere in the world. But "What is ThingSpeak?” ThingSpeak is an open-source IoT platform that allows...

Amaze your friend with latest tricks of Raspberry Pi and Firebase

Introduction to our Raspberry Pi and Firebase trick Let me introduce you to the latest trick of Raspberry Pi and Firebase we'll be using to fool them. It begins with a small circuit to connect a temperature sensor and an Infrared sensor with Raspberry Pi. The circuit...

How to implement Machine Learning on IoT based Data?

Introduction The industrial scope for the convergence of the Internet of Things(IoT) and Machine learning(ML) is wide and informative. IoT renders an enormous amount of data from various sensors. On the other hand, ML opens up insight hidden in the acquired data....

Smart Display Board based on IoT and Google Firebase

Introduction In this tutorial, we are going to build a Smart Display Board based on IoT and Google Firebase by using NodeMCU8266 (or you can even use NodeMCU32) and LCD. Generally, in shops, hotels, offices, railway stations, notice/ display boards are used. They are...

Smart Gardening System – GO GREEN Project

Automation of farm activities can transform agricultural domain from being manual into a dynamic field to yield higher production with less human intervention. The project Green is developed to manage farms using modern information and communication technologies....