ESP32-C6 Zigbee On/Off Light Example - Unstable Commissioning & Boot Button Quirk

ajlaj25
Posts: 1
Joined: Fri Nov 28, 2025 6:12 pm

ESP32-C6 Zigbee On/Off Light Example - Unstable Commissioning & Boot Button Quirk

Postby ajlaj25 » Fri Nov 28, 2025 7:55 pm

Hi everyone,

I'm hoping to get some guidance with the Zigbee_On_Off_Light example on an ESP32-C6. I'm coming from a Python/Rust software development background, so while coding itself is familiar, the world of microcontrollers and Zigbee is new to me. I've only done a couple of small home projects in the past.

I'm facing some persistent and confusing issues with device commissioning and stability.

My Setup:
Board: ESP32-C6-WROOM-1 (The back says ESP32-C6-DEV-KIT-N8)
IDE: Arduino IDE (freshly set up)
Example: Barebones Zigbee_On_Off_Light (with minor added logging)
Zigbee Coordinator: SONOFF Dongle Max with Home Assistant ZHA.

My Configuration (Arduino IDE -> Tools):
Board: ESP32C6 Dev Module
Erease Flash before Sketch upload: Enabled
Flash size: 8MB
Partition Scheme: Zigbee 8MB with spiffs
Zigbee mode: Zigbee ED

(Everything else is on default. Sorry, for some reason I couln't upload a picture.)
(I've assumed the Flash Size and Partition Scheme should be set to "8MB" and "Zigbee 8MB with spiffs" respectively, since the board is marked "N8". Please correct me if this is wrong.)

The Problem:
Initial Commissioning: The code builds and flashes without errors. On boot, it prints dots (.) indefinitely. My device will not appear in ZHA's pairing list unless I repeatedly press the BOOT button on the board. Once I do this, it pairs and works flawlessly.

Post-Reboot Instability: After a reboot, the behavior is completely random. Sometimes it rejoins the network instantly, sometimes it takes minutes, and sometimes pressing the BOOT button again seems to help. Other times, I have to remove it from ZHA and re-pair it entirely. I've spent 6-8 hours trying to find a pattern.

My Questions:
Why would pressing the BOOT button have any effect on Zigbee commissioning? From my understanding, it should be irrelevant.
Is it necessary to remove and re-pair the device in ZHA after every new flash, even for minor code changes?
Are there any "developer" settings in ZHA that could help a developer?
What does Zigbee.factoryReset() actually do? Does it require a re-pair with the coordinator afterward?
Are there any recommended, up-to-date guides for developing Zigbee devices on the ESP32-C6?
Is there comprehensive documentation for the ESP-Zigbee-SDK API (e.g., detailed explanations for functions like Zigbee.factoryReset)?

Any help, insight, or pointers to the right documentation would be greatly appreciated. I feel like I'm missing a fundamental piece of the puzzle.

Thanks in advance!

The code:

Code: Select all

// Copyright 2024 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @brief This example demonstrates simple Zigbee light bulb.
 *
 * The example demonstrates how to use Zigbee library to create a end device light bulb.
 * The light bulb is a Zigbee end device, which is controlled by a Zigbee coordinator.
 *
 * Proper Zigbee mode must be selected in Tools->Zigbee mode
 * and also the correct partition scheme must be selected in Tools->Partition Scheme.
 *
 * Please check the README.md for instructions and more detailed description.
 *
 * Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/)
 */

#ifndef ZIGBEE_MODE_ED
#error "Zigbee end device mode is not selected in Tools->Zigbee mode"
#endif

#include "Zigbee.h"

/* Zigbee light bulb configuration */
#define ZIGBEE_LIGHT_ENDPOINT 10
uint8_t led = RGB_BUILTIN;
uint8_t button = BOOT_PIN;

ZigbeeLight zbLight = ZigbeeLight(ZIGBEE_LIGHT_ENDPOINT);

/********************* RGB LED functions **************************/
void setLED(bool value) {
  Serial.println("setLED function called!");
  digitalWrite(led, value);
}

/********************* Arduino functions **************************/
void setup() {
  delay(5000);
  Serial.begin(115200);

  Serial.println("Setup start!");

  // Init LED and turn it OFF (if LED_PIN == RGB_BUILTIN, the rgbLedWrite() will be used under the hood)
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);

  // Init button for factory reset
  pinMode(button, INPUT_PULLUP);

  //Optional: set Zigbee device name and model
  zbLight.setManufacturerAndModel("Espressif", "ZBLightBulb");

  // Set callback function for light change
  zbLight.onLightChange(setLED);

  //Add endpoint to Zigbee Core
  Serial.println("Adding ZigbeeLight endpoint to Zigbee Core");
  Zigbee.addEndpoint(&zbLight);
  Serial.println("Zigbee endpoints are added to Zigbee Core");

  // When all EPs are registered, start Zigbee. By default acts as ZIGBEE_END_DEVICE
  if (!Zigbee.begin()) {
    Serial.println("Zigbee failed to start!");
    Serial.println("Rebooting...");
    ESP.restart();
  }

  unsigned long startTime = millis();
  while (!Zigbee.connected()) {
    Serial.print(".");
    delay(1000);
    
    // Timeout after 30 seconds
    if (millis() - startTime > 30000) {
      Serial.println("\nConnection timeout! Rebooting...");
      // Zigbee.factoryReset();
      ESP.restart();
    }
  }
  Serial.printf("\nConnected in %lu ms\n", millis() - startTime);

  Serial.println("Setup end!");
}

void loop() {
  // Checking button for factory reset
  if (digitalRead(button) == LOW) {  // Push button pressed
    // Key debounce handling
    delay(100);
    int startTime = millis();
    while (digitalRead(button) == LOW) {
      delay(50);
      if ((millis() - startTime) > 3000) {
        
        // If key pressed for more than 3secs, factory reset Zigbee and reboot
        Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
        delay(1000);
        Zigbee.factoryReset();
      }
    }
    // Toggle light by pressing the button
    zbLight.setLight(!zbLight.getLightState());
  }

  delay(1000);
  Serial.println("loop");
}

Who is online

Users browsing this forum: Qwantbot and 2 guests