Fixes (minor?) issues with the ZigBee sample

1. zigbee_configure_sleepy_behavior must be called before zigbee_enable - [source
docs](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/libraries/zigbee/zigbee_app_utils.html#c.zigbee_configure_sleepy_behavior)

2. zb_zdo_pim_set_long_poll_interval must be called after the network is joined - [source docs](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/zboss/3.5.2.0/group__zdo__poll__control.html#ga3aae8929b30e71c872f937771b89c768).
On top of that, the argument for the call was incorrect - it expects ms directly.

3. Removed the unecessary CONFIG_PM, seems like there's no impact in power consumption. Could it cause some weirdness?

4. Implemented CONFIG_PRST_ZB_FACTORY_RESET_DISABLED=y to fully disable factory resetting. May aid debugging.

5. Implemented multi/single channel support. Helps with battery life when scanning networks
This commit is contained in:
rbaron 2023-06-27 19:08:58 +02:00
parent 5882312a77
commit 90f99bd5b0
4 changed files with 21 additions and 13 deletions

View file

@ -7,7 +7,7 @@ config PRST_ZB_SLEEP_DURATION_SEC
config PRST_ZB_PARENT_POLL_INTERVAL_SEC
int "Interval for when b-parasite polls its parent for data in seconds."
default 60
default 10
config PRST_ZB_BUILD_DATE
string "Zigbee basic cluster build date attribute. Max 16 bytes."

View file

@ -8,9 +8,6 @@ CONFIG_GPIO=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_SEGGER_RTT_BUFFER_SIZE_UP=4096
CONFIG_PM=y
CONFIG_PM_DEVICE=y
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
@ -39,8 +36,17 @@ CONFIG_NET_IPV6_RA_RDNSS=n
CONFIG_NET_IP_ADDR_CHECK=n
CONFIG_NET_UDP=n
##
## ZigBee Channel Selection
##
# Get Zigbee to scan every channel.
CONFIG_ZIGBEE_CHANNEL_SELECTION_MODE_MULTI=y
# By default only scans channel 11 (ZigBee2MQTT default) and 15 (ZHA default).
# Comment to scan all channels - this will make pairing consume more energy.
# CONFIG_ZIGBEE_CHANNEL_MASK=0x8800
# Uncomment to set a specific channel - this will make pairing more energy efficient.
# CONFIG_ZIGBEE_CHANNEL=11
# Enable API for powering down unused RAM parts.
# https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.7.1/nrf/ug_zigbee_configuring.html#power-saving-during-sleep
@ -60,4 +66,3 @@ CONFIG_FILE_SYSTEM_LITTLEFS=y
# Factory reset method selection. Only hardware revision 2.0.0+ has button SW1. Earlier
# revisions must select a different method. See Kconfig for options.
# CONFIG_PRST_ZB_FACTORY_RESET_VIA_SW1=y
CONFIG_PRST_ZB_FACTORY_RESET_DISABLED=y

View file

@ -138,6 +138,8 @@ void zboss_signal_handler(zb_bufid_t bufid) {
k_timer_stop(&led_flashing_timer);
prst_restart_watchdog_stop();
prst_led_off();
// Update the long polling parent interval - needs to be done after joining.
zb_zdo_pim_set_long_poll_interval(1000 * CONFIG_PRST_ZB_PARENT_POLL_INTERVAL_SEC);
} else {
LOG_DBG("Steering failed. Status: %d", status);
prst_debug_counters_increment("steering_failure");
@ -244,7 +246,7 @@ void update_sensors_cb(zb_uint8_t arg) {
}
void log_counter(const char *counter_name, prst_debug_counter_t value) {
LOG_INF("- %s: %d", counter_name, value);
LOG_DBG("- %s: %d", counter_name, value);
}
int main(void) {
@ -254,9 +256,12 @@ int main(void) {
RET_IF_ERR(prst_flash_fs_init());
RET_IF_ERR(prst_debug_counters_init());
// Initialize sensors - quickly put them into low power mode.
RET_IF_ERR(prst_sensors_read_all(&sensors));
prst_debug_counters_increment("boot");
LOG_INF("Dumping debug counters:");
LOG_DBG("Dumping debug counters:");
prst_debug_counters_get_all(log_counter);
RET_IF_ERR(prst_zb_factory_reset_check());
@ -265,19 +270,17 @@ int main(void) {
ZB_AF_REGISTER_DEVICE_CTX(&app_template_ctx);
// Kick-off the recurring task to read sensors and update ZigBee clusters.
update_sensors_cb(/*arg=*/0);
zb_zdo_pim_set_long_poll_interval(
ZB_TIME_ONE_SECOND * CONFIG_PRST_ZB_PARENT_POLL_INTERVAL_SEC);
power_down_unused_ram();
RET_IF_ERR(prst_led_flash(2));
k_msleep(100);
ZB_AF_SET_IDENTIFY_NOTIFICATION_HANDLER(PRST_ZIGBEE_ENDPOINT, identify_cb);
zigbee_enable();
zigbee_configure_sleepy_behavior(/*enable=*/true);
power_down_unused_ram();
zigbee_enable();
prst_debug_counters_increment("main_finish");

View file

@ -11,7 +11,7 @@ LOG_MODULE_REGISTER(restart_handler, CONFIG_LOG_DEFAULT_LEVEL);
void callback_work_handler(struct k_work *work) {
LOG_INF("Running restart callback_work_handler.");
prst_debug_counters_increment("steering_watchdog_restart");
zb_reset(0);
user_input_indicate();
}
K_WORK_DEFINE(callback_work, callback_work_handler);