In this chapter you’ll configure, build, and flash your device firmware—which will connect to AWS IoT Core. In order to connect and communicate to AWS IoT Core, you need to configure your device with Wi-Fi credentials and the URL of your AWS endpoint. Connectivity is simplified with the pre-provisioned certificates in the Microchip ATECC608 Trust&GO, which is assigned to our AWS IoT thing and attached to a security policy from the previous chapter. You do not need to retrieve certificates from AWS IoT Core or generate your own. To configure, build, and flash our firmware on to the Espressif ESP32-D0WD you will use the ESP-IDF.
Configuration of your source code is handled through Kconfig. Kconfig is the same configuration system used by the Linux kernel and helps simplify available configuration options (symbols) into a tree structure. Before you set the configuration, you will first need to retrieve your AWS IoT endpoint.
aws iot describe-endpoint --endpoint-type iot:Data-ATS
Copy your AWS IoT endpoint without the quotes. It will look something like 3duk1t3xampl3.iot.us-west-2.amazonaws.com
. We’ll use this in a moment.
You can enter the configuration menu from the Blink-Hello-World directory of the repository:
idf.py menuconfig
Be sure your SSID is for a 2.4GHz network. The ESP32-D0WD on the M5Stack Core2 for AWS hardware does not support 5GHz Wi-Fi bands.
Building the firmware is easy, but can take quite a while the first time. ESP-IDF uses CMAKE as it’s build system and will link all the files necessary and begin compiling the code to a flashable binary in ELF format that can be flashed on to the device.
idf.py build
If you completed the Getting Started or Alexa demo, it is recommended to erase the flash memory of your device. The flash is split into separate partitions where the application data, OTA data, and keys are stored. The other walk-throughs use a different partition table than used for this tutorial and could cause issues if not wiped. Replace «DEVICE_PORT» with the serial port your Core2 for AWS IoT EduKit device is connected to:
idf.py erase_flash -p <<DEVICE_PORT>>
To flash the firmware you just built and view all the outputs by the device over the serial connection, you’re going to daisy chain commands and enter:
idf.py flash monitor -p <<DEVICE_PORT>>
Once the device is flashed, it will reboot and run the application. You should see the device connect to your Wi-Fi network, establish a secure MQTT connection to AWS IoT Core, subscribe to the preset MQTT topic, and begin sending messages.
In this chapter, you have successfully compiled and flash your device and are actively monitoring it’s serial outputs. Using the AWS IoT Device SDK for Embedded C, the reference hardware authenticated with the MQTT message broker (AWS IoT Core) and is ready to receive messages.
You are now ready to head to the final chapter in this tutorial, Blinking the LED.