Sending Data from Raspberry Pi to Thingsboard Cloud

Sending Data from Raspberry Pi to Thingsboard Cloud

Table of Contents

  1. Introduction
  2. Setting up Thingsboard Cloud
    • Using the Thingsboard Cloud Platform
    • Creating a Device and Obtaining Access Token
  3. Setting up Raspberry Pi Hardware
    • Connecting the DHT11 Sensor
    • Hardware Connection Setup
  4. Installing Libraries and Setting up Raspberry Pi
    • Installing Adafruit DHT Library
    • Installing Paho MQTT Library
  5. Reading Temperature and Humidity Data from DHT11 Sensor
    • Running the DHT Simple Test Code
  6. Sending Sensor Data to Thingsboard Cloud
    • Installing Paho MQTT Library
    • Configuring Access Token
    • Running the Code to Send Data
  7. Viewing Telemetry on Thingsboard Cloud Platform
    • Creating Widgets for Temperature and Humidity
    • Adding Widgets to a Dashboard
    • Viewing Sensor Data on the Dashboard
  8. Conclusion

Introduction

In this tutorial, we will explore how to send data from a Raspberry Pi to the Thingsboard Cloud platform. Thingsboard is an IoT cloud service that allows You to manage and Visualize your IoT devices and their data. We will cover the process of setting up Thingsboard Cloud, connecting the DHT11 temperature and humidity sensor to the Raspberry Pi, installing the necessary libraries, reading sensor data, and sending it to the cloud platform. Finally, we will learn how to view the telemetry data on the Thingsboard Cloud platform using widgets and dashboards.

Setting up Thingsboard Cloud

To start, we need to set up Thingsboard Cloud and Create a device that will be used to send the sensor data. The Thingsboard Cloud platform enables us to manage our devices and visualize the collected data. We will follow the steps below:

Using the Thingsboard Cloud Platform

  1. Visit the Thingsboard Cloud Website and create an account if you don't have one.
  2. Log in to your Thingsboard Cloud account.
  3. After logging in, you will be directed to the Thingsboard Dashboard. Close the pop-up window if prompted.
  4. To create a new device, click on the "Devices" tab on the top navigation menu.
  5. In the left panel, click on "Device groups" to access existing groups or create a new one.
  6. Select the desired device group and click on the "Add Device" button.
  7. Give your device a name, such as "Raspberry Pi DHT11," and click on "Add."

Creating a Device and Obtaining Access Token

  1. Within the device group, click on the "Add Device" button to create a new device.
  2. Provide a name for your device, such as "Raspberry Pi DHT11."
  3. Optionally, you can add a label for your device.
  4. Leave other settings as default and click on "Add."
  5. Once the device is created, copy the access token for later use.

Setting up Raspberry Pi Hardware

Now, we will connect the DHT11 temperature and humidity sensor to the Raspberry Pi. Follow the steps below for the hardware connection setup:

Connecting the DHT11 Sensor

  1. Connect the DHT11 sensor to the Raspberry Pi as follows:
    • Connect the sensor's VCC Pin to pin 1 (3.3V power supply) on the Raspberry Pi.
    • Connect the sensor's data pin to GPIO 4 (pin 7) on the Raspberry Pi.
    • Connect the sensor's ground pin to pin 9 (ground) on the Raspberry Pi.
  2. Ensure the connections are secure and properly seated.

Hardware Connection Setup

  1. Connect the Raspberry Pi to your computer using a headless method, such as SSH or VNC.
  2. Power on the Raspberry Pi.

Installing Libraries and Setting up Raspberry Pi

Now, we will install the necessary libraries and set up the Raspberry Pi to Read data from the DHT11 sensor.

Installing Adafruit DHT Library

  1. Open a web browser on the Raspberry Pi and search for "Adafruit DHT Raspberry Pi setup."
  2. Click on the appropriate link to access the instructions for setting up the Raspberry Pi to read temperature and humidity from the DHT11 sensor.
  3. Follow the instructions provided to install the required setup tools on the Raspberry Pi. This may involve running some commands in the terminal.
  4. After completing the setup, open the Thonny IDE on the Raspberry Pi.

Installing Paho MQTT Library

  1. Open the terminal on the Raspberry Pi.
  2. Type the command pip3 install paho-mqtt and press enter.
  3. Wait for the installation to complete. The terminal should display a message indicating that the requirement has been satisfied.

Reading Temperature and Humidity Data from DHT11 Sensor

Using the Adafruit DHT library and the Thonny IDE, we can read temperature and humidity data from the DHT11 sensor connected to the Raspberry Pi.

Running the DHT Simple Test Code

  1. Open the Thonny IDE.
  2. Copy the code provided in the tutorial for reading the DHT11 sensor data.
  3. Paste the code into the Thonny IDE.
  4. Modify the code if necessary, such as changing the pin number from D18 to D4 (GPIO 4) for the DHT11 sensor.
  5. Save the code and click on the "Run" button in the Thonny IDE.
  6. Monitor the output in the console to see the temperature and humidity readings.

Sending Sensor Data to Thingsboard Cloud

To send the sensor data to Thingsboard Cloud, we will use the Paho MQTT library and the access token obtained earlier.

Configuring Access Token

  1. In the code provided, locate the line where the access token needs to be entered.
  2. Replace <your_access_token> with the access token copied from the Thingsboard Cloud platform.

Running the Code to Send Data

  1. Save the code with the modifications.
  2. Click on the "Run" button in the Thonny IDE.
  3. The code will connect to Thingsboard Cloud using MQTT and send the sensor data.
  4. Monitor the console output for any errors or messages indicating the status of the MQTT connection.

Viewing Telemetry on Thingsboard Cloud Platform

After successfully sending the sensor data to Thingsboard Cloud, we can view and visualize the telemetry on the platform.

Creating Widgets for Temperature and Humidity

  1. Log in to your Thingsboard Cloud account.
  2. Navigate to the device that was created earlier, for example, "Raspberry Pi DHT11."
  3. Click on the "Latest Telemetry" tab to view the sensor data.
  4. To create widgets for temperature and humidity, click on the "Show on Widgets" button.

Adding Widgets to a Dashboard

  1. After clicking on "Show on Widgets," a pop-up window will appear with widget options.
  2. Select the appropriate widget type for temperature, such as a card or analog gauge.
  3. Click on the "Add to Dashboard" button and select the desired dashboard.
  4. Repeat the same process for creating a widget for humidity.
  5. Once added, navigate to the dashboard to view the telemetry data in graphical format.

Conclusion

In this tutorial, we learned how to set up Thingsboard Cloud and Raspberry Pi to send temperature and humidity data from a DHT11 sensor to the cloud platform. We covered the steps for setting up Thingsboard Cloud, connecting the hardware, installing libraries, reading sensor data, and sending it to the cloud platform. Finally, we explored how to view the telemetry data on the Thingsboard Cloud platform using widgets and a dashboard.

Most people like

Find AI tools in Toolify

Join TOOLIFY to find the ai tools

Get started

Sign Up
App rating
4.9
AI Tools
20k+
Trusted Users
5000+
No complicated
No difficulty
Free forever
Browse More Content