Using Matter to set up Wi-Fi for ESP32 (COPY)

Becoming familiar with Matter Wi-Fi Config support

  1. Build the ayla_matter_demo application and flash it to your ESP32 following the steps on the Ayla ESP32 Solution page.
  2. Tap the reset button on the ESP32 board.
  3. If you’ve previously provisioned the ESP32 to a Wi-Fi network, type reset factory at the ESP32 CLI to clear the Wi-Fi configuration.
  4. Run CLI command matter qrshow to get the QR Code.
->matter qrshow
vendor:         4190 (0x105e)
product:        18905 (0x49d9)
discovery mask: 0x02
discriminator:  3549
passcode:       53725857
pairing code:   31910532797
QR payload:     MT:G8IB6SDF15FEAQ45510
QR code URL:    https://project-chip.github.io/connectedhomeip/qrcode.html?data=MT%3AG8IB6SDF15FEAQ45510
->

Proceed with the steps for iPhone or Android, depending on which device you are using.

Provisioning using Aura on iPhone

  1. Launch the Aura app on an iPhone.
  2. If you had previously provisioned and registered the ESP32 device, unregister it:
    a. Swipe left on the device’s entry.
    b. Tap Unregister.
    c. When prompted, confirm by tapping Unregister.
    d. Tap OK.
  3. Tap the + icon on the upper right.
  4. Tap Ayla Matter Setup.
  5. Scan Device QR Code(Open the QR code URL(matter qrshow) to get the QR code).
  6. Enter the Wi-Fi network Password.
  7. Tap Continue .
  8. Tap Continue.
  9. Wait the device to finish Matter setup.
  10. Tap Continue .
  11. Set the device name as you want after Matter setup finish.
  12. Tap Done icon on the upper right.
  13. Observe the device you just added is displayed in the Devices list.

Provisioning using Aura on Android

  1. Launch the Aura app on an Android.
  2. If you had previously provisioned and registered the ESP32 device, unregister it:
    a. Tap on the device’s entry in the Device List.
    b. Tap the vertical ellipsis icon at the upper right.
    c. Tap Unregister Device.
    d. Tap OK to confirm.
  3. Tap the + icon.
  4. Tap the list expander icon at the right of the Advanced header.
  5. Tap Ayla Matter Setup.
  6. Scan Device QR Code(Open the QR code URL to get the QR code).
  7. Enter the Wi-Fi network Password.
  8. Tap Continue.
  9. Tap Continue.
  10. Wait the device to finish Matter setup.
  11. Set the device name as you want after Matter setup finish.
  12. Tap Return to Device List.
  13. Observe the device you just added is displayed in the Device List.

Understanding how to integrate Matter support

  1. Locate and open examples/ayla_matter_demo/demo_matter.c, which provides an example of integrating Matter support with an application.
  2. Review demo_init. This function performs the initialization to start Matter service. It does the following:
    a. Initializes ADM module
    b. Register event handler and attribute change callback function
    c. Start ADM module(will start Matter protocol service)
    d. Initializes Matter demo GPIO port
    e. Register Matter demo properties
  3. Review other functions in demo_matter.c. Your application will need to implement similar functionality to support Matter protocol.
    a. demo_idle implements the host task thread, which handle button press event and on/off operation.
    b. demo_matter_event_cb implements handling matter event, call ada_client_ip_up when received IPV4 up event, call ada_client_ip_down when received IPV4 down event.
    c. demo_on_off_cb implements handling matter on/off attribute change callback. The demo_on_off_cb is used in the demo_on_off_cb_entry struct, you need to define this variable first.
    d. demo_write_notify_event implements to notify the Matter protocol stack when user pressed the button.
    e. demo_props defines the demo property list, you should use the ada_sprop_mgr_register to register it.

Enabling Matter support in your application

  1. Base ayla_matter_demo to implement your application.
  2. Update the ADM_CLUSTER_LIST cluster list to follow your application requirement, the ADM_CLUSTER_LIST defined in CMakeLists.txt in ayla_matter_demo directory.
  3. Use zap tool to update zap/ayla_demo.zap, define your application cluster/attribute list, and generate the zap code, copy generated files into examples/ayla_matter_demo/main/zap-generated directory or examples/ayla_matter_demo/main/app directory.
  4. Update the demo_props property list to define your application property list.
  5. Call adm_attribute_change_cb_register to register your application implement's cluster attribute change notification.

Note: You could refer the below command to install zap tool.

apt-get update
apt-get install --fix-missing libpixman-1-dev libcairo-dev libsdl-pango-dev libjpeg-dev libgif-dev

wget https://github.com/project-chip/zap/releases/download/v2023.11.13/zap-linux-x64.zip
mkdir zap-linux-x64
cd zap-linux-x64
unzip ../zap-linux-x64.zip

export ZAP_INSTALL_PATH=~/work/zap/zap-linux-x64
cd ~/work/aylasrc/examples/ayla_matter_demo/zap  # Your zap file path
~/work/CHIP-v1.0.0.2/scripts/tools/zap/run_zaptool.sh ./ayla_demo.zap 

Files

  • lib/adm/adm.* Initializes Matter protocol stack, starts Matter service, implements the Matter stack event callback and attribute change callback.
  • lib/adm/adm_data_provider.* implements the Matter factory data handling.
  • lib/adm/ayla-server.* implements the Ayla Matter register handling, adding/registering device in Mobile App will need these device information.
  • lib/adm/ayla-lc-server.* implements Ayla local control via Matter protocol.
  • lib/adm/adm_cli.* implements CLI commands for Matter protocol data configuration.
  • examples/ayla_matter_demo/demo_matter.c implements Matter application functions.

Build Switches

The define symbol AYLA_MATTER_SUPPORT is used as a compile time switch to enable or disable inclusion of Matter features. Defining this symbol enables compilation of Matter support. This symbol is defined by default. It is defined in the following files:

  • tools/cmake/ayla_matter_project.cmake
  • examples/ayla_matter_demo/CMakeLists.txt