Connecting to AWS IoT Core

In this chapter you’ll configure, build, and flash your device firmware—which will allow your device to connect to your Wi-Fi network and 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 IoT endpoint. Establishing a secure MQTT connection is simplified with the AWS IoT Device SDK for Embedded C and the pre-provisioned secure hardware certificates in the on-board Microchip ATECC608 Trust&GO. With the secure element, you do not need to retrieve certificates from AWS IoT Core, or generate your own, to connect. The connectivity libraries in the AWS IoT Device SDK for Embedded C simplify connectivity and access to AWS IoT services and features.

Configuring the ESP32 Firmware

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 We’ll use this in a moment.

Go to the configuration menu from the Blink-Hello-World directory of the repository and enter:

pio run --environment core2foraws --target menuconfig

Configuring Core2 for AWS IoT EduKit with menuconfig

Here you will set the configuration. Use the direction keys on your keyboard to go to Component config –> Amazon Web Services IoT Platform and open AWS IoT Endpoint Hostname to set the string. You can paste the address you copied moments ago into the box and hit enter to set that symbol. Next, go back to the configuration home screen by pressing the ESC key twice. Then select AWS IoT EduKit Configuration from the menu. Set your WiFi SSID and WiFi Password with your Wi-FI credentials. Once you are finished, press the s button on your keyboard to save, confirm the location of the file by pressing enter, followed by q to quit.

In case the UP and DOWN arrows do not work in menuconfig try using the J key to move the cursor down and K to move the cursor up. Another option is to use - and + keys on the numeric keypad.

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, uploading, and monitoring the Blinky Hello World firmware

You are now ready to build (compile) and upload the Blinky Hello World firmware. The process is the same as with the Getting Started tutorial for building, flashing, and monitoring the serial output:

  1. To build the firmware, paste in the command below (it will take several minutes):
    pio run --environment core2foraws
  2. With the build successful, it’s time to upload the compiled firmware to the connected device over USB by running the command:
    pio run --environment core2foraws --target upload
  3. Lastly, monitor the serial output from the device on your host machine via:
    pio run --environment core2foraws --target monitor

If during upload or while monitoring the serial output you receive an error about an incorrect port or timeout, open the platformio.ini file, and follow the instructions there to manually set the upload port.

Chapter conclusion

In this chapter, you have successfully compiled and flashed 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.

Community support Report bugs