Monitor and control a Raspberry Pi over the internet using AWS IoT Core, MQTT, and environmental sensors from the Raspberry Pi Sense HAT.
Sensor readings from the Raspberry Pi Sense HAT are published over WiFi via MQTT to AWS IoT Core. An IoT Rule routes the data to Amazon SNS, DynamoDB, and AWS Lambda. Lambda evaluates readings against configurable thresholds and publishes control commands back to the device in real time.
| Layer | Technology |
|---|---|
| Device | Raspberry Pi + Sense HAT |
| Protocol | MQTT |
| Cloud Broker | AWS IoT Core |
| Rules Engine | AWS IoT Rules |
| Compute | AWS Lambda |
| Notifications | Amazon SNS |
| Storage | Amazon DynamoDB |
| Language | Python 3 |
Each message published by the device contains:
| Field | Description | Example |
|---|---|---|
SENSOR_TYPE |
Type of sensor reading | TEMP, HUMIDITY, PRESSURE |
VALUE |
Recorded sensor value | 23.4 |
NOW |
ISO datetime of the reading | 2024-01-15T12:00:00 |
NODE_ID |
Unique device serial number | abc123xyz |
AWS IoT Core can support billions of devices and route trillions of messages, connecting physical sensors to the cloud without provisioning custom infrastructure. Its built-in Rules Engine lets incoming MQTT messages trigger serverless workflows, filter data for analytics, and store historical state — seamlessly integrated with the broader AWS ecosystem.
| File | Description |
|---|---|
aws-iot-test01.py |
Test local Sense HAT behavior — prints sensor readings and drives the LED matrix |
basicPubSub.py |
Main script — connects to AWS IoT, publishes sensor data, and receives control commands |
IoTLambdaSensorResponse.py |
Lambda function — evaluates data, triggers SNS alerts on threshold breaches, and publishes commands back to the device |
- Python 3.x
- Sense HAT Library (on Raspberry Pi):
sudo apt-get update && sudo apt-get install sense-hat - AWS IoT Python SDK v1 — installation guide
- An AWS Account with IoT Core access
-
Create a Lambda function using
IoTLambdaSensorResponse.pyas the baseline. -
Update the
TopicArnto point to your SNS Topic ARN. -
Update the region in
boto3.clientcalls if you are not usingus-east-1. -
Attach an IAM Execution Role with these permissions:
Permission Service sns:PublishAmazon SNS iot:PublishAWS IoT Core
-
Register a Thing in the AWS IoT Core console and download:
- Certificate (
.pem.crt) - Private Key (
-private.pem.key) - Root CA
- Certificate (
-
Note your AWS IoT endpoint from the IoT Core console.
Test local sensors:
python3 aws-iot-test01.pyRun the full IoT pipeline:
python3 basicPubSub.py \
-e <your-iot-endpoint>.amazonaws.com \
-r <root-CA-file> \
-c <certificate-file> \
-k <private-key-file>- Raspberry Pi — WiFi-enabled single-board computer
- Raspberry Pi Sense HAT — gyroscope, accelerometer, magnetometer, temperature, barometric pressure, humidity sensors + LED matrix
