Skip to content
Merged
43 changes: 38 additions & 5 deletions docs/en/zigbee/ep_contact_switch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ Sets the contact switch to open state.

This function will return ``true`` if successful, ``false`` otherwise.

report
^^^^^^

Manually reports the current contact state.

.. code-block:: arduino

bool report();

This function will return ``true`` if successful, ``false`` otherwise.

setIASClientEndpoint
^^^^^^^^^^^^^^^^^^^^

Expand All @@ -74,16 +85,38 @@ Sets the IAS Client endpoint number (default is 1).

* ``ep_number`` - IAS Client endpoint number

report
^^^^^^
requestIASZoneEnroll
^^^^^^^^^^^^^^^^^^^^

Manually reports the current contact state.
Requests a new IAS Zone enrollment. Can be called to enroll a new device or to re-enroll an already enrolled device.

.. code-block:: arduino

bool report();
bool requestIASZoneEnroll();

This function will return ``true`` if successful, ``false`` otherwise.
This function will return ``true`` if the enrollment request was sent successfully, ``false`` otherwise. The actual enrollment status should be checked using the ``enrolled()`` method after waiting for the enrollment response.

restoreIASZoneEnroll
^^^^^^^^^^^^^^^^^^^^

Restores IAS Zone enrollment from stored attributes. This method should be called after rebooting an already enrolled device. It restores the enrollment information from flash memory, which is faster for sleepy devices compared to requesting a new enrollment.

.. code-block:: arduino

bool restoreIASZoneEnroll();

This function will return ``true`` if the enrollment was successfully restored, ``false`` otherwise. The enrollment information (zone ID and IAS CIE address) must be available in the device's stored attributes for this to succeed.

enrolled
^^^^^^^^

Checks if the device is currently enrolled in the IAS Zone.

.. code-block:: arduino

bool enrolled();

This function returns ``true`` if the device is enrolled, ``false`` otherwise. Use this method to check the enrollment status after calling ``requestIASZoneEnroll()`` or ``restoreIASZoneEnroll()``.

Example
-------
Expand Down
43 changes: 38 additions & 5 deletions docs/en/zigbee/ep_door_window_handle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ Sets the door/window handle to tilted position.

This function will return ``true`` if successful, ``false`` otherwise.

report
^^^^^^

Manually reports the current handle position.

.. code-block:: arduino

bool report();

This function will return ``true`` if successful, ``false`` otherwise.

setIASClientEndpoint
^^^^^^^^^^^^^^^^^^^^

Expand All @@ -78,16 +89,38 @@ Sets the IAS Client endpoint number (default is 1).

* ``ep_number`` - IAS Client endpoint number

report
^^^^^^
requestIASZoneEnroll
^^^^^^^^^^^^^^^^^^^^

Manually reports the current handle position.
Requests a new IAS Zone enrollment. Can be called to enroll a new device or to re-enroll an already enrolled device.

.. code-block:: arduino

bool report();
bool requestIASZoneEnroll();

This function will return ``true`` if successful, ``false`` otherwise.
This function will return ``true`` if the enrollment request was sent successfully, ``false`` otherwise. The actual enrollment status should be checked using the ``enrolled()`` method after waiting for the enrollment response.

restoreIASZoneEnroll
^^^^^^^^^^^^^^^^^^^^

Restores IAS Zone enrollment from stored attributes. This method should be called after rebooting an already enrolled device. It restores the enrollment information from flash memory, which is faster for sleepy devices compared to requesting a new enrollment.

.. code-block:: arduino

bool restoreIASZoneEnroll();

This function will return ``true`` if the enrollment was successfully restored, ``false`` otherwise. The enrollment information (zone ID and IAS CIE address) must be available in the device's stored attributes for this to succeed.

enrolled
^^^^^^^^

Checks if the device is currently enrolled in the IAS Zone.

.. code-block:: arduino

bool enrolled();

This function returns ``true`` if the device is enrolled, ``false`` otherwise. Use this method to check the enrollment status after calling ``requestIASZoneEnroll()``.

Example
-------
Expand Down
37 changes: 35 additions & 2 deletions docs/en/zigbee/ep_vibration_sensor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,42 @@ Manually reports the current vibration state.

.. code-block:: arduino

void report();
bool report();

This function does not return a value.
This function will return ``true`` if successful, ``false`` otherwise.

requestIASZoneEnroll
^^^^^^^^^^^^^^^^^^^^

Requests a new IAS Zone enrollment. Can be called to enroll a new device or to re-enroll an already enrolled device.

.. code-block:: arduino

bool requestIASZoneEnroll();

This function will return ``true`` if the enrollment request was sent successfully, ``false`` otherwise. The actual enrollment status should be checked using the ``enrolled()`` method after waiting for the enrollment response.

restoreIASZoneEnroll
^^^^^^^^^^^^^^^^^^^^

Restores IAS Zone enrollment from stored attributes. This method should be called after rebooting an already enrolled device. It restores the enrollment information from flash memory, which is faster for sleepy devices compared to requesting a new enrollment.

.. code-block:: arduino

bool restoreIASZoneEnroll();

This function will return ``true`` if the enrollment was successfully restored, ``false`` otherwise. The enrollment information (zone ID and IAS CIE address) must be available in the device's stored attributes for this to succeed.

enrolled
^^^^^^^^

Checks if the device is currently enrolled in the IAS Zone.

.. code-block:: arduino

bool enrolled();

This function returns ``true`` if the device is enrolled, ``false`` otherwise. Use this method to check the enrollment status after calling ``requestIASZoneEnroll()`` or ``restoreIASZoneEnroll()``.

Example
-------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,25 @@
#endif

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

/* Zigbee contact sensor configuration */
#define CONTACT_SWITCH_ENDPOINT_NUMBER 10
#define CONTACT_SWITCH_ENDPOINT_NUMBER 1
uint8_t button = BOOT_PIN;
uint8_t sensor_pin = 4;

ZigbeeContactSwitch zbContactSwitch = ZigbeeContactSwitch(CONTACT_SWITCH_ENDPOINT_NUMBER);

/* 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, INPUT_PULLUP);
Expand All @@ -67,6 +75,31 @@ void setup() {
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.restoreIASZoneEnroll();
} else {
Serial.println("Device is factory new - first time joining network - requesting new IAS Zone enrollment");
zbContactSwitch.requestIASZoneEnroll();
}

while (!zbContactSwitch.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() {
Expand All @@ -91,6 +124,11 @@ void loop() {
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,25 @@
#endif

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

/* Zigbee vibration sensor configuration */
#define VIBRATION_SENSOR_ENDPOINT_NUMBER 10
#define VIBRATION_SENSOR_ENDPOINT_NUMBER 1
uint8_t button = BOOT_PIN;
uint8_t sensor_pin = 4;

ZigbeeVibrationSensor zbVibrationSensor = ZigbeeVibrationSensor(VIBRATION_SENSOR_ENDPOINT_NUMBER);

/* 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 + sensor
pinMode(button, INPUT_PULLUP);
pinMode(sensor_pin, INPUT);
Expand All @@ -67,6 +75,31 @@ void setup() {
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");
zbVibrationSensor.restoreIASZoneEnroll();
} else {
Serial.println("Device is factory new - first time joining network - requesting new IAS Zone enrollment");
zbVibrationSensor.requestIASZoneEnroll();
}

while (!zbVibrationSensor.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() {
Expand Down Expand Up @@ -95,6 +128,11 @@ void loop() {
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();
}
Expand Down
3 changes: 3 additions & 0 deletions libraries/Zigbee/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ setIASClientEndpoint KEYWORD2
setClosed KEYWORD2
setOpen KEYWORD2
setTilted KEYWORD2
requestIASZoneEnroll KEYWORD2
restoreIASZoneEnroll KEYWORD2
enrolled KEYWORD2

# ZigbeeVibrationSensor
setVibration KEYWORD2
Expand Down
Loading
Loading