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.

Now, you’ll go into the KConfig menu to configure the required symbols for the device to connect to your 2.4GHz Wi-Fi network. Start by switching to the Blink-Hello-World directory of the repository in the PIO terminal window and enter:

pio run --environment core2foraws --target menuconfig
Configuring Core2 for AWS IoT EduKit with p.py menuconfig

Use the direction keys (or K and J, or - and +) on your keyboard to go to 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.

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