aws-iot-dragonconnect-c

Arrow DragonConnect

Introduction

The DragonConnect example includes the ability to manage an LED. You will need the following components to complete the circuit

Circuit

NOTE: Please ensure that your DragonBoard™ is powered off and the power supply has been disconnected from the DragonBoard™. This is a good practice that will help reduce the chances of an accidental short circuit that could damage your single board computer.

The steps below to complete the circuit assume the use of the SparkFun TXB0104 Level Shifter. Depending upon the voltage translator you choose the steps may be different

  • Connect one end of the wire from the GPIO 12 (positive) position to the VCCA terminal of the level shifter
  • Connect the VCCB terminal of the level shifter to the red row of the breadboard
  • Connect pin 37 of the GPIO to the red row of the breadboard
  • Connect the red row of the breadboard to one end of the resistor (m)
  • Connect the other end of the resistor to to a different row (n)
  • Connect the anode of the LED in the same row (n)
  • Connect the cathode of the LED to a different row (o)
  • Connect the row with the LED cathode (o) to the ground of the level shifter
  • Connect the other ground of the level shifter to pin 40 of the GPIO

Your circuit should look similar to the following

DragonBoard Manage LED Breadboard

Design

The LED is managed using the API Gateway, Lambda, and IoT services and is composed of retrieving the status of the device shadow and requesting an update of its state.

State Retrieval

Let's begin by understanding how the status of the LED is retrieved. The following diagram provides an overview of the status retrieval

DragonBoard Status

The browser issues a GET on the resource /things/{thingId}/led. The API Gateway is configured to invoke the DragonConnect-led Lambda function. The DragonConnect-led Lambda performs the following steps

  1. Validates that a thing is in IoT Thing Registry and is assigned a principal (certificate)
  2. Retrieves the reported state from the IoT Device Shadow. The IoT device shadow provides the reported state in a document similar to

    {
        "state": {
            "desired": {
                "active": true
            },
            "reported": {
                "active": true
            }
        },
        "metadata": {
            "desired": {
                "active": {
                    "timestamp": 1451516587
                }
            },
            "reported": {
                "active": {
                    "timestamp": 1451516635
                }
            }
        },
        "version": 50,
        "timestamp": 1451592857
    }
    
  3. The DragonConnect-led Lambda function transforms the response into the simple document of

    {
      "active": true
    }
    

State Update

A request to update the state of the LED is made through a web browser when a user selects the desired state. Logic in the web client controls the possible selection. If a device has not reported state, ...

When a user selects a state, the following actions occur

DragonBoard LED Update

  1. The web browser performs a POST to the resource /things/{thingId}/led through the API Gateway.
  2. The API Gateway is configured to invoke the DragonConnect-led Lambda function with the desired state.
  3. The Lambda function requests an update to the thing state using the Device Shadow. Assuming that a user has requested to turn off the LED the desired state is false

    {
      "state": {
        "desired": {
          "active": false
        }
      }
    }
    
  4. Meanwhile, when the DragonConnect client starts it subscribes to the topic $aws/things/{thingId}/shadow/update/delta. When the desired state is set through the previous step, the IoT service publishes a method to the aforementioned topic. The client receives the message.

  5. Once the message has been received, the DragonConnect client activates or deactivates the configured General Purpose IO (GPIO) pin.

  6. Finally, the DragonConnect client publishes a method to the Device Shadow topic of $aws/things/{thingId}/shadow/update as shown in the diagram below

DragonBoard Update


Home