Through the previous lessons, you configured your device software. It’s now running, and you are connected to AWS IoT Core. Your device is sending messages to the cloud, and is ready to receive and act on messages from the cloud. In this lesson, you will subscribe to an MQTT topic , view the messages that AWS IoT Core receives, and send an MQTT request to blink your device’s LEDs.
MQTT is a publish-subscribe protocol . This means that you can subscribe and publish to specific topics. The policy that the registration script created defines these topics. Your device can only send or receive messages to AWS IoT Core through the topics that satisfy the AWS IoT policy’s parameters and match the client ID. In our case, the client ID is the same as the device’s secure element’s unique serial number. Understanding this process is critical, so that you can filter messages and secure communication.
The AWS IoT MQTT client in the AWS IoT Core console allows you to both view and publish MQTT messages.
Complete the following steps to subscribe to an MQTT message topic:
The messages that your device sends to the cloud will begin to appear. (Note: It can take a minute or two before they appear.)
Because of the policy constraints, the device can only publish messages to the topic beginning with its client ID. This provides flexibility, so that another subscriber (such as a cloud application) can filter topics for specific devices. Filters can also be applied to display more specific topics, such as a specific device’s temperature readings.
To start or stop blinking the LED bars on the side of the Core2 for AWS, publish a message to the device from the AWS IoT MQTT client in a topic that the device subscribes. The subscription topic for the device will have the pattern <<CLIENT_ID>>/#
. You can view the subscription topic on the device after it successfully subscribes to the topic. Additionally, you can view the client ID that’s been output on the host machine’s serial monitor.
Complete the following steps to begin blinking the LED bars on the device:
<<CLIENT_ID>>/blink
Your device’s LED bars should now blink. To pause the lights, press the Publish button again to publish another message to the same topic.
To avoid unwanted possible AWS Cloud service charges and optimize your resources, erase the flash memory on your device. This will also prepare it for subsequent tutorials.
Complete the following steps to erase the flash memory on your device:
pio run --environment core2foraws --target erase
When the command in the terminal window completes, the Core2 for AWS may not automatically restart or appear to be different. Power the device off and then on to confirm that the firmware was flashed.
Congratulations! You successfully communicated to your Core2 for AWS and blinked its LEDs. Now you are ready to complete the final lesson of this tutorial, Conclusion .
AWS IoT Kit now features direct access to
M5Stack Forum
, which is a community-driven, questions-and-answers service. Search re:Post using the
Core2 for AWS
tag to see if your question has been asked and answered. If not, ask a new question using the Core2 for AWS
tag.