INTRO
This project will walk the user through the process to connect a Tria RZBoard to AWS IoT Core. Amazon provides a working c++ example application called aws-iot-device-client that we'll leverage for the exercise. We'll create an AWS IoT Core Thing, and then configure the aws-iot-device-client application to connect to the new Thing.
The aws-iot-device-client application is an open-source project that demonstrates AWS best practices for developing device client applications. We'll use the aws-iot-device-client application to send and receive MQTT data to/from AWS.
PREREQUISITES
- RZBoard V2L
- Ethernet Cable
- USB to TTL Cable
- AWS account
- Terminal application such as TeraTerm
The setup consists of...
- Creating a new AWS IoT Core Thing
- Downloading the Certificates and Keys associated with the new thing
- Flashing a new image onto the RZBoard
- Copying the certificates and keys onto the RZBoard
- Updating the configuration file to identify details of your AWS IoT Thing
CREATING A NEW THING
- Login to your AWS account
- Select IoT Core
- Select Manage --> All devices --> Things
- Select the "Create things" link
- Select "Create a single thing" then Next
Name your thing and click Next
- Name your thing and click Next
- Select the "Auto generate a new certificate" Option then click Next
- Create a policy for the new thing
- Note the policy below does NOT follow AWS best practices
- Create a policy similar to the one shown below
- Click the Create link
- Navigate back to the Create single thing web page browser tab; my new policy form opened in a separate tab in my browser.
- Select the new policy just created
- Select the "Create thing link"
- The Download certificates and keys dialog opens
- Download all the items identified below
- Click on the Done link
I like to rename the device certificate and the keys to match my thing's name
FLASH THE AWS IMAGE ONTO THE RZBoard
- Install the Tria RZBoard flash utility by following the detailed instructions here
- Configure your RZBoard as shown before flashing the images
- Connect an Ethernet cable to the local network
- Connect a USB to TTL cable from RZBoard to PC
- Set the Dip Switches as shown
- Add a 5V jumper as shown (red line)
- Download the file package from here (this is a large download ~1.3GB)
- Unzip the contents into an empty directory
- Open a Windows PowerShell instance and change directory to directory where you installed the flash utility (note you must run the flash utility from the same folder where the flash utility was installed)
- Determine the COM port number for your USB to TTL serial device
Update Process
The update process requires human intervention after the bootloader is flashed
- Execute the command to flash the board (make sure you run it from the rzboard_flash_util folder or wherever you installed the utility)
- My command looks like: C:\tools\RzBoard\rzboard_flash_util> python3.\flash_rzboard.py --full --serial_port com5 --serial_port_baud 115200 --image_path..\aws_blog\rzboard_aws-package-Oct2024\
- Power on the RZboard by pressing the user button (long press) closest to the corner of the board. You'll see a white LED.
- The boot images are flashed to the device (note this is a slow process, be patient)
- Once you see the "Waiting for device..." prompt, remove the 5V jumper wire and power cycle the device, then press the user button again (long press)
- The board is flashed with the new images
- Open a terminal application such as TeraTerm. Open the USB to TTL serial port with settings 115200, 8, N, 1.
- Power Cycle the RZBoard
- Turn on the RZBoard with a long press on the user button
- The device boots to a Linux login prompt. Enter the login user as "root" and a password of "avnet"
CHECKPOINT
At this point in the exercise, we have...
- Created a new AWS IoT Core Thing
- Flashed our RZBoard with an image that contains the aws-iot-device-client application
Next we'll move the HacksterThing certificates and keys to the RZBoard and update the aws-iot-device-client configuration
MOVE CERTIFICATES TO THE RZBOARD
- From your terminal application determine the IP Address with: > ifconfig to determine the board's IP address
- On the RZBoard create a new directory called aws and another called aws/certs
- Using a tool such as WinSCP, copy the certificates and keys to the ~/aws/certs directory
- Copy the myConfig.json and publish.sh files from the download package to the ~/aws directory
- From the terminal change the file permissions
- > chmod 600 certs/*-private.pem.key
UPDATE THE CONFIGURATION FILE
- Open the myConfig.json file to edit: > nano myConfig.json
- If using winSCP you can also edit remote files from the WinSCP interface
- Edit the file to include...
cert, key, root-ca: entries should be updated to reference your path and certificate file names
thing-name: Update to match the thing name we created earlier in the AWS console
publish-file: Update to match the path and filename of a Json document containing JSON to publish on the "publish-topic"
endpoint: Can be found in the AWS IoT Console under Connect --> Domain Configurations
- Update the permissions on the new publish file
- > chmod 600 publish.json
- Update the permissions on the aws/certs directory
- chmod 700 aws/certs
CHECK POINT
- We copied the AWS certificates and keys to our RZBoard
- We updated the myConfig.json file to reflect the certificate/key filenames
- We update the myConfig.json file with our Thing name
- We updated the myConfig.json file with our aws endpoint FQDN
We're ready to connect the RZBoard to AWS!
Exercise the aws-iot-device-client- Run the application using our new configuration...
- > aws-iot-device-client --config-file myConfig.json
At this point you may see some errors. Most likely there are file permission errors. Examine the output to see which files need to be updated. The debug will output what the expected permissions should be set to. A successful startup looks similar to the graphic below.
- Go back to the AWS console
- Select Test --> MQTT test client
- Subscribe to the topic "myTopic"
- Kill the aws-iot-device-client (Ctrl+c) and restart it. When the application connects to AWS it sends a MQTT message with the content from your publish.json file
- Observe the incoming MQTT message from the RZBoard
- Now in the MQTT test client publish to a topic
- For topic name enter "myTopic"
- For the message payload enter "DC-Publish"
- Hit the Publish button
Note in the debug windows you see that a message was received, and another message was sent. The aws-iot-device-client will resend the MQTT publish data when it receives the "DC-Publish" text
CONCLUSION
In this project the user learned how to...
- Create a new AWS IoT Thing
- Flash the RZBoard with a new image
- Configure the aws-iot-device-client to connect to AWS to receive and send MQTT data
The aws-iot-device-client application supports other features that we're not exercising. Feel free to review the on-line documentation and exercise other features on the RZBoard.
Please post any questions or comments below and thank you for your time!
Brian
Comments
Please log in or sign up to comment.