Bluetooth Low Energy (BLE) sensor nodes are increasingly utilized across a wide range of applications, including health and wellness, industrial, and environmental monitoring. These devices typically operate with short-range communication, making them ideal for localized data collection in diverse environments. The AWS IoT Greengrass BLE Sensor Gateway enables seamless communication between BLE sensor nodes and AWS cloud services through a Linux-based MPU platform. This solution allows users to securely collect data from a variety of BLE-enabled sensor nodes and transmit it to AWS IoT Core for further processing, analytics, and integration with other AWS services.
In this solution, the STEVAL-PROTEUS1 series microcontroller acts as the BLE node, transmitting sensor data. The application sets up the STM32MPU as the AWS IoT Greengrass BLE Sensor Gateway, allowing it to securely transmits data from the STEVAL-PROTEUS1 devices to AWS IoT Core for processing, analytics, and integration with other AWS services. Additionally, the solution supports remote deployment to the STM32MPU devices operating Greengrass Lite in the field, providing flexibility for managing remote and distributed sensor networks.
AWS IoT Greengrass is a service that extends AWS to edge devices, allowing them to act locally on the data they generate. It enables local execution of AWS Lambda functions, message brokering, data caching, and synchronization with AWS cloud services, even when the devices are offline. Greengrass helps you manage remote devices at scale, securely deploy applications, and keep devices up-to-date with remote software updates.
The Greengrass nucleus lite is a device runtime for constrained edge devices optimized for minimal memory footprint (uses less than 5MB RAM). It has been introduced with AWS IoT Greengrass version 2.14.0 release and is backward compatible with AWS IoT Greengrass generic components, Greengrass V2 API, and SDK.
The BLE Gateway is packaged as an AWS IoT Greengrass V2 component, enabling seamless remote deployment onto STM32MPU devices with the provided deploy.sh
script.
This setup allows you to:
- Manage Devices at Scale: Easily deploy and manage your sensor networks in remote locations without requiring direct interaction with each device.
- Real-time Monitoring: Continuously collect data from sensors in the field and monitor it in real time in AWS IoT Core.
- Remote Firmware Updates: Push updates to devices remotely, ensuring they remain up-to-date with minimal intervention.
- Edge Computing: Run AWS Lambda functions on the edge to process data locally, reducing latency and bandwidth usage by sending only relevant data to the cloud.
-
Developer Prepares the Component:
- The Developer PC clones this BLE Gateway Component.
-
Upload the Component to Greengrass:
- The developer uploads the component artifacts to Amazon S3.
-
Greengrass Deploys to the Gateway Device:
- The developer interacts with AWS Greengrass to deploy the BLE Gateway Component to the STM32MPU Gateway Device.
-
Communication with BLE Sensor Nodes:
- The Gateway Device begins scanning for nearby BLE Sensor Nodes (e.g., health thermometers or other BLE devices).
- The gateway securely collects BLE sensor data.
-
Data Transmission to AWS IoT Core:
- The Gateway Device formats sensor data into MQTT messages, and sends it to AWS IoT Core over the internet.
- AWS IoT Core can be used for further processing, analysis, and integration with other AWS services.
This deployment process ensures you can manage remote sensor networks at scale, monitor data in real-time, and update devices remotely with minimal physical intervention, making it ideal for both on-premise and edge use cases.
This project serves as a proof of concept, collecting data from BLE devices using the Health Thermometer Service UUID. However, it can be easily adapted for a wide range of BLE sensor node applications. Some potential use cases include:
- Remote Health Monitoring: Gather temperature data from personal or home-based health thermometers, leveraging AWS services to analyze trends, detect anomalies, and offer remote health insights.
- Smart Home Integration: Seamlessly connect BLE thermometers with smart home systems to trigger automatic actions, such as adjusting heating or cooling based on temperature readings.
- Medical Device Integration: Enable BLE-enabled medical devices to send data to AWS IoT Core, facilitating centralized data management, real-time analytics, and improved patient care.
- Industrial Equipment Monitoring: Integrate BLE-enabled sensors with industrial machinery to monitor operating conditions in real-time. Data can be sent to AWS IoT Core for predictive maintenance, alerting operators to abnormalities, thereby reducing downtime and maintenance costs.
This gateway is a Python-based application packaged as an AWS IoT Greengrass V2 component for STM32MPU devices. It enables STM32MPU devices to communicate with nearby BLE sensor nodes. The component is deployed remotely from the developer's PC to an STM32MPU board, allowing it to function independently in the field, providing seamless data collection and communication with AWS IoT Core.
Key features of the component include:
-
BLE Device Scanning: The component uses the Bleak library to scan for nearby BLE devices that advertise the STMicroelectronics Manufacturer ID
-
Data Collection: The system subscribes to BLE notifications for temperature, accelerometer events, switch status, and battery status from nearby PROTEUS devices. It processes and formats the received data into structured JSON MQTT messages. For more details, refer to the Data Collection section.
-
Secure MQTT Communication: The component uses the Paho-MQTT library along with TLS encryption to securely send data to AWS IoT Core via the MQTT protocol.
-
AWS IoT Integration: Data collected from BLE devices is published to AWS IoT Core in real time, where it can be further processed, analyzed, and integrated with other AWS services for monitoring, analytics, and decision-making.
By packaging this functionality as an AWS Greengrass component, developers can deploy and manage the gateway remotely, without needing direct access to each device in the field, ensuring scalability and ease of maintenance.
This system collects and processes sensor data from a Bluetooth Low Energy (BLE) device using predefined service and characteristic UUIDs. Incoming notifications are parsed based on the characteristic type, and the extracted data is published via MQTT.
- Service UUID:
00000000-0001-11e1-9ab4-0002a5d5c51b
(PROTEUS) - Characteristics:
- Battery:
00020000-0001-11e1-ac36-0002a5d5c51b
- Temperature:
00040000-0001-11e1-ac36-0002a5d5c51b
- Accelerometer Event:
00000400-0001-11e1-ac36-0002a5d5c51b
- Switch:
20000000-0001-11e1-ac36-0002a5d5c51b
- Battery:
Incoming BLE notifications are processed based on the characteristic UUID, and data is extracted accordingly:
- Ignored: First temperature reading
- Fields:
timestamp
(UInt16)temperature
(°C, scaled by 10)
- MQTT Topic:
{device_name}/temp/{device_address}
- Fields:
timestamp
(UInt16)battery
percentage (scaled by 10)voltage
(V, scaled by 1000)current
(mA, scaled by 10)status
(mapped from a predefined set of values)
- Status Mapping:
0
: Low battery1
: Discharging2
: Plugged, not charging3
: Charging4
: Unknown
- MQTT Topic:
{device_name}/battery/{device_address}
- Fields:
timestamp
(UInt16)event
(mapped from predefined values)steps
(UInt16)
- Event Mapping:
0x00
: No event0x01
: Orientation top right0x02
: Orientation bottom right0x03
: Orientation bottom left0x04
: Orientation top left0x05
: Orientation up0x06
: Orientation bottom0x08
: Tilt0x10
: Free fall0x20
: Single tap0x40
: Double tap0x80
: Wake up
- MQTT Topic:
{device_name}/acc_event/{device_address}
- Fields:
timestamp
(UInt16)switch
state (0
: OFF,1
: ON)
- MQTT Topic:
{device_name}/switch/{device_address}
- The Greengrass BLE Gateway component is deployed onto a STM32MPU device.
- The STM32MPU then periodically scans for BLE sensor nodes advertising specific UUIDs.
- The STM32MPU loops through available BLE devices collecting sensor data.
- The data is structured as a JSON message and sent securely to AWS IoT Core via MQTT.
- The integration with AWS IoT Core allows for real-time processing and analytics.
GG_BLE_Gateway/
├── BleGatewayComponent/
│ ├── artifacts/
│ │ └── com.example.BleGateway/
│ │ └── 1.0.0/
│ │ ├── BleGateway.py # Main BLE gateway script
│ │ └── install.sh # Dependency installation script
│ └── recipes/
│ └── com.example.BleGateway-TEMPLATE.yaml # Greengrass component recipe template
├── config.json # Deployment configuration file
└── deploy.sh # Deployment script
-
BleGatewayComponent/
: Contains the Greengrass component's recipe and its artifacts. -
install.sh
: Installs complete version of Python3, Pip3, Bleak, and Paho-Mqtt if not present -
deploy.sh
: Automates AWS Greengrass Deployment of BLE Gateway Component. Depends on AWS CLI (refer to Required Software section). -
config.json
: Configuration script for deploy.sh.
- Compatible Firmware:
- The STEVAL-PROTEUS comes preloaded with compatible firmware. Both version 1.0.0 and version 1.1.1 are supported. You can use the preloaded firmware or rebuild and flash your own image.
- For detailed build instructions, refer to the official documentation: STSW-PROTEUS.
- A Greengrass-compatible STM32MPU board is required for deployment.
- Supported STM32MPU boards include:
To interact with AWS services from the terminal, you need to have the AWS CLI installed and configured.
-
Installation:
Follow the official AWS CLI installation guide for your operating system. -
Configuration:
After installing the AWS CLI, you must configure it with your AWS credentials (access key and secret key):- Run the aws configure command:
aws configure
- You will be prompted to enter:
- Run the aws configure command:
git clone https://github.com/AlnurElberier/GreenGrass_Lite_BLE_Gateway_Proteus
- Power on your STEVAL-PROTEUS board
- Ensure you are using a comptible firmware version
- For additional support please review Getting started with the STEVAL-PROTEUS1
Follow this lightweight approach to set up AWS IoT Greengrass on STM32MPU devices :
The BLE Gateway Component is packaged as a Greengrass V2 Component and deployment is automated with deploy.sh
.
-
Configure
config.json
Theconfig.json
file contains essential parameters for deploying the BleGateway component using AWS Greengrass. Follow the instructions below to correctly populate the fields.Key Description GROUP_NAME
The name of the AWS IoT Group that will receive the Greengrass deployment. Example: "MyGreengrassGroup"
or"MyGreengrassGroup"
.BASE_BUCKET_NAME
The base name for the AWS S3 bucket where artifacts will be stored. Your AWS account ID will be appended to this name automatically. REGION
The AWS region where your resources (S3 bucket, Greengrass component, IoT Thing) are located. Example: "us-west-2"
.VERSION
The version number of the component. This should match the version of your deployment. Example: "1.0.0"
.COMPONENT_NAME
The name of the AWS Greengrass component being deployed. Example: "com.example.BleGateway"
.{ "TARGET_GROUP": "MyGreengrassGroup", "BASE_BUCKET_NAME": "ble-gateway", "REGION": "us-west-2", "VERSION": "1.0.0", "COMPONENT_NAME": "com.example.BleGateway" }
- Ensure that
BASE_BUCKET_NAME
is unique across AWS (your account ID helps with this). - The
TARGET_GROUP
should match an existing AWS IoT Group Name. - Creating New Versions or Modifying Artifacts:
- If you create a new version or modify artifacts (e.g.,
BleGateway.py
,install.sh
), place them in a directory corresponding to the new version. - The script expects artifacts to be in:
./BleGatewayComponent/artifacts/com.example.BleGateway/<VERSION>/
- This ensures the deployment script can find and upload the correct files.
- If you create a new version or modify artifacts (e.g.,
- Ensure that
-
Run
Deploy.sh
- AWS CLI installed and configured.
- A properly filled
config.json
cd GG_BLE_GATEWAY chmod +x deploy.sh # Ensure it's executable (only needed once) ./deploy.sh
This will:
- Load settings from
config.json
. - Upload artifacts (
BleGateway.py
,install.sh
) to S3. - Update the component recipe.
- Create and deploy the component in AWS Greengrass.
To monitor and debug MQTT messages from your AWS Greengrass BLE Gateway, use the AWS IoT MQTT test client:
-
Open AWS IoT Core
- Sign in to the AWS IoT Console.
-
Access the MQTT Test Client
- In the left navigation pane, select Test under Message Routing.
-
Subscribe to Topics
- Enter the topic filter (e.g.,
HTSTM/temp/
) and choose Subscribe to topic.
- Enter the topic filter (e.g.,
-
Publish and View Messages
- Monitor incoming messages or send test messages to your IoT Core topics.
For detailed instructions, refer to the AWS documentation.
Contributions are welcome! If you'd like to improve the repository or add new features, feel free to open a pull request or submit an issue.