From 5882312a77b3ca83a8be165b20278529745cfd61 Mon Sep 17 00:00:00 2001 From: rbaron Date: Sun, 18 Jun 2023 14:37:25 +0200 Subject: [PATCH 1/8] [zb] Debugging changes: - Disables double reset - Fully reset with zb_reset() on reset watchdog instead of user_input_indicate() - Debug counters before/after sensors read --- code/nrf-connect/samples/zigbee/Kconfig | 3 +++ code/nrf-connect/samples/zigbee/prj.conf | 1 + code/nrf-connect/samples/zigbee/src/debug_counters.c | 1 + code/nrf-connect/samples/zigbee/src/factory_reset.c | 3 ++- code/nrf-connect/samples/zigbee/src/main.c | 2 ++ code/nrf-connect/samples/zigbee/src/restart_handler.c | 3 +-- 6 files changed, 10 insertions(+), 3 deletions(-) diff --git a/code/nrf-connect/samples/zigbee/Kconfig b/code/nrf-connect/samples/zigbee/Kconfig index 1092ced..2e86690 100644 --- a/code/nrf-connect/samples/zigbee/Kconfig +++ b/code/nrf-connect/samples/zigbee/Kconfig @@ -34,6 +34,9 @@ config PRST_ZB_FACTORY_RESET_VIA_RESET_PIN config PRST_ZB_FACTORY_RESET_VIA_SW1 bool "Resetting while pressing and holding SW1 for 5 seconds will factory reset the device. Only available on v2.0.0+ hardware revisions." +config PRST_ZB_FACTORY_RESET_DISABLED + bool "No factory reset procedure." + endchoice # PRST_ZB_FACTORY_RESET_METHOD config PRST_ZB_RESTART_WATCHDOG_TIMEOUT_SEC diff --git a/code/nrf-connect/samples/zigbee/prj.conf b/code/nrf-connect/samples/zigbee/prj.conf index e5d8f1b..53b6508 100644 --- a/code/nrf-connect/samples/zigbee/prj.conf +++ b/code/nrf-connect/samples/zigbee/prj.conf @@ -60,3 +60,4 @@ 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 \ No newline at end of file diff --git a/code/nrf-connect/samples/zigbee/src/debug_counters.c b/code/nrf-connect/samples/zigbee/src/debug_counters.c index ede174c..72f006a 100644 --- a/code/nrf-connect/samples/zigbee/src/debug_counters.c +++ b/code/nrf-connect/samples/zigbee/src/debug_counters.c @@ -65,6 +65,7 @@ int prst_debug_counters_increment(const char* counter_name) { if (written != sizeof(value)) { LOG_ERR("fs_write returned %d, expected %d", written, sizeof(value)); } + RET_IF_ERR(fs_sync(&file)); return fs_close(&file); } diff --git a/code/nrf-connect/samples/zigbee/src/factory_reset.c b/code/nrf-connect/samples/zigbee/src/factory_reset.c index 7ada82b..5b64cdc 100644 --- a/code/nrf-connect/samples/zigbee/src/factory_reset.c +++ b/code/nrf-connect/samples/zigbee/src/factory_reset.c @@ -66,6 +66,7 @@ int prst_zb_factory_reset_check() { LOG_DBG("SW1 pressed. Scheduling timer"); k_timer_start(&sw1_factory_reset_check_timer, K_SECONDS(5), K_NO_WAIT); } -#endif +#elif CONFIG_PRST_ZB_FACTORY_RESET_DISABLED return 0; +#endif // CONFIG_PRST_ZB_FACTORY_RESET_VIA_RESET_PIN } \ No newline at end of file diff --git a/code/nrf-connect/samples/zigbee/src/main.c b/code/nrf-connect/samples/zigbee/src/main.c index b1c1c42..7fb52c4 100644 --- a/code/nrf-connect/samples/zigbee/src/main.c +++ b/code/nrf-connect/samples/zigbee/src/main.c @@ -198,11 +198,13 @@ void update_sensors_cb(zb_uint8_t arg) { /*param=*/0, ZB_TIME_ONE_SECOND * CONFIG_PRST_ZB_SLEEP_DURATION_SEC); + prst_debug_counters_increment("sensors_read_before"); if (prst_sensors_read_all(&sensors)) { prst_debug_counters_increment("sensors_read_error"); LOG_ERR("Unable to read sensors"); return; } + prst_debug_counters_increment("sensors_read_after"); // Battery voltage in units of 100 mV. uint8_t batt_voltage = sensors.batt.adc_read.millivolts / 100; diff --git a/code/nrf-connect/samples/zigbee/src/restart_handler.c b/code/nrf-connect/samples/zigbee/src/restart_handler.c index 0a23df3..a504bf6 100644 --- a/code/nrf-connect/samples/zigbee/src/restart_handler.c +++ b/code/nrf-connect/samples/zigbee/src/restart_handler.c @@ -11,8 +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"); - // If the device is not commissioned, the rejoin procedure is started. - user_input_indicate(); + zb_reset(0); } K_WORK_DEFINE(callback_work, callback_work_handler); From 90f99bd5b074c7646f0a7f17a3a00adcc7cb2617 Mon Sep 17 00:00:00 2001 From: rbaron Date: Tue, 27 Jun 2023 19:08:58 +0200 Subject: [PATCH 2/8] 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 --- code/nrf-connect/samples/zigbee/Kconfig | 2 +- code/nrf-connect/samples/zigbee/prj.conf | 13 +++++++++---- code/nrf-connect/samples/zigbee/src/main.c | 17 ++++++++++------- .../samples/zigbee/src/restart_handler.c | 2 +- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/code/nrf-connect/samples/zigbee/Kconfig b/code/nrf-connect/samples/zigbee/Kconfig index 2e86690..6fbb42a 100644 --- a/code/nrf-connect/samples/zigbee/Kconfig +++ b/code/nrf-connect/samples/zigbee/Kconfig @@ -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." diff --git a/code/nrf-connect/samples/zigbee/prj.conf b/code/nrf-connect/samples/zigbee/prj.conf index 53b6508..5583e41 100644 --- a/code/nrf-connect/samples/zigbee/prj.conf +++ b/code/nrf-connect/samples/zigbee/prj.conf @@ -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 \ No newline at end of file diff --git a/code/nrf-connect/samples/zigbee/src/main.c b/code/nrf-connect/samples/zigbee/src/main.c index 7fb52c4..2899be9 100644 --- a/code/nrf-connect/samples/zigbee/src/main.c +++ b/code/nrf-connect/samples/zigbee/src/main.c @@ -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"); diff --git a/code/nrf-connect/samples/zigbee/src/restart_handler.c b/code/nrf-connect/samples/zigbee/src/restart_handler.c index a504bf6..4959ae9 100644 --- a/code/nrf-connect/samples/zigbee/src/restart_handler.c +++ b/code/nrf-connect/samples/zigbee/src/restart_handler.c @@ -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); From 62a99cc71649ce017356d65fca07072c5e5c4af5 Mon Sep 17 00:00:00 2001 From: rbaron Date: Tue, 27 Jun 2023 21:38:42 +0200 Subject: [PATCH 3/8] Reintroduced accidentally deleted comment --- code/nrf-connect/samples/zigbee/src/restart_handler.c | 1 + 1 file changed, 1 insertion(+) diff --git a/code/nrf-connect/samples/zigbee/src/restart_handler.c b/code/nrf-connect/samples/zigbee/src/restart_handler.c index 4959ae9..0a23df3 100644 --- a/code/nrf-connect/samples/zigbee/src/restart_handler.c +++ b/code/nrf-connect/samples/zigbee/src/restart_handler.c @@ -11,6 +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"); + // If the device is not commissioned, the rejoin procedure is started. user_input_indicate(); } From 46feb542cc06b933e22438bb1a4274f4c1422dba Mon Sep 17 00:00:00 2001 From: rbaron Date: Wed, 28 Jun 2023 21:47:33 +0200 Subject: [PATCH 4/8] More fixes to the ZigBee sample MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 🚨 Missing `break` statements in `zboss_signal_handler` - Makes `zboss_signal_handler` return fast. According to the [docs](https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.thread_zigbee.v2.0.0%2Fgroup__zb__comm__signals.html): "Signal processing should not do long operations synchronously". I removed calls to `prst_flash_led` (essentially a huge sync delay) and `debug_counters_increment`, which were blocking. I'll try migrating the debug_counters to non-blocking separately - Main sensor reading task is started for the first time upon the `ZB_ZDO_SIGNAL_SKIP_STARTUP` signal. This is what the [weather_station sample](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/applications/zigbee_weather_station/README.html) does. It should have no functional difference, but there's [some special handling for alarms started from the ZigBee task](https://github.com/nrfconnect/sdk-nrf/blob/0469247dc45b64f5657270ee02254ec5de692811/subsys/zigbee/osif/zb_nrf_platform.c#L426) --- code/nrf-connect/samples/zigbee/src/main.c | 151 +++++++++++---------- 1 file changed, 76 insertions(+), 75 deletions(-) diff --git a/code/nrf-connect/samples/zigbee/src/main.c b/code/nrf-connect/samples/zigbee/src/main.c index 2899be9..ea7b58b 100644 --- a/code/nrf-connect/samples/zigbee/src/main.c +++ b/code/nrf-connect/samples/zigbee/src/main.c @@ -122,83 +122,13 @@ void identify_cb(zb_bufid_t bufid) { prst_led_flash(15); } -void zboss_signal_handler(zb_bufid_t bufid) { - // See zigbee_default_signal_handler() for all available signals. - zb_zdo_app_signal_hdr_t *sig_hndler = NULL; - zb_zdo_app_signal_type_t sig = zb_get_app_signal(bufid, /*sg_p=*/&sig_hndler); - zb_ret_t status = ZB_GET_APP_SIGNAL_STATUS(bufid); - switch (sig) { - case ZB_BDB_SIGNAL_STEERING: // New network. - case ZB_BDB_SIGNAL_DEVICE_REBOOT: { // Previously joined network. - LOG_DBG("Steering complete. Status: %d", status); - if (status == RET_OK) { - LOG_DBG("Steering successful. Status: %d", status); - prst_debug_counters_increment("steering_success"); - prst_led_flash(/*times=*/3); - 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"); - prst_led_flash(/*times=*/7); - prst_restart_watchdog_start(); - k_timer_stop(&led_flashing_timer); // Power saving - prst_led_off(); - } - } - case ZB_BDB_SIGNAL_DEVICE_FIRST_START: - joining_signal_received = true; - break; - case ZB_ZDO_SIGNAL_LEAVE: - if (status == RET_OK) { - k_timer_start(&led_flashing_timer, K_NO_WAIT, K_SECONDS(1)); - zb_zdo_signal_leave_params_t *leave_params = ZB_ZDO_SIGNAL_GET_PARAMS(sig_hndler, zb_zdo_signal_leave_params_t); - LOG_INF("Network left (leave type: %d)", leave_params->leave_type); - - /* Set joining_signal_received to false so broken rejoin procedure can be detected correctly. */ - if (leave_params->leave_type == ZB_NWK_LEAVE_TYPE_REJOIN) { - joining_signal_received = false; - } - } - case ZB_ZDO_SIGNAL_SKIP_STARTUP: { - stack_initialised = true; - LOG_DBG("Started zigbee stack and waiting for connection to network."); - k_timer_start(&led_flashing_timer, K_NO_WAIT, K_SECONDS(1)); - break; - } - case ZB_NLME_STATUS_INDICATION: { - zb_zdo_signal_nlme_status_indication_params_t *nlme_status_ind = - ZB_ZDO_SIGNAL_GET_PARAMS(sig_hndler, zb_zdo_signal_nlme_status_indication_params_t); - if (nlme_status_ind->nlme_status.status == ZB_NWK_COMMAND_STATUS_PARENT_LINK_FAILURE) { - /* Check for broken rejoin procedure and restart the device to recover. - This implements Nordic's suggested workaround for errata KRKNWK-12017, which effects - the recent nRF Connect SDK (v1.8.0 - v2.3.0 at time of writing). - For details see: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/known_issues.html?v=v2-3-0 - */ - if (stack_initialised && !joining_signal_received) { - prst_debug_counters_increment("krknwk_12017_reset"); - zb_reset(0); - } - } - break; - } - } - - ZB_ERROR_CHECK(zigbee_default_signal_handler(bufid)); - if (bufid) { - zb_buf_free(bufid); - } -} - void update_sensors_cb(zb_uint8_t arg) { LOG_INF("Updating sensors"); + // Reschedule the same callback. ZB_SCHEDULE_APP_ALARM(update_sensors_cb, /*param=*/0, - ZB_TIME_ONE_SECOND * CONFIG_PRST_ZB_SLEEP_DURATION_SEC); + ZB_MILLISECONDS_TO_BEACON_INTERVAL(1000 * CONFIG_PRST_ZB_SLEEP_DURATION_SEC)); prst_debug_counters_increment("sensors_read_before"); if (prst_sensors_read_all(&sensors)) { @@ -245,6 +175,80 @@ void update_sensors_cb(zb_uint8_t arg) { &log_lux); } +void zboss_signal_handler(zb_bufid_t bufid) { + // See zigbee_default_signal_handler() for all available signals. + zb_zdo_app_signal_hdr_t *sig_hndler = NULL; + zb_zdo_app_signal_type_t sig = zb_get_app_signal(bufid, /*sg_p=*/&sig_hndler); + zb_ret_t status = ZB_GET_APP_SIGNAL_STATUS(bufid); + switch (sig) { + case ZB_BDB_SIGNAL_STEERING: // New network. + case ZB_BDB_SIGNAL_DEVICE_REBOOT: { // Previously joined network. + LOG_DBG("Steering complete. Status: %d", status); + if (status == RET_OK) { + LOG_DBG("Steering successful. Status: %d", status); + k_timer_stop(&led_flashing_timer); + prst_led_off(); + prst_restart_watchdog_stop(); + // 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_restart_watchdog_start(); + // Power saving. + k_timer_stop(&led_flashing_timer); + } + joining_signal_received = true; + break; + } + case ZB_BDB_SIGNAL_DEVICE_FIRST_START: + joining_signal_received = true; + break; + case ZB_ZDO_SIGNAL_LEAVE: + if (status == RET_OK) { + k_timer_start(&led_flashing_timer, K_NO_WAIT, K_SECONDS(1)); + zb_zdo_signal_leave_params_t *leave_params = ZB_ZDO_SIGNAL_GET_PARAMS(sig_hndler, zb_zdo_signal_leave_params_t); + LOG_DBG("Network left (leave type: %d)", leave_params->leave_type); + + /* Set joining_signal_received to false so broken rejoin procedure can be detected correctly. */ + if (leave_params->leave_type == ZB_NWK_LEAVE_TYPE_REJOIN) { + joining_signal_received = false; + } + } + break; + case ZB_ZDO_SIGNAL_SKIP_STARTUP: { + stack_initialised = true; + LOG_DBG("Started zigbee stack and waiting for connection to network."); + k_timer_start(&led_flashing_timer, K_NO_WAIT, K_SECONDS(1)); + + // Kick off main sensor update task. + ZB_SCHEDULE_APP_ALARM(update_sensors_cb, + /*param=*/0, + ZB_MILLISECONDS_TO_BEACON_INTERVAL(1000)); + break; + } + case ZB_NLME_STATUS_INDICATION: { + zb_zdo_signal_nlme_status_indication_params_t *nlme_status_ind = + ZB_ZDO_SIGNAL_GET_PARAMS(sig_hndler, zb_zdo_signal_nlme_status_indication_params_t); + if (nlme_status_ind->nlme_status.status == ZB_NWK_COMMAND_STATUS_PARENT_LINK_FAILURE) { + /* Check for broken rejoin procedure and restart the device to recover. + This implements Nordic's suggested workaround for errata KRKNWK-12017, which effects + the recent nRF Connect SDK (v1.8.0 - v2.3.0 at time of writing). + For details see: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/known_issues.html?v=v2-3-0 + */ + if (stack_initialised && !joining_signal_received) { + zb_reset(0); + } + } + break; + } + } + + ZB_ERROR_CHECK(zigbee_default_signal_handler(bufid)); + if (bufid) { + zb_buf_free(bufid); + } +} + void log_counter(const char *counter_name, prst_debug_counter_t value) { LOG_DBG("- %s: %d", counter_name, value); } @@ -270,9 +274,6 @@ 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); - RET_IF_ERR(prst_led_flash(2)); k_msleep(100); From 7f42dd0c009e929abdeef5b07eb25627ed7ed5c7 Mon Sep 17 00:00:00 2001 From: rbaron Date: Wed, 28 Jun 2023 22:08:18 +0200 Subject: [PATCH 5/8] Add missing prst_led_off after stopping LED flashing timer --- code/nrf-connect/samples/zigbee/src/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/code/nrf-connect/samples/zigbee/src/main.c b/code/nrf-connect/samples/zigbee/src/main.c index ea7b58b..2077004 100644 --- a/code/nrf-connect/samples/zigbee/src/main.c +++ b/code/nrf-connect/samples/zigbee/src/main.c @@ -196,6 +196,7 @@ void zboss_signal_handler(zb_bufid_t bufid) { prst_restart_watchdog_start(); // Power saving. k_timer_stop(&led_flashing_timer); + prst_led_off(); } joining_signal_received = true; break; From c86f04e4066f528f11d8021a490df28c7c7d7d3e Mon Sep 17 00:00:00 2001 From: rbaron Date: Wed, 28 Jun 2023 22:22:34 +0200 Subject: [PATCH 6/8] Nuclear reset option if recurring sensor task cannot be rescheduled Famous last words: "this should never happen" --- code/nrf-connect/samples/zigbee/src/main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/code/nrf-connect/samples/zigbee/src/main.c b/code/nrf-connect/samples/zigbee/src/main.c index 2077004..3e4432c 100644 --- a/code/nrf-connect/samples/zigbee/src/main.c +++ b/code/nrf-connect/samples/zigbee/src/main.c @@ -126,9 +126,14 @@ void update_sensors_cb(zb_uint8_t arg) { LOG_INF("Updating sensors"); // Reschedule the same callback. - ZB_SCHEDULE_APP_ALARM(update_sensors_cb, - /*param=*/0, - ZB_MILLISECONDS_TO_BEACON_INTERVAL(1000 * CONFIG_PRST_ZB_SLEEP_DURATION_SEC)); + zb_ret_t ret = ZB_SCHEDULE_APP_ALARM( + update_sensors_cb, + /*param=*/0, + ZB_MILLISECONDS_TO_BEACON_INTERVAL(1000 * CONFIG_PRST_ZB_SLEEP_DURATION_SEC)); + if (ret != RET_OK) { + prst_debug_counters_increment("sens_cb_schedule_err"); + zb_reset(0); + } prst_debug_counters_increment("sensors_read_before"); if (prst_sensors_read_all(&sensors)) { From 37aff683adbe974da390ad1d6c92e477bae02229 Mon Sep 17 00:00:00 2001 From: rbaron Date: Wed, 28 Jun 2023 22:25:32 +0200 Subject: [PATCH 7/8] LOG_INF -> LOG_DBG --- code/nrf-connect/samples/zigbee/src/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/nrf-connect/samples/zigbee/src/main.c b/code/nrf-connect/samples/zigbee/src/main.c index 3e4432c..20cbe9f 100644 --- a/code/nrf-connect/samples/zigbee/src/main.c +++ b/code/nrf-connect/samples/zigbee/src/main.c @@ -123,7 +123,7 @@ void identify_cb(zb_bufid_t bufid) { } void update_sensors_cb(zb_uint8_t arg) { - LOG_INF("Updating sensors"); + LOG_DBG("Updating sensors"); // Reschedule the same callback. zb_ret_t ret = ZB_SCHEDULE_APP_ALARM( @@ -256,7 +256,7 @@ void zboss_signal_handler(zb_bufid_t bufid) { } void log_counter(const char *counter_name, prst_debug_counter_t value) { - LOG_DBG("- %s: %d", counter_name, value); + LOG_INF("- %s: %d", counter_name, value); } int main(void) { @@ -271,7 +271,7 @@ int main(void) { prst_debug_counters_increment("boot"); - LOG_DBG("Dumping debug counters:"); + LOG_INF("Dumping debug counters:"); prst_debug_counters_get_all(log_counter); RET_IF_ERR(prst_zb_factory_reset_check()); From bc3d834b20972476246cb8a6efab0c3ffa3c3bf7 Mon Sep 17 00:00:00 2001 From: rbaron Date: Sat, 1 Jul 2023 08:26:21 +0200 Subject: [PATCH 8/8] Make it mandatory to select a factory reset method ... in order to avoid unhappy surprises --- code/nrf-connect/samples/zigbee/src/factory_reset.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/nrf-connect/samples/zigbee/src/factory_reset.c b/code/nrf-connect/samples/zigbee/src/factory_reset.c index 5b64cdc..3495799 100644 --- a/code/nrf-connect/samples/zigbee/src/factory_reset.c +++ b/code/nrf-connect/samples/zigbee/src/factory_reset.c @@ -66,7 +66,10 @@ int prst_zb_factory_reset_check() { LOG_DBG("SW1 pressed. Scheduling timer"); k_timer_start(&sw1_factory_reset_check_timer, K_SECONDS(5), K_NO_WAIT); } + return 0; #elif CONFIG_PRST_ZB_FACTORY_RESET_DISABLED return 0; +#else +#error "No factory reset method selected -- explicitly select CONFIG_PRST_ZB_FACTORY_RESET_DISABLED=y to disable it" #endif // CONFIG_PRST_ZB_FACTORY_RESET_VIA_RESET_PIN } \ No newline at end of file