This document includes all the details required to connect your device to AWS and send/receive MQTT data. The document captures all the details to . . .
- Sign up for a free AWS account
- Create a new IoT Core device in AWS
- Configure the Avnet Out-of-Box (OOB) application to connect to AWS
- Run the demo and verify that inference data is sent to AWS as telemetry
- You have an Avnet RASynBoard EVK
- You have a microSD card for the EVK
- You have a USB-C cable to connect the EVK to your development PC
- You have completed the RASynBoard Getting Started Guide
- You have exercised the 5-keyword ML model "up", "down", "back", "next", "ok-syntiant"
- You have a USB to TTL debug cable to view debug from the OOB application
You'll need an AWS account to complete these instructions. If you already have an account sign into the AWS console. If not, AWS provides a free tier that will provide all the services we need to connect our device to AWS and send/receive data.
Note the free account does require that you enter a credit card number
- Navigate to the AWS account sign up page
- Follow the sign up process. If you have any questions, you can refer to this AWS document on the process
- Once you've completed the sign up process login to the AWS Console
- Select the IoT Core link
- On the left side menu, select Manage --> Add devices --> Things
- Click on the Create things button
- Select Create single thing
- Select the Next button
- Give you thing a name
- Select the Next button
- Select Auto-generate a new certificate (recommended)
- Select the Next button
- Click on the Create policy button
- Give your policy a name
- Add the 4 policies shown below, use the Add new statement button to add the additional policy lines
- Note that we're providing a wildcard * for the Policy resource. This is NOT a best practice!
- Click the Create button
- Your new policy is created
- Verify that the check box next to the policy is selected!
- Click the Create thing button to finish the process
- Once your device has been created the interface will open the Download certificates and keys dialog
Note This is the only time you can download the key files for the device!
- Using the Download buttons download the
- Device certificate
- Public key file
- Private key file
- Once you have downloaded the certificates, click the Done button
Notice that the certificate names are not very meaningful. As a best practice I like to rename my certs after the thingName
- Open your downloads folder and replace the long number with the thingName to each of the certs we just downloaded
So far we have . . .
- Signed up for an free AWS account, or logged into our existing account
- Created a new IoT Core Thing
- Created a security policy allowing our thing to connect to AWS
- Downloaded the Thing certificate and keys
At this point it's important that all the prerequisites detailed at the top of this document have been completed. Please review them and make sure you're ready to proceed.
There are two AWS details we need to configure the OOB application to connect to AWS IoT Core. We'll add them to the config.ini file on the RASynBoard microSD card. I recommend opening up a text document to capture these items.
- The Unique ID can be found on the Manage --> All devices --> Things page
- In my case it's "BW-RASyn"
The endpoint url is used by the RASynBoard firmware to establish the MQTT over TLS connection.
- From the AWS IoT page, select the Settings link at the left towards the bottom of the list
- Note the Endpoint FQDN
We're getting close now! The next step is to configure the OOB application by adding the device certificates and updating the config.ini file that's located on the microSD card. Since you already completed the RASynBoard Getting Started Guide you updated your microSD card with all the files from the /ndp120/synpkg_files/* folder.
- Copy the device certificate and the private key certificate files to the microSD card into the /certs directory
- The certs directory should already contain the AmazonRootCA1.pem file, if not copy it from the repo /ndp120/synkpg_files/certs folder
- Open the config.ini file by either removing the microSD card from the RASynBoard and using a microSD card reader, or by running the OOB application and connecting your USB-C cable to the USB-C connector on the core board.
If you use the RASynBoard OOB application . . .
- Make sure the OOB application is loaded onto the device (if you completed the RASynBoard Getting Started Guide this is done)
- Make sure that the Jumper is installed on J3 across pins 1-2 (this will auto boot the application)
- Connect your development PC to the USB-C connector on the core board (NOT the I/O board)
Once the application boots, the microSD card will enumerate on your development PC as an external USB drive
- Update the following items in your config.ini
Now that everything is configured, we can run the demo! Cycle power on the device by disconnecting/reconnecting the USB-C connector from your development PC.
- Note: When the application starts up it outputs the configuration so you can confirm that your settings are being used . . .
- Note: The debug will show the different states that the IoTConnect thread processes while connecting to AWS. If your device does not connect watch the debug for ERROR debug messages.
The OOB application implements a queue for telemetry data. This way if telemetry data is generated before the application is connected to AWS, the message is not lost. As soon as the MQTT connection is established the IoTConnect thread looks for messages in the queue and if present they get sent to AWS! Additionally, the application verifies that there is a valid MQTT connection before sending any telemetry. If not, the state machine is rolled back to re-establish the MQTT connection.
The application sends inference data up as telemetry each time there is an inference event.
-
Speak one of the keywords "up"
- The NDP120 detects the keyword and interrupts the OOB application running on the RA6
- The OOB application constructs JSON with the inference data and sends an MQTT message on the "MyTopic" publish topic
- AWS receives the MQTT message and since the device is subscribed to the "MyTopic" topic, AWS sends it back to the device
- The device receives the message and outputs it to debug.
- Now go back to the AWS console
- Select Test --> Device Advisor --> MQTT test client
- Select the Subscribe to a topic tab
- Enter "MyTopic in the Topic filter input box
- Click the Subscribe button
- Speak one of the keywords again "OK-Syntiant"
- Note that the MQTT Test Client receives the inference JSON that the application sent
- Click on the Publish button to send the hello message
- Note that the hello message is received by the device
The ability to send and receive data to AWS opens lots of different use cases. In the coming weeks, I'll add logic to the OOB application to parse incoming messages to do things like control an LED, or update a configuration value on-the-fly.
I hope you were successful in sending/receiving data to AWS. If you encounter any issues or have questions feel free to open an issue in the repo