Description
Board
ESP32C6
Device Description
Button and RGB led onboard
Hardware Configuration
ESP32C6Zero (Waveshare)
Version
latest development Release Candidate (RC-X)
IDE Name
Arduino IDE
Operating System
Mac OSX 15.1
Flash frequency
80
PSRAM enabled
no
Upload speed
921000
Description
Hello,
I have tested to create ESP32C6 zigbee device with light, temperature and input switch at the same time. Basically it works. Temperature and Light are fully ok. While I tested many things to get the switch to work without any success.
I want it to work with Z2M and not as local coordinator.
First problem from the example is zbSwitch.setManualBinding(true); that does not exist as method. Strange. Looked at all repos and no clue.
Second problem is it reports as IAS with alarm1, alarm2 what is in the code. How to create a simple (or multiple) wall input buttons with simple, double or whatever function? I do not see it in any example. Seems to me a basic function but I cannot find anything working in Arduino IDE with the wrappers.
Third problem is the ROUTER mode, if I try the MultiSwitch example with Coordinator in ESP stack config and start with Zigbee.begin(ZIGBEE_ROUTER) it crashes at startup.
If anybody has any idea... mmany thanks. Library ESP is latest 3.3.0 alpha 1.
Sketch
Here is the global sketch:
// 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 Zigbee temperature sensor.
*
* The example demonstrates how to use Zigbee library to create a end device temperature sensor.
* The temperature sensor 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 temperature sensor configuration */
#define TEMP_SENSOR_ENDPOINT_NUMBER 10
#define ZIGBEE_LIGHT_ENDPOINT 11
#define CONTACT_SWITCH_ENDPOINT_NUMBER 12
//#define ZIGBEE_ROLE NONE//ZIGBEE_ROUTER
uint8_t button = 9;
uint8_t sensor_pin = 9;
#define LED_PIN 8
typedef enum {
SWITCH_ON_CONTROL,
SWITCH_OFF_CONTROL,
SWITCH_ONOFF_TOGGLE_CONTROL,
SWITCH_LEVEL_UP_CONTROL,
SWITCH_LEVEL_DOWN_CONTROL,
SWITCH_LEVEL_CYCLE_CONTROL,
SWITCH_COLOR_CONTROL,
} SwitchFunction;
typedef struct {
uint8_t pin;
SwitchFunction func;
} SwitchData;
typedef enum {
SWITCH_IDLE,
SWITCH_PRESS_ARMED,
SWITCH_PRESS_DETECTED,
SWITCH_PRESSED,
SWITCH_RELEASE_DETECTED,
} SwitchState;
// Optional Time cluster variables
struct tm timeinfo;
struct tm *localTime;
int32_t timezone;
ZigbeeTempSensor zbTempSensor = ZigbeeTempSensor(TEMP_SENSOR_ENDPOINT_NUMBER);
ZigbeeLight zbLight = ZigbeeLight(ZIGBEE_LIGHT_ENDPOINT);
ZigbeeContactSwitch zbContactSwitch = ZigbeeContactSwitch(CONTACT_SWITCH_ENDPOINT_NUMBER);
/********************* RGB LED functions **************************/
void setLED(bool value) {
if (value)
rgbLedWrite(LED_PIN,0,255,0);
else
rgbLedWrite(LED_PIN,0,0,0);
}
/************************ Temp sensor *****************************/
static void temp_sensor_value_update(void *arg) {
for (;;) {
// Read temperature sensor value
float tsens_value = temperatureRead();
Serial.printf("Updated temperature sensor value to %.2f°C\r\n", tsens_value);
// Update temperature value in Temperature sensor EP
zbTempSensor.setTemperature(tsens_value);
delay(1000);
}
}
/********************* Arduino functions **************************/
void setup() {
Serial.begin(115200);
// Init button + switch
pinMode(button, INPUT_PULLUP);
pinMode(sensor_pin, INPUT_PULLUP);
// Init RGB and leave light OFF
rgbLedWrite(LED_PIN,0,0,0);
// Set callback function for light change
zbLight.onLightChange(setLED);
zbLight.setVersion( 1234);
zbTempSensor.setVersion( 1234);
zbContactSwitch.setVersion( 1234);
//Add endpoint to Zigbee Core
Serial.println("Adding ZigbeeSwitch endpoint to Zigbee Core");
Zigbee.addEndpoint(&zbContactSwitch);
//Add endpoint to Zigbee Core
Serial.println("Adding ZigbeeLight endpoint to Zigbee Core");
Zigbee.addEndpoint(&zbLight);
// Optional: set Zigbee device name and model
zbTempSensor.setManufacturerAndModel("B4E", "ZB_Test_1");
// Set minimum and maximum temperature measurement value (10-50°C is default range for chip temperature measurement)
zbTempSensor.setMinMaxValue(10, 60);
// Optional: Set tolerance for temperature measurement in °C (lowest possible value is 0.01°C)
zbTempSensor.setTolerance(1);
// Optional: Time cluster configuration (default params, as this device will revieve time from coordinator)
zbTempSensor.addTimeCluster();
// Add endpoint to Zigbee Core
Serial.println("Adding ZigbeeTemperature endpoint to Zigbee Core");
Zigbee.addEndpoint(&zbTempSensor);
Serial.println("Starting Zigbee...");
// When all EPs are registered, start Zigbee in End Device mode
if (!Zigbee.begin()) {
Serial.println("Zigbee failed to start!");
Serial.println("Rebooting...");
ESP.restart();
} else {
Serial.println("Zigbee started successfully!");
}
Serial.println("Connecting to network");
while (!Zigbee.connected()) {
Serial.print(".");
delay(100);
}
Serial.println();
// Optional: If time cluster is added, time can be read from the coordinator
timeinfo = zbTempSensor.getTime();
timezone = zbTempSensor.getTimezone();
Serial.println("UTC time:");
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
time_t local = mktime(&timeinfo) + timezone;
localTime = localtime(&local);
Serial.println("Local time with timezone:");
Serial.println(localTime, "%A, %B %d %Y %H:%M:%S");
// Start Temperature sensor reading task
xTaskCreate(temp_sensor_value_update, "temp_sensor_update", 2048, NULL, 10, NULL);
// Set reporting interval for temperature measurement in seconds, must be called after Zigbee.begin()
// min_interval and max_interval in seconds, delta (temp change in 0,1 °C)
// if min = 1 and max = 0, reporting is sent only when temperature changes by delta
// if min = 0 and max = 10, reporting is sent every 10 seconds or temperature changes by delta
// if min = 0, max = 10 and delta = 0, reporting is sent every 10 seconds regardless of temperature change
zbTempSensor.setReporting(1, 0, 1);
}
void loop() {
#if 0
// 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();
}
}
zbTempSensor.reportTemperature();
}
#endif
// Checking pin for contact change
static bool contact = false;
if (digitalRead(sensor_pin) == HIGH && !contact) {
// Update contact sensor value
zbContactSwitch.setClosed();
contact = true;
Serial.println("Switch true");
} else if (digitalRead(sensor_pin) == LOW && contact) {
zbContactSwitch.setOpen();
contact = false;
Serial.println("Switch false");
}
#if 0
// 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();
}
}
}
#endif
delay(100);
// Send temperature each 10 seconds
static uint32_t lastPrint = 0;
if (millis() - lastPrint > 10000) {
lastPrint = millis();
zbTempSensor.reportTemperature();
}
}
[Zigbee_Sensor.txt](https://github.com/user-attachments/files/21077061/Zigbee_Sensor.txt)
Debug Message
[ 1336][E][ZigbeeContactSwitch.cpp:82] report(): Failed to send IAS Zone status changed notification: 0x2: ERROR
Switch true
Other Steps to Reproduce
No additional steps
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.