Skip to content

Endpoint alarm_1 or alarm_2 #12085

@Geyorgiy

Description

@Geyorgiy

Board

nanoESP32-C6

Device Description

nanoESP32-C6

Hardware Configuration

9 : GPIO
12 : USB_DM
13 : USB_DP
16 : UART_TX[0]
17 : UART_RX[0]

Version

v3.3.4

Type

Bug

IDE Name

Arduino Ide 2.3.6

Operating System

Linux Mint 21.3

Flash frequency

80

PSRAM enabled

yes

Upload speed

115200

Description

Good afternoon, no matter what examples I use for the end device, there is always an alarm_1 and alarm_2 endpoint.
nanoESP32-C6 ,arduino ide 2.3.6

Image

Sketch

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

#include "Zigbee.h"
#include <Preferences.h>

/* Zigbee contact sensor configuration */
#define CONTACT_SWITCH_ENDPOINT_NUMBER 1
#define CONTACT_SWITCH_ENDPOINT_NUMBER 2
#define CONTACT_SWITCH_ENDPOINT_NUMBER 3

uint8_t button = BOOT_PIN;
uint8_t sensor_pin_1 = 4;
uint8_t sensor_pin_2 = 5;
uint8_t sensor_pin_3 = 6;

ZigbeeContactSwitch zbContactSwitch_1 = ZigbeeContactSwitch(CONTACT_SWITCH_ENDPOINT_NUMBER);

ZigbeeContactSwitch zbContactSwitch_2 = ZigbeeContactSwitch(CONTACT_SWITCH_ENDPOINT_NUMBER + 1);

ZigbeeContactSwitch zbContactSwitch_3 = ZigbeeContactSwitch(CONTACT_SWITCH_ENDPOINT_NUMBER + 2);

/* Preferences for storing ENROLLED flag to persist across reboots */
Preferences preferences;

void setup() {
  Serial.begin(115200);

  preferences.begin("Zigbee", false);               // Save ENROLLED flag in flash so it persists across reboots
  bool enrolled = preferences.getBool("ENROLLED");  // Get ENROLLED flag from preferences
  preferences.end();

  // Init button + switch
  pinMode(button, INPUT_PULLUP);
  pinMode(sensor_pin_1, INPUT_PULLUP);
  pinMode(button, INPUT_PULLUP);
  pinMode(sensor_pin_2, INPUT_PULLUP);
  pinMode(button, INPUT_PULLUP);
  pinMode(sensor_pin_3, INPUT_PULLUP);

  // Optional: set Zigbee device name and model
  zbContactSwitch_1.setManufacturerAndModel("Espressif", "ZigbeeContact1");
  zbContactSwitch_2.setManufacturerAndModel("Espressif", "ZigbeeContact2");
  zbContactSwitch_3.setManufacturerAndModel("Espressif", "ZigbeeContact3");

  // Add endpoint to Zigbee Core
  Zigbee.addEndpoint(&zbContactSwitch_1);
  Zigbee.addEndpoint(&zbContactSwitch_2);
  Zigbee.addEndpoint(&zbContactSwitch_3);

  
  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();

  // Check if device has been enrolled before restarting - if so, restore IAS Zone enroll, otherwise request new IAS Zone enroll
  if (enrolled) {
    Serial.println("Device has been enrolled before - restoring IAS Zone enrollment");
    zbContactSwitch_1.restoreIASZoneEnroll();
    zbContactSwitch_2.restoreIASZoneEnroll();
    zbContactSwitch_3.restoreIASZoneEnroll();


  } else {
    Serial.println("Device is factory new - first time joining network - requesting new IAS Zone enrollment");
    zbContactSwitch_1.requestIASZoneEnroll();
    zbContactSwitch_2.requestIASZoneEnroll();
    zbContactSwitch_3.requestIASZoneEnroll();

  }

  while (!zbContactSwitch_1.enrolled());
        (!zbContactSwitch_2.enrolled());
        (!zbContactSwitch_3.enrolled());{
    Serial.print(".");
    delay(100);
  }
  Serial.println();
  Serial.println("Zigbee enrolled successfully!");

  // Store ENROLLED flag only if this was a new enrollment (previous flag was false)
  // Skip writing if we just restored enrollment (flag was already true)
  if (!enrolled) {
    preferences.begin("Zigbee", false);
    preferences.putBool("ENROLLED", true);  // set ENROLLED flag to true
    preferences.end();
    Serial.println("ENROLLED flag saved to preferences");
  }
}

void loop() {
  // Checking pin for contact change
  static bool contact_1 = false;
  if (digitalRead(sensor_pin_1) == HIGH && !contact_1) {
    // Update contact sensor value
    zbContactSwitch_1.setOpen();
    contact_1 = true;
  } else if (digitalRead(sensor_pin_1) == LOW && contact_1) {
    zbContactSwitch_1.setClosed();
    contact_1 = false;
  }


  static bool contact_2 = false;
  if (digitalRead(sensor_pin_2) == HIGH && !contact_2) {
    // Update contact sensor value
    zbContactSwitch_2.setOpen();
    contact_2 = true;
  } else if (digitalRead(sensor_pin_2) == LOW && contact_2) {
    zbContactSwitch_2.setClosed();
    contact_2 = false;
  }

 static bool contact_3 = false;
  if (digitalRead(sensor_pin_3) == HIGH && !contact_3) {
    // Update contact sensor value
    zbContactSwitch_3.setOpen();
    contact_3 = true;
  } else if (digitalRead(sensor_pin_3) == LOW && contact_3) {
    zbContactSwitch_3.setClosed();
    contact_3 = false;
  }


  // 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.");
        // Clear the ENROLLED flag from preferences
        preferences.begin("Zigbee", false);
        preferences.putBool("ENROLLED", false);  // set ENROLLED flag to false
        preferences.end();
        Serial.println("ENROLLED flag cleared from preferences");
        delay(1000);
        Zigbee.factoryReset();
      }
    }
  }
  delay(100);

Debug Message

12:06:38.827 -> [  1453][D][ZigbeeCore.cpp:578] bindingTableCb(): Clearing bound devices for EP 5
12:06:38.827 -> Zigbee started successfully!
12:06:38.827 -> Connecting to network
12:06:38.827 -> 
12:06:38.827 -> Device has been enrolled before - restoring IAS Zone enrollment
12:06:38.827 -> [  1454][D][ZigbeeContactSwitch.cpp:158] restoreIASZoneEnroll(): Restored IAS Zone enroll: zone id(255), ias cie address(FF:FF:FF:FF:FF:FF:FF:FF)
12:06:38.827 -> [  1454][E][ZigbeeContactSwitch.cpp:164] restoreIASZoneEnroll(): Failed to restore IAS Zone enroll: zone id not valid
12:06:38.827 -> [  1455][D][ZigbeeContactSwitch.cpp:158] restoreIASZoneEnroll(): Restored IAS Zone enroll: zone id(255), ias cie address(FF:FF:FF:FF:FF:FF:FF:FF)
12:06:38.827 -> [  1456][E][ZigbeeContactSwitch.cpp:164] restoreIASZoneEnroll(): Failed to restore IAS Zone enroll: zone id not valid
12:06:38.827 -> [  1457][D][ZigbeeContactSwitch.cpp:158] restoreIASZoneEnroll(): Restored IAS Zone enroll: zone id(255), ias cie address(FF:FF:FF:FF:FF:FF:FF:FF)
12:06:38.827 -> [  1458][E][ZigbeeContactSwitch.cpp:164] restoreIASZoneEnroll(): Failed to restore IAS Zone enroll: zone id not valid
12:06:38.827 -> .
12:06:38.924 -> Zigbee enrolled successfully!
12:06:38.924 -> =========== After Setup Start ============
12:06:38.924 -> INTERNAL Memory Info:
12:06:38.924 -> ------------------------------------------
12:06:38.924 ->   Total Size        :   439212 B ( 428.9 KB)
12:06:38.924 ->   Free Bytes        :   371024 B ( 362.3 KB)
12:06:38.924 ->   Allocated Bytes   :    59564 B (  58.2 KB)
12:06:38.924 ->   Minimum Free Bytes:   370860 B ( 362.2 KB)
12:06:38.924 ->   Largest Free Block:   352244 B ( 344.0 KB)
12:06:38.924 -> ------------------------------------------
12:06:38.924 -> GPIO Info:
12:06:38.924 -> ------------------------------------------
12:06:38.924 ->   GPIO : BUS_TYPE[bus/unit][chan]
12:06:38.924 ->   --------------------------------------  
12:06:38.924 ->      4 : GPIO
12:06:38.924 ->      5 : GPIO
12:06:38.924 ->      6 : GPIO
12:06:38.924 ->      9 : GPIO
12:06:38.924 ->     12 : USB_DM
12:06:38.924 ->     13 : USB_DP
12:06:38.924 ->     16 : UART_TX[0]
12:06:38.924 ->     17 : UART_RX[0]
12:06:38.924 -> ============ After Setup End =============
12:06:38.956 -> [  1583][V][ZigbeeContactSwitch.cpp:66] setOpen(): Setting Contact switch to open
12:06:38.956 -> [[  1584][V][ZigbeeCore.cpp:466] esp_zb_app_signal_handler(): ZDO signal: ZDO Device Unavailable (0x3c), status: ESP_OK
12:06:38.956 ->   1584][V][ZigbeeContactSwitch.cpp:98] report(): IAS Zone status changed notification sent
12:06:38.956 -> [  1586][V][ZigbeeContactSwitch.cpp:66] setOpen(): Setting Contact switch to open
12:06:38.956 -> [[  1587][V][ZigbeeCore.cpp:466] esp_zb_app_signal_handler(): ZDO signal: ZDO Device Unavailable (0x3c), status: ESP_OK
12:06:38.956 ->   1587][V][ZigbeeContactSwitch.cpp:98] report(): IAS Zone status changed notification sent
12:06:38.956 -> [  1588][V][ZigbeeContactSwitch.cpp:66] setOpen(): Setting Contact switch to open
12:06:38.956 -> [[  1590][V][ZigbeeCore.cpp:466] esp_zb_app_signal_handler(): ZDO signal: ZDO Device Unavailable (0x3c), status: ESP_OK
12:06:38.956 ->   1589][V][ZigbeeContactSwitch.cpp:98] report(): IAS Zone status changed notification sent

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions