AWS IoT for ESP32 v1.0.0
An ESP-IDF based solution
|
The solution is built on top of the ESP-IDF framework. The AWS IoT solution is provided as a library as a set of non-blocking APIs to the application layer.
The below image represents the layered design.
The lib_system module initializes the system and puts the system in one of the following mode based on device configuration.
The system library callbacks application handler to notify the application about system events such as connection & disconnection events. It also ensures that all pending flash operations are performed before executing system reset.
Following libraries gets initialized when SYSTEM_init()
function is called.
lib_events
lib_flash
lib_wifi
lib_aws
lib_ble
lib_ota
The below image represents the system state machine.
The lib_aws module connects the device to AWS IoT. It provides simple MQTT APIs to send and receive messages using simple publish and subscribe APIs and callbacks. The communication between the device and AWS is secure by TLS v1.2, and authentication with AWS IoT requires X.509 thing certificates. Without unique thing certificate the device cannot authenticate and connect with AWS IoT.
When the device is provisioned with thing certificates it can authenticate and connect with AWS. If the device is not provisioned then the library can provision it.
AWS provides several ways to provision a device and install unique client certificates on it. This library implements Device Provisioning by Claim process. The provisioning process requires a claim certificate that allows the device to connect with AWS to only generate and install a new thing certificate for the device. This provisioning check and provisioning process happens during the AWS_init call.
The library provides APIs for registering application callbacks to handle AWS IoT Shadow updates and AWS IoT Jobs. When a new message is received on a subscribed topic the message gets pushed into a ring buffer. The application must read the ring buffer to process the received message.
There are three ways by which the device can use thing certificates using this library.
Using claim certificates.
The device by itself will acquire thing certificates from AWS & register as a thing on AWS IoT device registry (provision by claim) for the first time. Then it re-uses those thing certificates for subsequent connections. If you choose this method then you should configure claim certificates in the s_sysConfig
variable.
sample configuration:
Using thing certificates.
This means that you already have thing certificates for your device and you just want to use them instead of running provision by claim process on device. If you choose this method then you should configure thing certificates in the s_sysConfig
variable instead of claim certificates.
sample configuration:
Using thing certificates, received as device configuration from the BLE application.
The flowchart below serves as a reference from the application developer’s perspective.
To update the device firmware an AWS IoT Job for firmware update (Job) must be created. This job consists of a job document which contains an https download link to the firmware file.
The firmware update job must be created from the AWS IoT dashboard and must specify the target device or device group. Once the job is created, the device gets notified and requests for the job document. It then parses the job document to retrieve the download link and puts the system in the OTA mode and firmware update process starts running.
The below image represents the state machine transitions during the OTA process within the ota library.
For storing data from application we have assigned 256 bytes of non-volatile storage of the flash memory. This flash library is initialized during SYSTEM_init()
call.
The system library handles flash operations in an asynchronous way. On calling system reset API, the system library ensures that all pending flash operations are performed before executing system reset. To restart a device always use the SYSTEM_restart
API.
The table below lists services and its characterisitcs offered by BLE library.
Services | Characteristics | UUID | Permissions |
---|---|---|---|
Service 1 UUID: 5704246a-5d4c-4f19-9b53-157d8824063d | |||
Char 1 | 15ba8b82-df9a-46dc-865a-177a17ad9035 | Read, Write, Notify | |
Char 2 | 20a62cd0-93ba-41e2-96b0-31b1aa131909 | Read, Write, Notify | |
Char 3 | 3a21768b-174a-41bc-8b25-b9c1ebfb7510 | Read, Write, Notify | |
Char 4 | 43c5e37d-b664-4b4a-aa33-032bbaf7133f | Read, Write, Notify |