Get Started with an ESP RainMaker Classic Example Project

In this tutorial, you'll learn the basic workflow of an ESP RainMaker project using the public instance of RainMaker, which removes the need for custom cloud backend setup or deployment. The switch example from the official ESP RainMaker repository will serve as a reference throughout this guide.

The tutorial will cover the following workflow steps:

Setup

Configure Region

Build and Flash

Wi-Fi Provision and Control

To know more about the technical overview of ESP RainMaker, please refer to the documentation hub under section Technical Overview

If you're not familiar with firmware development, head over to the Tryout Centre in the Evaluation Hub to quickly try RainMaker using pre-built firmware and apps like the official ESP RainMaker app.

Note: ESP RainMaker works with all variants of ESP32 like ESP32, ESP32-S2, ESP32-C3 and ESP32-S3. We will just use the name ESP32 to mean all of these, unless explicitly specified otherwise.

Introduction

The ESP RainMaker GitHub project should be used for implementing a "Node" which can then be configured by logged in Users using the clients (like a phone app) and then controlled via the ESP RainMaker Cloud. In addition, the user can view the node operation data and create remote OTA jobs via the ESP RainMaker Dashboard. The examples in this guide are best suited for ESP32-S2-Saola-1, ESP32-C3-DevKitC and ESP32-S3-DevKitC, but the same can be used on other boards by re-configuring Button/LED GPIOs. Meanwhile, the example will use the ESP RainMaker APP to control device remotely.

Intro

Set up Host environment

Setup the Host environment and ESP IDF (master branch) as per the steps given here.

A Visual Studio Code Extension for ESP-IDF and ESP RainMaker is now available. You can check out the information here.

Setup Platform

Download ESP RainMaker using the following:

$ git clone --recursive https://github.com/espressif/esp-rainmaker.git

This repository has the agent code required for firmware development and the CLI required for testing.

Then, run the following commands:

$ cd /path/to/esp-rainmaker/examples/switch/
$ export ESPPORT=/dev/tty.SLAB_USBtoUART #Set your ESP32's serial port here
$ idf.py set-target esp32 # Set target platform to esp32, esp32s2, esp32c3 or esp32s3

Note the --recursive option. This is required to pull in the JSON dependencies into esp-rainmaker. In case you have already cloned the repository without this option, execute this to pull in the submodules: git submodule update --init --recursive

Region Selection (Global/China)

For details on the differences between the Global and China regions of ESP RainMaker, refer here.

To learn about the claiming services used in public ESP RainMaker, refer here.

Claiming type

Build and Flash firmware

It is recommended to first erase the flash using idf.py erase_flash if you are using this for the first time and then flash the firmware.

Here are the steps:

$ idf.py build
$ idf.py erase_flash
$ idf.py flash monitor

Tip (Advanced)

Besides using idf.py erase_flash, you can erase the factory partition with esptool.py -p $ESPPORT erase_region 0x340000 0x6000 to remove any old certificates. When erasing the factory partition, ensure the partition address is correct, as it may differ if the NVS (Non-Volatile Storage) partition image is not flashed to the default address (0x340000).

When you try this out for the first time, the monitor log will show a print like this:

I (755) esp_claim: Initialising Self Claiming. This may take time.

OR

I (895) esp_claim: Initialising Assisted Claiming. This may take time

This means that your board does not have the credentials to connect to the ESP RainMaker Cloud but will eventually get them from the Claiming service after it connects to the Wi-Fi.

When all the basic initialisations are done, the device will show a QR code on the terminal, which can be used for Wi-Fi provisioning.

QR code not rendering?

It is possible that the QR code may not render properly in your terminal. Something like this:

Broken QR

In that case, check the below lines on your terminal and copy paste the given URL in a browser.

I (1080) app_wifi: If QR code is not visible, copy paste the below URL in a browser.
https://rainmaker.espressif.com/qrcode.html?data={"ver":"v1","name":"PROV_000317","pop":"a1000317","transport":"softap"}

Note: You may have to pull the latest code from GitHub if you do not see this URL. Each board will have own unique QR code. So, use the URL from your serial terminal, not from the above snippet.

Wi-Fi Provisioning and Control

Wi-Fi Provisioning and Control can be done via:

Links to download the RainMaker Phone apps are found here

Follow these steps on the Phone apps

What to expect in this example?

esp32-s2-saola-1

I (16073) app_main: Received value = true for Switch - output

LED not working?

The ESP32-S2-Saola-1 board has the RGB LED connected to GPIO 18. However, a few earlier boards may have it on GPIO 17. Please use CONFIG_WS2812_LED_GPIO to set the appropriate GPIO.

$ idf.py menuconfig
    Component config -> WS2812 RGB LED -> WS2812 LED GPIO -> 17

Resetting the board

You will have to provision the board again to use it.

Set up RainMaker CLI (Optional)

The RainMaker CLI offers client functionality (similar to phone apps) integral to the RainMaker solution and can be used for testing and debugging. Please follow the steps here to set up the CLI.

Develop own firmware

Now that the basics are done, let's move onto understanding ESP RainMaker Code. To learn more about how to build a basic ESP RainMaker application by initializing Wi-Fi, setting up a node and device (e.g., a switch), adding standard parameters, and starting the RainMaker agent for cloud communication and control. In addition, you can also use the standardized ESP RainMaker solution to quickly create a product demo by referring to Custom & Standard Types. Currently ESP RainMaker supports lighting, electrical, energy monitoring, and MeshLite features.