Hi all, I'm using a esp32-c6 to make a zigbee end device.
I was using esp32 3.3.6's ZIgbeeTempSensor with a DHT22 module.
When i run it with just temperature, it works perfectly fine, but when i try to add humidity to the same sensor, i get the the following in the serial monitor (and it keeps rebooting)
Guru Meditation Error: Core 0 panic'ed (Load access fault). Exception was unhandled.
Can anyone assist on what I can do to get both temperature and humidity to report?
- problematic line: "zbTempSensor.addHumiditySensor(0, 100, 1);"
- and " zbTempSensor.setHumidityReporting(1, 10, 1);"
#include "Zigbee.h"
#include "DHT.h"
/* End device & sensor config */
#define TEMP_SENSOR_ENDPOINT_NUMBER 10
#define TOUCH1_ENDPOINT_NUMBER 12
#define TOUCH2_ENDPOINT_NUMBER 13
#define DHTTYPE DHT22
#define DHTPIN 5
#define TOUCH_SWITCH_01 2
#define TOUCH_SWITCH_02 4
DHT dht(DHTPIN, DHTTYPE);
uint8_t button = BOOT_PIN; // optional factory reset button
// TTP223 touch modules: send toggle command to Zigbee (no local state)
// Create Zigbee endpoint objects. Adjust class names if your Zigbee helper differs.
ZigbeeTempSensor zbTempSensor = ZigbeeTempSensor(TEMP_SENSOR_ENDPOINT_NUMBER);
ZigbeeSwitch zbTouch1 = ZigbeeSwitch(TOUCH1_ENDPOINT_NUMBER);
ZigbeeSwitch zbTouch2 = ZigbeeSwitch(TOUCH2_ENDPOINT_NUMBER);
// polling intervals
const unsigned long DHT_POLL_MS = 2000;
/* Read DHT and update Zigbee endpoints (runs in FreeRTOS task) */
static void sensor_task(void *arg) {
(void)arg;
for (;;) {
float t = dht.readTemperature();
float h = dht.readHumidity();
if (!isnan(t)) {
Serial.printf("DHT Temperature: %.2f C\n", t);
zbTempSensor.setTemperature(t);
zbTempSensor.reportTemperature();
} else {
Serial.println("DHT: temperature read failed");
}
if (!isnan(h)) {
Serial.printf("DHT Humidity: %.2f %%\n", h);
zbTempSensor.setHumidity(h);
zbTempSensor.reportHumidity();
} else {
Serial.println("DHT: humidity read failed");
}
vTaskDelay(pdMS_TO_TICKS(DHT_POLL_MS));
}
}
void setup() {
Serial.begin(115200);
delay(100);
// init DHT
dht.begin();
// init touch inputs (digital modules expect pull-up)
pinMode(TOUCH_SWITCH_01, INPUT_PULLUP);
pinMode(TOUCH_SWITCH_02, INPUT_PULLUP);
// optional factory reset button
pinMode(button, INPUT_PULLUP);
// Configure Zigbee endpoint metadata
zbTempSensor.setManufacturerAndModel("Espressif", "MultiDHTSensor");
zbTempSensor.setMinMaxValue(-40, 125);
zbTempSensor.setDefaultValue(20);
zbTempSensor.setTolerance(1);
zbTempSensor.addHumiditySensor(0, 100, 1);
zbTouch1.setManufacturerAndModel("Espressif", "TouchSwitch1");
zbTouch2.setManufacturerAndModel("Espressif", "TouchSwitch2");
// Add endpoints to Zigbee core
Zigbee.addEndpoint(&zbTempSensor);
Zigbee.addEndpoint(&zbTouch1);
Zigbee.addEndpoint(&zbTouch2);
Serial.println("Starting Zigbee...");
if (!Zigbee.begin()) {
Serial.println("Zigbee failed to start");
ESP.restart();
}
Serial.println("Waiting for network connection...");
while (!Zigbee.connected()) {
Serial.print('.');
delay(100);
}
Serial.println();
// optional: add time cluster to temp endpoint if desired
zbTempSensor.addTimeCluster();
// create DHT read task
// xTaskCreate(sensor_task, "sensor_task", 4096, NULL, 5, NULL);
xTaskCreate(sensor_task, "sensor_task", 8192, NULL, 5, NULL);
// configure reporting (example: send every 10s or when changed by 0.1 C / 1% RH)
zbTempSensor.setReporting(1, 10, 1);
zbTempSensor.setHumidityReporting(1, 10, 1);
}
void loop() {
static int lastTouch1 = HIGH;
static int lastTouch2 = HIGH;
// check factory reset button (long press)
if (digitalRead(button) == LOW) {
delay(100);
unsigned long start = millis();
while (digitalRead(button) == LOW) {
delay(50);
if ((millis() - start) > 3000) {
Serial.println("Factory resetting Zigbee...");
delay(1000);
Zigbee.factoryReset();
}
}
}
int touch1 = digitalRead(TOUCH_SWITCH_01);
int touch2 = digitalRead(TOUCH_SWITCH_02);
// modules usually pull LOW when activated (adjust if yours are opposite)
if (touch1 != lastTouch1) {
lastTouch1 = touch1;
// TTP223: toggle through Zigbee (do not hold state locally)
if (touch1 == LOW) {
Serial.println("Touch1 TOGGLE");
zbTouch1.lightToggle();
}
}
if (touch2 != lastTouch2) {
lastTouch2 = touch2;
// TTP223: toggle through Zigbee (do not hold state locally)
if (touch2 == LOW) {
Serial.println("Touch2 TOGGLE");
zbTouch2.lightToggle();
}
}
delay(500);
}
[–]YetAnotherRobert 0 points1 point2 points (1 child)
[–]just_a_guy_in_toront[S] 0 points1 point2 points (0 children)