This shows you the differences between two versions of the page.
iothings:laboratoare:2025:lab5 [2025/10/22 10:34] dan.tudose [Zigbee ED Example] |
iothings:laboratoare:2025:lab5 [2025/10/22 11:33] (current) dan.tudose [Zigbee Router + End Device] |
||
---|---|---|---|
Line 102: | Line 102: | ||
As a coordinator we will be using a [[https://www.home-assistant.io/green/|Home Assistant Green]] gateway with a [[https://www.home-assistant.io/connectzbt1|Connect ZBT-1]] Zigbee Coordinator attached. | As a coordinator we will be using a [[https://www.home-assistant.io/green/|Home Assistant Green]] gateway with a [[https://www.home-assistant.io/connectzbt1|Connect ZBT-1]] Zigbee Coordinator attached. | ||
- | ===== Platformio Project Setup ===== | ||
You will need to edit platformio.ini and add these compile flags and libraries: | You will need to edit platformio.ini and add these compile flags and libraries: | ||
Line 149: | Line 148: | ||
</code> | </code> | ||
- | ===== Zigbee ED Example ===== | ||
Then you can add the main.cpp contents. | Then you can add the main.cpp contents. | ||
Line 160: | Line 158: | ||
The device registers itself on the Zigbee network with manufacturer and model identifiers, sets reporting intervals and tolerances for each sensor type, and reacts to identify commands by blinking its LED. If Zigbee fails to initialize or connect, it restarts the ESP32. | The device registers itself on the Zigbee network with manufacturer and model identifiers, sets reporting intervals and tolerances for each sensor type, and reacts to identify commands by blinking its LED. If Zigbee fails to initialize or connect, it restarts the ESP32. | ||
- | ===== Zigbee Router + End Device ===== | + | ====== Zigbee Router + End Device ====== |
In this next example we will simulate a Zigbee smart lightbulb controlled by a Zigbee light switch, using two ESP32-C6 Sparrow nodes. | In this next example we will simulate a Zigbee smart lightbulb controlled by a Zigbee light switch, using two ESP32-C6 Sparrow nodes. | ||
Line 179: | Line 177: | ||
When the ED button is pressed it sends an On or Off Zigbee command to the bound router device. The router receives the command and toggles the NeoPixel accordingly. Zigbee binding or group addressing links the two. | When the ED button is pressed it sends an On or Off Zigbee command to the bound router device. The router receives the command and toggles the NeoPixel accordingly. Zigbee binding or group addressing links the two. | ||
+ | |||
+ | |||
+ | === Platformio Project Setup === | ||
+ | |||
+ | You will need to modify platformio.ini with this dual-environment file: | ||
+ | |||
+ | <code bash platformio.ini> | ||
+ | ; PlatformIO Project Configuration File | ||
+ | ; | ||
+ | ; Build options: build flags, source filter | ||
+ | ; Upload options: custom upload port, speed and extra flags | ||
+ | ; Library options: dependencies, extra library storages | ||
+ | ; Advanced options: extra scripting | ||
+ | ; | ||
+ | ; See https://docs.platformio.org/page/projectconf.html for details. | ||
+ | |||
+ | [platformio] | ||
+ | default_envs = sparrow-switch | ||
+ | |||
+ | [env] | ||
+ | platform = https://github.com/pioarduino/platform-espressif32/releases/download/54.03.20/platform-espressif32.zip | ||
+ | board = esp32-c6-devkitm-1 | ||
+ | framework = arduino | ||
+ | ; use SPIFFS for on-board files | ||
+ | ;board_build.filesystem = spiffs | ||
+ | build_flags = | ||
+ | -D ARDUINO_USB_MODE=1 | ||
+ | -D ARDUINO_USB_CDC_ON_BOOT=1 | ||
+ | -D ESP32_C6_env | ||
+ | ; (optional) more logs while bringing up Zigbee | ||
+ | ;-D CORE_DEBUG_LEVEL=5 | ||
+ | |||
+ | ; Use a partitions.csv that contains Zigbee NV partitions (see step 2) | ||
+ | board_build.partitions = partitions.csv | ||
+ | |||
+ | monitor_speed = 115200 | ||
+ | |||
+ | [env:sparrow-switch] | ||
+ | build_flags = | ||
+ | ${env.build_flags} | ||
+ | -D ZIGBEE_MODE_ED | ||
+ | -D SPARROW_SWITCH | ||
+ | -D CONFIG_ZB_ENABLED=1 | ||
+ | -L$PLATFORMIO_PACKAGES_DIR/framework-arduinoespressif32-libs/esp32c6/lib | ||
+ | -lesp_zb_api.ed | ||
+ | -lzboss_stack.ed | ||
+ | -lzboss_port.native | ||
+ | -lzboss_port.remote | ||
+ | |||
+ | [env:sparrow-light] | ||
+ | build_flags = | ||
+ | ${env.build_flags} | ||
+ | -D ZIGBEE_MODE_ROUTER | ||
+ | -D SPARROW_LIGHT | ||
+ | -D CONFIG_ZB_ENABLED=1 | ||
+ | -L$PLATFORMIO_PACKAGES_DIR/framework-arduinoespressif32-libs/esp32c6/lib | ||
+ | -lesp_zb_api.zczr | ||
+ | -lzboss_stack.zczr | ||
+ | -lzboss_port.native | ||
+ | -lzboss_port.remote | ||
+ | lib_deps = | ||
+ | adafruit/Adafruit NeoPixel@^1.12.0 | ||
+ | |||
+ | |||
+ | </code> | ||
+ | |||
+ | When building and deploying on the two nodes, switch ''default_envs'' between ''sparrow-switch'' and ''sparrow-light''. | ||
+ | |||
+ | Keep the same partitions.csv file. | ||
+ | |||
+ | The main is a dual one, depending on which type of device you are building for from platformio.ini. | ||
+ | |||
+ | [[iothings:laboratoare:2025_code:lab5_2|Click here to get the code for this example.]] | ||
+ |