cancel
Showing results for 
Search instead for 
Did you mean: 

How to detect a door knock with STM32U5 IoT discovery kit and AWS

Alnur ELBERIER
Associate II
This article extends the integration of the modular AWS FreeRTOS™ software by reconfiguring the original project to send an MQTT message to AWS and performing an action using the Rule Engine. This project runs on the STM32U585 IoT discovery kit and connects to AWS. The article focuses on running the Non-TrustZone version of the project in Windows OS.

1. Introduction

In this article, we use AWS IoT Core to monitor whenever a knock was detected on a door. Once a door knock event has been detected. It triggers an IoT rule that sends an alert to the end-user.
The board that is used is the B-U585I-IOT02A board. It comes with a multitude of motion-based functionalities such as a magnetometer, accelerometer, gyroscope, pressure, Time-of-Flight, and gesture-detection. It also has some environmental sensors such as temperature and humidity. For this extension of the project, we use motion-based sensors, specifically the ISM330DHCX sensor that is already integrated with the discovery kit.
In this tutorial, you are able to modify the original project linked below to change what the motion sensor data sends to AWS IoT Core, where instead of a constant stream of sensor data, it will only show a single message whenever the board detects a double tap event.
 

2. Requirements

  • A working build of the original project
  • Refer to this article to get the original project up and running
 

3. Modifying the original project


Using the GitHub repository here, you can use the same unix-like console application you used to clone the original project files. The only difference is that we will be replacing the files in the original project with the ones that are in the GitHub repository linked above, so it is recommended to clone them into somewhere easily accessible.
git clone https://github.com/timdenisiuk/Double-Tap-Detection-Updated-Files.git
Once cloned, open both the updated files and the root directory of the original project. Notice how the folder names in the updated files match some of the ones in the original project. This is done to easily find which files need to be replaced.
Note: It is highly recommended that you create a backup of the original project in case something goes wrong in the file transfer process. This saves you time from having to reclone the original project and rebuild it again.
 

 


4. Testing the modified project


After all the files have been transferred, rebuild and reflash the project. Note that you do not have to reprovision the board again, as it sends the MQTT messages to the same device (thing) in the AWS IoT Core.
Log back into aws.amazon.com with your IAM user. Navigate your way back to AWS IoT Core and click on MQTT test client on the left side bar.
In this case, we want to clearly observe that a double tap event was detected and sent through the MQTT test client. On the topic filter search bar, type in
<name of board given through provision script>/motion_sensor_data
and press subscribe. Once done, physically tap on the board twice with about a half second interval between taps. If all goes well, you should see a message pop up.
1432.jpg

5. Setting up the alert system


The alert system uses the rules engine, a free service that monitors MQTT message to trigger an action once it detects the correct message. The rule sends an email as soon as it is triggered
To setup the rule, on the IOT core navigate to the left side bar and go to Manage -> Message Routing -> Rules
Make sure that you are setting up the rule in the same region as your device.
Give the rule a name. Descriptions and tags are optional.
Keep the SQL statement version to 2016-03-23. For the SQL statement itself, write it out as follows:
1435.jpg
For context, the SQL statement is looking at the double_tap object in the JSON payload within the motion_sensor_data topic. It only activates the rule if double_tap is true.
For the rule action, click Simple Notification Service (SNS) from the dropdown menu.


6. Create the Messaging System


You need to create a new SNS topic. This takes you a new window.
In the new window, set the topic type to standard, give it a name, and create the topic.
1436.jpg
You are sent to the topic details. On the lower tabs, click subscriptions and click Create subscriptions.
The ARN will automatically be filled in for you. Select Email from the protocol dropdown and type in an email that you know.
Note: A limitation to this is that the rule does not have a delay between triggers, so it is possible to flood your email with notifications. Use a burner email or one you are not worried about flooding.
Open the email sent to the address and click on the link to confirm and activate the subscription.


7. Finish creating the rule


Navigate back to the rule and attach the SNS topic to the rule. Keep the message format to RAW and create a new IAM role for the rule.
Review the information and create the rule. It will automatically activate for you. You can deactivate the rule at any time from the website to stop sending messages.
 
Version history
Last update:
‎2022-11-02 05:29 AM
Updated by: