Skip to main content

Getting Started

MQTT Setup

Step 1:

  • Login from your golain account and go to "Fleets and Devices".

  • From a fleet of your choice, create a device as per your requirements.

  • You will receive a zip file with all the certificates you need and JSON file named connection_settings.json contain multiple configuration parameters. We will use the certificates in the next step, and the config parameters in the step 3.

note

Remember to use the same shadow definitions as your configurations.

Step 2:

  • Copy your certificates and move them in /main/certs. Your folder structure should look like this:

    main
    |
    -certs
    |
    -device_cert.pem
    -device_private_key.pem
    -mqtt_broker_cert.pem
    -root_ca_cert.pem
  • Add the following to your root CMakeLists.txt:

    target_add_binary_data(${PROJECT_NAME}.elf "main/certs/device_cert.pem" TEXT)
    target_add_binary_data(${PROJECT_NAME}.elf "main/certs/device_private_key.pem" TEXT)
    target_add_binary_data(${PROJECT_NAME}.elf "main/certs/mqtt_broker_cert.pem" TEXT)
    target_add_binary_data(${PROJECT_NAME}.elf "main/certs/root_ca_cert.pem" TEXT)
  • Ensure that your certificates are named accordingly.

  • These certificates allow the device to establish a TLS connection. We use a TLS connection for security.

Step 3:

  • Open ESP-IDF menuconfig by :
    • Press Ctrl + Shift + P and then search for "menuconfig")

    • Open command line and run

      idf.py menuconfig
    • You can find more information in ESP-IDF's official documentation

      menuconfig

  • Scroll down to Golain

  • Using the parameters we found in connection_settings.json, update the following in this KConfig:

    • Topic Root → root_topic

    • Device Name → device_name

      root-dev-name

Step 4:

  • Click on the "Enable Wifi" option to allow golain to handle wifi.

  • Enter your ssid and password in "Enter ssid" and "Enter wifi password" fields respectively.

    root-dev-name

note

This step is optional and is only required if you don't use golain to setup wifi. However, it is recommended that you do allow golain to setup and handle wifi.