This shows you the differences between two versions of the page.
|
iothings:laboratoare:2025:lab5 [2025/10/22 10:41] dan.tudose [Zigbee Router + End Device] |
iothings:laboratoare:2025:lab5 [2025/10/28 11:35] (current) dan.tudose [Switch as a Sleepy ED] |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Lab 5. Zigbee ====== | + | ====== Lab 5. Zigbee Networking ====== |
| Zigbee is a low‑power, low‑data‑rate wireless protocol for building sensor/actuator networks (home automation, smart energy, lighting, industrial monitoring). It sits on top of IEEE 802.15.4 radios and adds networking, security, and application profiles. | Zigbee is a low‑power, low‑data‑rate wireless protocol for building sensor/actuator networks (home automation, smart energy, lighting, industrial monitoring). It sits on top of IEEE 802.15.4 radios and adds networking, security, and application profiles. | ||
| 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 186: | Line 184: | ||
| <code bash platformio.ini> | <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] | [platformio] | ||
| default_envs = sparrow-switch | default_envs = sparrow-switch | ||
| Line 202: | Line 209: | ||
| ;-D CORE_DEBUG_LEVEL=5 | ;-D CORE_DEBUG_LEVEL=5 | ||
| - | ; Use a partitions.csv that contains Zigbee NV partitions | + | ; Use a partitions.csv that contains Zigbee NV partitions (see step 2) |
| board_build.partitions = partitions.csv | board_build.partitions = partitions.csv | ||
| Line 212: | Line 219: | ||
| -D ZIGBEE_MODE_ED | -D ZIGBEE_MODE_ED | ||
| -D SPARROW_SWITCH | -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] | [env:sparrow-light] | ||
| Line 218: | Line 231: | ||
| -D ZIGBEE_MODE_ROUTER | -D ZIGBEE_MODE_ROUTER | ||
| -D SPARROW_LIGHT | -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 = | lib_deps = | ||
| adafruit/Adafruit NeoPixel@^1.12.0 | adafruit/Adafruit NeoPixel@^1.12.0 | ||
| + | |||
| </code> | </code> | ||
| - | When building and deploying on the two nodes, switch between ''sparrow-switch'' and ''sparrow-light''. | + | When building and deploying on the two nodes, switch ''default_envs'' between ''sparrow-switch'' and ''sparrow-light''. |
| Keep the same partitions.csv file. | Keep the same partitions.csv file. | ||
| Line 229: | Line 249: | ||
| The main is a dual one, depending on which type of device you are building for from platformio.ini. | 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.]] | ||
| + | |||
| + | ====== Switch as a Sleepy ED ====== | ||
| + | |||
| + | The previous example has the downside that the ED can be battery powered, but the code is not particularly optimized for energy saving. As a regular user will not press the switch more that a dozen times a day, it makes a lot of sense to keep the switch ED in deep sleep and wake only when the button is pressed. waking from deep sleep equates to having a hardware reset, so we will need to persist switch logic into the non-volatile RTC memory. This is all handled in the code below. | ||
| + | |||
| + | [[iothings:laboratoare:2025_code:lab5_3|Click here to get the code for this example.]] | ||
| + | |||
| + | <note>**Assignment 1:** | ||
| + | Use the on-board BME680 sensor to switch lights on/off depending on the switch temperature instead of pushing a button. For example, if the temperature is above 25 degrees C, the light should turn on. | ||
| + | </note> | ||
| + | |||
| + | <note>**Assignment 2:** | ||
| + | Encode more than simple on/off behavior from the switch. For example, a press toggles, and a hold dims up/down. Add a long-press detector on GPIO 9 and send MoveWithOnOff / Stop commands; on the bulb, implement Level Control callbacks to set NeoPixel brightness with transition times. | ||
| + | </note> | ||
| + | |||
| + | <hidden> | ||
| + | Pentru asistenți: la laboratorul ăsta o să aveți nevoie de un gateway Home Assistant cu stick Zigbee Coordinator atașat. Dacă nu aveți așa ceva, întrebați-l pe Dan Tudose. | ||
| + | </hidden> | ||