AWS IoT - Device data to dashboard in 10 minutes - A demonstration
3 min read
1 year ago
Published on Jan 23, 2025
This response is partially generated with the help of AI. It may contain inaccuracies.
Table of Contents
Introduction
This tutorial provides a step-by-step guide on how to connect an IoT device to AWS IoT Core, store telemetry data in Amazon Timestream, and display this data in an Amazon Managed Grafana dashboard. This process is crucial for monitoring and visualizing data from IoT devices, enabling real-time insights.
Step 1: Understand the End-to-End Architecture
Before diving into implementation, familiarize yourself with the overall architecture. The key components include:
- AWS IoT Core: The service that connects your IoT devices to the cloud.
- Amazon Timestream: A time-series database service to store telemetry data.
- Amazon Managed Grafana: A visualization tool to create dashboards for monitoring data.
Step 2: Create the AWS IoT Core Thing
- Log into the AWS Management Console.
- Navigate to the IoT Core service.
- Select "Manage" and then click on "Things".
- Choose "Create thing".
- Input the necessary details for your IoT device:
- Name your Thing.
- Optionally, add a type and group.
- Click "Create thing" to finalize.
Step 3: Send IoT Client Data to AWS IoT Core
- Use the AWS IoT Python SDK to connect your device to AWS IoT Core.
- Install the SDK:
pip install AWSIoTPythonSDK - Use the following code snippet to establish a connection:
from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient client = AWSIoTMQTTClient("MyClientID") client.configureEndpoint("YOUR_ENDPOINT", 8883) client.configureCredentials("YOUR_ROOT_CA_PATH", "YOUR_PRIVATE_KEY_PATH", "YOUR_CERTIFICATE_PATH") client.connect() - Replace
YOUR_ENDPOINT,YOUR_ROOT_CA_PATH,YOUR_PRIVATE_KEY_PATH, andYOUR_CERTIFICATE_PATHwith your specific configurations.
Step 4: Modify the Sample Client to Send a JSON Payload
- Create a JSON payload that includes the telemetry data you want to send. For example:
{ "temperature": 25, "humidity": 60 } - Publish the JSON payload to the desired topic:
import json payload = { "temperature": 25, "humidity": 60 } client.publish("your/topic", json.dumps(payload), 1)
Step 5: Create the Amazon Timestream Table
- Go to the Amazon Timestream console.
- Choose "Create database" and input a name for your database.
- Click “Create table” and specify:
- The name of the table.
- The retention policies for your data.
- Click "Create" to finalize the table setup.
Step 6: Create the AWS IoT Core Rule
- Navigate to the AWS IoT Core console.
- Select "Act" and then "Rules".
- Click "Create rule" and define the rule:
- Name your rule.
- Set the SQL query to select data from the incoming messages.
- Choose "Add action" and select "Write to Timestream".
- Configure the action with your Timestream database and table.
- Click "Create" to save the rule.
Step 7: Verify the Data in Amazon Timestream
- Go back to the Amazon Timestream console.
- Navigate to your created database and table.
- Run a query to check if the data is being received correctly:
SELECT * FROM "your_database"."your_table" - Ensure that the telemetry data is visible in the query results.
Step 8: Create the Amazon Managed Grafana Dashboard
- Open the Amazon Managed Grafana console.
- Choose "Create workspace" and follow the prompts to set up.
- Once created, click on "Dashboards" and then "New dashboard".
- Add a new panel and select Timestream as your data source.
- Configure the panel to visualize the telemetry data from Timestream:
- Select the database and table.
- Choose the metrics to display.
- Save your dashboard for future access.
Conclusion
By following these steps, you have successfully connected an IoT device to AWS IoT Core, stored data in Amazon Timestream, and visualized it in an Amazon Managed Grafana dashboard. For further exploration, consider integrating additional data sources or expanding your dashboard with more complex visualizations.