1.1 AWS IoT Device Shadow Example Application

Description

This example application shows the usage of AWS device shadow feature of AWS IoT to set/get LED status from the device.

Pre-requisite

  • Have already created and configured an AWS account
  • Have an AWS IoT Thing created with the AWS IoT

User may refer to the official AWS IoT Developer Guide for more details.

Development Tools and Software Dependencies

To see the list of development tools and software dependencies required for this application, please refer to aws_iot/release_notes.md

Hardware Setup - SAM E54 Xplained Pro

The target board for running the application is SAM E54 Xplained Pro.

This section provides essential hardware configuration of this target board to run shadow application.

Figure 1-1. SAM E54 Xplained Pro

Board Setup

  • (5) Turn ON the switch 1 the ATECC608 TRUST to enable the TNGTLS device.
  • (6) Connect a USB micro cable to the Debug port.
  • (7) Connect the Ethernet cable.

Enable Device Shadow Library

From MCC, please enable the device shadow library and regenerate the code.

Note: The demo application already has this setting.

Running the Demo Application

Note: The Shadow demo is based on this implementation, while the MQTT demo helpers are taken from this reference. Users are free to adapt or replace them with their own custom demo files and apply modifications as necessary.

  1. Open apps\led_shadow_client_ecc\firmware\sam_e54_xpro.X project in MPLAB X IDE
  2. Open apps\led_shadow_client_ecc\firmware\src\demo_config.h and set the following as per user's configurations:

    ParameterDescription
    democonfigTHING_NAMEUse the Thing name here, which you would have created at AWS server side (the pre-requisite step as mentioned above)
    democonfigCLIENT_IDENTIFIERShould be same as democonfigTHING_NAME
    democonfigMQTT_BROKER_ENDPOINTUse your AWS IoT server's endpoint which can be found in the AWS IoT server's console page
  3. The GMAC peripheral on the SAME54 Xplained Pro does not have a built-in (pre-programmed) MAC address. Therefore, this demo uses a hard-coded sample MAC address.

    Users must update the MAC Address for their hardware setup from here: src\third_party\FreeRTOS-Libraries\FreeRTOS-Plus-TCP\source\portable\NetworkInterface\include\NetworkConfig.h

  4. Compile and program the project on the SAM E54 XPRO board
  5. On coming up for the first time, user have to read the device certificate from ATECC608-TNGTLS device (this certificate is unique for every device), using the cli command "getcert 2" .

    User needs this device certificate for registering the device with AWS Cloud server.

  6. Once the user has registered the device certifcate and attached it to 'Thing', you need to reset the board.On coming up, the demo application shall connect to the configured AWS Cloud server.

  7. The demo application subscribes to shadow related delete and update topics.Please note that the demo application assumes that the shadow classic is already existing for the device at the AWS IoT Server. If user want to learn more about shadow, then user may refer to the official AWS IoT Developer Guide.

  8. Edit the device shadow document and set the 'powerOn' to "1" and click 'update'.

  9. The demo shall receive a message on the subscribed topic, as shown below. For every state change, the demo shall perform an action(LED set or LED clear) according to the values of 'powerOn' received in the message.

    User will see the LED Set / LED Clear messages on the console, along with the LED switching ON (Set) or OFF (Clear) on the IO1 Xplained Pro board.

References

  1. Device Shadow demo reference.
  2. MQTT demo helpers reference.