tree: f925cd8b2705564148224423914794e3d318133f [path history] [tgz]
  1. main/
  2. third_party/
  3. .gitignore
  4. CMakeLists.txt
  5. partitions.csv
  6. README.md
  7. sdkconfig.defaults
  8. sdkconfig.optimize.defaults
  9. sdkconfig_rpc.defaults
examples/temperature-measurement-app/esp32/README.md

CHIP ESP32 Temperature Sensor Example

This example is meant to represent a minimal-sized application.



Building the Example Application

Building the example application requires the use of the Espressif ESP32 IoT Development Framework and the xtensa-esp32-elf toolchain.

The VSCode devcontainer has these components pre-installed, so you can skip this step. To install these components manually, follow these steps:

  • Clone the Espressif ESP-IDF and checkout v4.4 release

      $ mkdir ${HOME}/tools
      $ cd ${HOME}/tools
      $ git clone https://github.com/espressif/esp-idf.git
      $ cd esp-idf
      $ git checkout v4.4
      $ git submodule update --init
      $ ./install.sh
    
  • Install ninja-build

      $ sudo apt-get install ninja-build
    

Currently building in VSCode and deploying from native is not supported, so make sure the IDF_PATH has been exported(See the manual setup steps above).

  • Setting up the environment

    $ cd ${HOME}/tools/esp-idf
    $ ./install.sh
    $ . ./export.sh
    $ cd {path-to-connectedhomeip}
    

    To download and install packages.

    $ source ./scripts/bootstrap.sh
    $ source ./scripts/activate.sh
    

    If packages are already installed then simply activate them.

    $ source ./scripts/activate.sh
    
  • Target Select

    $ idf.py set-target esp32(or esp32c3)
    
  • Configuration Options

    This application uses ESP32-DevKitC as a default device type. To use other ESP32 based device types, please refer examples/all-clusters-app/esp32

  • To build the demo application.

      $ idf.py build
    
  • After building the application, to flash it outside of VSCode, connect your device via USB. Then run the following command to flash the demo application onto the device and then monitor its output. If necessary, replace /dev/tty.SLAB_USBtoUART(MacOS) with the correct USB device name for your system(like /dev/ttyUSB0 on Linux). Note that sometimes you might have to press and hold the boot button on the device while it's trying to connect before flashing. For ESP32-DevKitC devices this is labeled in the functional description diagram.

      $ idf.py -p /dev/tty.SLAB_USBtoUART flash monitor
    

    Note: Some users might have to install the VCP driver before the device shows up on /dev/tty.

  • Quit the monitor by hitting Ctrl+].

    Note: You can see a menu of various monitor commands by hitting Ctrl+t Ctrl+h while the monitor is running.

  • If desired, the monitor can be run again like so:

      $ idf.py -p /dev/tty.SLAB_USBtoUART monitor
    

Commissioning and cluster control

Commissioning can be carried out using WiFi or BLE.

  1. Set the Rendezvous Mode for commissioning using menuconfig; the default Rendezvous mode is BLE.

     $ idf.py menuconfig
    

Select the Rendezvous Mode via Demo -> Rendezvous Mode.

  1. Now flash the device with the same command as before. (Use the right /dev device)

      $ idf.py -p /dev/tty.SLAB_USBtoUART flash monitor
    
  2. The device should boot up. When device connects to your network, you will see a log like this on the device console.

      I (5524) chip[DL]: SYSTEM_EVENT_STA_GOT_IP
      I (5524) chip[DL]: IPv4 address changed on WiFi station interface: <IP_ADDRESS>...
    
  3. Use python based device controller or standalone chip-tool or iOS chip-tool app or Android chip-tool app to communicate with the device.

Note: The ESP32 does not support 5GHz networks. Also, the Device will persist your network configuration. To erase it, simply run.

$ idf.py -p /dev/tty.SLAB_USBtoUART erase_flash
  • Once ESP32 is up and running, we need to set up a device controller to perform commissioning and cluster control.

Setting up chip-tool

See the build guide for general background on build prerequisites.

Building the example:

$ cd examples/chip-tool

$ rm -rf out

$ gn gen out/debug

$ ninja -C out/debug

which puts the binary at out/debug/chip-tool

Commission a device using chip-tool

To initiate a client commissioning request to a device, run the built executable and choose the pairing mode.

Commissioning over BLE

Run the built executable and pass it the discriminator and pairing code of the remote device, as well as the network credentials to use.

The command below uses the default values hard-coded into the debug versions of the ESP32 all-clusters-app to commission it onto a Wi-Fi network:

$ ./out/debug/chip-tool pairing ble-wifi 12344321 ${SSID} ${PASSWORD} 20202021 3840

Parameters:

  1. Discriminator: 3840 (configurable through menuconfig)
  2. Setup-pin-code: 20202021 (configurable through menuconfig)
  3. Node-id: 12344321 (you can assign any node id)

Cluster control

temperaturemeasurement

Usage:
  ./out/debug/chip-tool temperaturemeasurement read measured-value 12344321 1

Flashing app using script

  • Follow these steps to use ${app_name}.flash.py.

    • First set IDF target, run set-target with one of the commands.

      $ idf.py set-target esp32
      $ idf.py set-target esp32c3
      
    • Execute below sequence of commands

        $ export ESPPORT=/dev/tty.SLAB_USBtoUART
        $ idf.py build
        $ idf.py flashing_script
        $ python ${app_name}.flash.py

Optimization

Optimization related to WiFi, BLuetooth, Asserts etc are the part of this example by default. To enable this option set is_debug=false from command-line.

# Reconfigure the project for additional optimizations
rm -rf sdkconfig build/
idf.py -Dis_debug=false reconfigure

# Set additional configurations if required
idf.py menuconfig

# Build, flash, and monitor the device
idf.py -p /dev/tty.SLAB_USBtoUART build flash monitor