From ba786eb2981bf2bc23a8d06c196e76b5a58b09cc Mon Sep 17 00:00:00 2001 From: Ole Odendahl Date: Tue, 11 Apr 2023 12:46:46 +0200 Subject: [PATCH 1/9] Moving steering successful flashing to success if branch. --- code/nrf-connect/samples/zigbee/src/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/nrf-connect/samples/zigbee/src/main.c b/code/nrf-connect/samples/zigbee/src/main.c index 12b428d..a68d9a4 100644 --- a/code/nrf-connect/samples/zigbee/src/main.c +++ b/code/nrf-connect/samples/zigbee/src/main.c @@ -128,8 +128,9 @@ void zboss_signal_handler(zb_bufid_t bufid) { case ZB_BDB_SIGNAL_STEERING: // New network. case ZB_BDB_SIGNAL_DEVICE_REBOOT: { // Previously joined network. LOG_DBG("Steering complete. Status: %d", status); - prst_led_flash(/*times=*/3); if (status == RET_OK) { + LOG_DBG("Steering successful. Status: %d", status); + prst_led_flash(/*times=*/3); k_timer_stop(&led_flashing_timer); prst_led_off(); } From 69c0ed3694727e79f9c84c0b4577bdb873f63858 Mon Sep 17 00:00:00 2001 From: Ole Odendahl Date: Tue, 11 Apr 2023 12:50:38 +0200 Subject: [PATCH 2/9] Separated two signals for better debugging and possibly different handling. --- code/nrf-connect/samples/zigbee/src/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/nrf-connect/samples/zigbee/src/main.c b/code/nrf-connect/samples/zigbee/src/main.c index a68d9a4..0f3f404 100644 --- a/code/nrf-connect/samples/zigbee/src/main.c +++ b/code/nrf-connect/samples/zigbee/src/main.c @@ -140,6 +140,7 @@ void zboss_signal_handler(zb_bufid_t bufid) { 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); @@ -150,7 +151,7 @@ void zboss_signal_handler(zb_bufid_t bufid) { } case ZB_ZDO_SIGNAL_SKIP_STARTUP: { stack_initialised = true; - LOG_DBG("Will restart flashing"); + LOG_DBG("Started zigbee stack and waiting for connection to network."); k_timer_start(&led_flashing_timer, K_NO_WAIT, K_SECONDS(1)); break; } From 727138415eafe13c3fea27ea0b9d7e314581e1cd Mon Sep 17 00:00:00 2001 From: Ole Odendahl Date: Tue, 11 Apr 2023 12:51:58 +0200 Subject: [PATCH 3/9] Added restart handler module. --- code/nrf-connect/samples/zigbee/CMakeLists.txt | 3 ++- .../samples/zigbee/src/restart_handler.c | 14 ++++++++++++++ .../samples/zigbee/src/restart_handler.h | 6 ++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 code/nrf-connect/samples/zigbee/src/restart_handler.c create mode 100644 code/nrf-connect/samples/zigbee/src/restart_handler.h diff --git a/code/nrf-connect/samples/zigbee/CMakeLists.txt b/code/nrf-connect/samples/zigbee/CMakeLists.txt index d000625..9fac7f5 100644 --- a/code/nrf-connect/samples/zigbee/CMakeLists.txt +++ b/code/nrf-connect/samples/zigbee/CMakeLists.txt @@ -16,8 +16,9 @@ target_sources(app PRIVATE src/factory_reset.c src/prst_zb_attrs.c src/prst_zb_soil_moisture_defs.c + src/restart_handler.c ) add_subdirectory(../../prstlib prstlib) target_include_directories(app PRIVATE ../../prstlib/include) -target_link_libraries(app PUBLIC prstlib) \ No newline at end of file +target_link_libraries(app PUBLIC prstlib) diff --git a/code/nrf-connect/samples/zigbee/src/restart_handler.c b/code/nrf-connect/samples/zigbee/src/restart_handler.c new file mode 100644 index 0000000..b6f6430 --- /dev/null +++ b/code/nrf-connect/samples/zigbee/src/restart_handler.c @@ -0,0 +1,14 @@ +#include +#include +#include + +#include "restart_handler.h" + +LOG_MODULE_REGISTER(restart_handler, CONFIG_LOG_DEFAULT_LEVEL); + +static void restart_network_steering_cb(struct k_timer *timer) { + LOG_DBG("Restart handler expired. Restarting network steering."); + user_input_indicate(); +} + +K_TIMER_DEFINE(restart_timer, restart_network_steering_cb, NULL); diff --git a/code/nrf-connect/samples/zigbee/src/restart_handler.h b/code/nrf-connect/samples/zigbee/src/restart_handler.h new file mode 100644 index 0000000..911470f --- /dev/null +++ b/code/nrf-connect/samples/zigbee/src/restart_handler.h @@ -0,0 +1,6 @@ +#ifndef _PRST_ZB_RESTART_HANDLER_H_ +#define _PRST_ZB_RESTART_HANDLER_H_ + +static const int PRST_ZB_RESET_TIMEOUT = 5 * 60; + +#endif // _PRST_ZB_RESTART_HANDLER_H_ From c52d5f7a488ed463a6ca62aa9ab9f048f5faa81c Mon Sep 17 00:00:00 2001 From: Ole Odendahl Date: Tue, 11 Apr 2023 12:53:59 +0200 Subject: [PATCH 4/9] Added steering restart handler to signal handler steering branch. Made the device flash less frequently to save power on unexpected connection drops. --- code/nrf-connect/samples/zigbee/src/main.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/code/nrf-connect/samples/zigbee/src/main.c b/code/nrf-connect/samples/zigbee/src/main.c index 0f3f404..ddaa000 100644 --- a/code/nrf-connect/samples/zigbee/src/main.c +++ b/code/nrf-connect/samples/zigbee/src/main.c @@ -19,6 +19,7 @@ #include "prst_zb_attrs.h" #include "prst_zb_endpoint_defs.h" #include "prst_zb_soil_moisture_defs.h" +#include "restart_handler.h" LOG_MODULE_REGISTER(app, CONFIG_LOG_DEFAULT_LEVEL); @@ -35,6 +36,8 @@ static void led_flashing_cb(struct k_timer *timer) { K_TIMER_DEFINE(led_flashing_timer, led_flashing_cb, /*stop_fn=*/NULL); +extern struct k_timer restart_timer; + ZB_ZCL_DECLARE_IDENTIFY_ATTRIB_LIST( identify_attr_list, &dev_ctx.identify_attr.identify_time); @@ -132,7 +135,14 @@ void zboss_signal_handler(zb_bufid_t bufid) { LOG_DBG("Steering successful. Status: %d", status); prst_led_flash(/*times=*/3); k_timer_stop(&led_flashing_timer); + k_timer_stop(&restart_timer); prst_led_off(); + } else { + LOG_DBG("Steering failed. Status: %d", status); + prst_led_flash(7); + k_timer_start(&restart_timer, K_SECONDS(PRST_ZB_RESET_TIMEOUT), K_MSEC(0)); + k_timer_stop(&led_flashing_timer); // Power saving + prst_led_off(); } } case ZB_BDB_SIGNAL_DEVICE_FIRST_START: From 6f10dc9e19a8f00f44cae1b155b12c7e860ea94b Mon Sep 17 00:00:00 2001 From: Ole Odendahl Date: Wed, 31 May 2023 12:47:40 +0200 Subject: [PATCH 5/9] Fixed clang format. --- code/nrf-connect/samples/zigbee/src/main.c | 4 ++-- .../nrf-connect/samples/zigbee/src/restart_handler.c | 12 ++++++------ .../nrf-connect/samples/zigbee/src/restart_handler.h | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/code/nrf-connect/samples/zigbee/src/main.c b/code/nrf-connect/samples/zigbee/src/main.c index ddaa000..8b8537b 100644 --- a/code/nrf-connect/samples/zigbee/src/main.c +++ b/code/nrf-connect/samples/zigbee/src/main.c @@ -141,8 +141,8 @@ void zboss_signal_handler(zb_bufid_t bufid) { LOG_DBG("Steering failed. Status: %d", status); prst_led_flash(7); k_timer_start(&restart_timer, K_SECONDS(PRST_ZB_RESET_TIMEOUT), K_MSEC(0)); - k_timer_stop(&led_flashing_timer); // Power saving - prst_led_off(); + k_timer_stop(&led_flashing_timer); // Power saving + prst_led_off(); } } case ZB_BDB_SIGNAL_DEVICE_FIRST_START: diff --git a/code/nrf-connect/samples/zigbee/src/restart_handler.c b/code/nrf-connect/samples/zigbee/src/restart_handler.c index b6f6430..961fbbe 100644 --- a/code/nrf-connect/samples/zigbee/src/restart_handler.c +++ b/code/nrf-connect/samples/zigbee/src/restart_handler.c @@ -1,14 +1,14 @@ -#include -#include -#include - #include "restart_handler.h" +#include +#include +#include + LOG_MODULE_REGISTER(restart_handler, CONFIG_LOG_DEFAULT_LEVEL); static void restart_network_steering_cb(struct k_timer *timer) { - LOG_DBG("Restart handler expired. Restarting network steering."); - user_input_indicate(); + LOG_DBG("Restart handler expired. Restarting network steering."); + user_input_indicate(); } K_TIMER_DEFINE(restart_timer, restart_network_steering_cb, NULL); diff --git a/code/nrf-connect/samples/zigbee/src/restart_handler.h b/code/nrf-connect/samples/zigbee/src/restart_handler.h index 911470f..a3f2e6a 100644 --- a/code/nrf-connect/samples/zigbee/src/restart_handler.h +++ b/code/nrf-connect/samples/zigbee/src/restart_handler.h @@ -3,4 +3,4 @@ static const int PRST_ZB_RESET_TIMEOUT = 5 * 60; -#endif // _PRST_ZB_RESTART_HANDLER_H_ +#endif // _PRST_ZB_RESTART_HANDLER_H_ From 9285a6bc41c474ed9a113007541da31a83f39afc Mon Sep 17 00:00:00 2001 From: Ole Odendahl Date: Fri, 2 Jun 2023 11:15:46 +0200 Subject: [PATCH 6/9] Added comment to describe nordic funny function name. --- 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 961fbbe..8d2e9dc 100644 --- a/code/nrf-connect/samples/zigbee/src/restart_handler.c +++ b/code/nrf-connect/samples/zigbee/src/restart_handler.c @@ -8,6 +8,7 @@ LOG_MODULE_REGISTER(restart_handler, CONFIG_LOG_DEFAULT_LEVEL); static void restart_network_steering_cb(struct k_timer *timer) { LOG_DBG("Restart handler expired. Restarting network steering."); + // If the device is not commissioned, the rejoin procedure is started. user_input_indicate(); } From 5cede82dc5874c4aeac053dae1fdb69e51a2f217 Mon Sep 17 00:00:00 2001 From: Ole Odendahl Date: Fri, 2 Jun 2023 11:16:49 +0200 Subject: [PATCH 7/9] Changing api of restart handler to only expose needed functions. This encapsulates the low level timer logic from the caller. --- code/nrf-connect/samples/zigbee/src/restart_handler.c | 8 ++++++++ code/nrf-connect/samples/zigbee/src/restart_handler.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/code/nrf-connect/samples/zigbee/src/restart_handler.c b/code/nrf-connect/samples/zigbee/src/restart_handler.c index 8d2e9dc..85c4c6a 100644 --- a/code/nrf-connect/samples/zigbee/src/restart_handler.c +++ b/code/nrf-connect/samples/zigbee/src/restart_handler.c @@ -13,3 +13,11 @@ static void restart_network_steering_cb(struct k_timer *timer) { } K_TIMER_DEFINE(restart_timer, restart_network_steering_cb, NULL); + +static void prst_restart_watchdog_start() { + k_timer_start(&restart_timer, K_SECONDS(PRST_ZB_RESET_TIMEOUT), K_MSEC(0)); +} + +static void prst_restart_watchdog_stop() { + k_timer_stop(&restart_timer); +} diff --git a/code/nrf-connect/samples/zigbee/src/restart_handler.h b/code/nrf-connect/samples/zigbee/src/restart_handler.h index a3f2e6a..9c4e6a5 100644 --- a/code/nrf-connect/samples/zigbee/src/restart_handler.h +++ b/code/nrf-connect/samples/zigbee/src/restart_handler.h @@ -3,4 +3,7 @@ static const int PRST_ZB_RESET_TIMEOUT = 5 * 60; +static void prst_restart_watchdog_start; +static void prst_restart_watchdog_stop; + #endif // _PRST_ZB_RESTART_HANDLER_H_ From ce748c47594885df5631d05e6b058a858bffe59c Mon Sep 17 00:00:00 2001 From: Ole Odendahl Date: Fri, 2 Jun 2023 11:31:58 +0200 Subject: [PATCH 8/9] Added restart watchdog timeout to Kconfig. --- code/nrf-connect/samples/zigbee/Kconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/code/nrf-connect/samples/zigbee/Kconfig b/code/nrf-connect/samples/zigbee/Kconfig index a06d770..5346f11 100644 --- a/code/nrf-connect/samples/zigbee/Kconfig +++ b/code/nrf-connect/samples/zigbee/Kconfig @@ -32,3 +32,7 @@ config PRST_ZB_FACTORY_RESET_VIA_RESET_PIN bool "Resetting via the reset pin will factory reset the device. Power cycling through battery replacement will not." endchoice # PRST_ZB_FACTORY_RESET_METHOD + +config PRST_ZB_RESTART_WATCHDOG_TIMEOUT_SEC + int "Duration after the device will restart the rejoin procedure if a network has not been successfully joined." + default 3600 From 3aa33cdd89e2f3737bd144f8815623f77467367a Mon Sep 17 00:00:00 2001 From: Ole Odendahl Date: Fri, 2 Jun 2023 11:39:52 +0200 Subject: [PATCH 9/9] Fixed api of restart watchdog. --- code/nrf-connect/samples/zigbee/src/main.c | 6 ++---- code/nrf-connect/samples/zigbee/src/restart_handler.c | 6 +++--- code/nrf-connect/samples/zigbee/src/restart_handler.h | 6 ++---- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/code/nrf-connect/samples/zigbee/src/main.c b/code/nrf-connect/samples/zigbee/src/main.c index 8b8537b..16ee57b 100644 --- a/code/nrf-connect/samples/zigbee/src/main.c +++ b/code/nrf-connect/samples/zigbee/src/main.c @@ -36,8 +36,6 @@ static void led_flashing_cb(struct k_timer *timer) { K_TIMER_DEFINE(led_flashing_timer, led_flashing_cb, /*stop_fn=*/NULL); -extern struct k_timer restart_timer; - ZB_ZCL_DECLARE_IDENTIFY_ATTRIB_LIST( identify_attr_list, &dev_ctx.identify_attr.identify_time); @@ -135,12 +133,12 @@ void zboss_signal_handler(zb_bufid_t bufid) { LOG_DBG("Steering successful. Status: %d", status); prst_led_flash(/*times=*/3); k_timer_stop(&led_flashing_timer); - k_timer_stop(&restart_timer); + prst_restart_watchdog_stop(); prst_led_off(); } else { LOG_DBG("Steering failed. Status: %d", status); prst_led_flash(7); - k_timer_start(&restart_timer, K_SECONDS(PRST_ZB_RESET_TIMEOUT), K_MSEC(0)); + prst_restart_watchdog_start(); k_timer_stop(&led_flashing_timer); // Power saving prst_led_off(); } diff --git a/code/nrf-connect/samples/zigbee/src/restart_handler.c b/code/nrf-connect/samples/zigbee/src/restart_handler.c index 85c4c6a..b864f69 100644 --- a/code/nrf-connect/samples/zigbee/src/restart_handler.c +++ b/code/nrf-connect/samples/zigbee/src/restart_handler.c @@ -14,10 +14,10 @@ static void restart_network_steering_cb(struct k_timer *timer) { K_TIMER_DEFINE(restart_timer, restart_network_steering_cb, NULL); -static void prst_restart_watchdog_start() { - k_timer_start(&restart_timer, K_SECONDS(PRST_ZB_RESET_TIMEOUT), K_MSEC(0)); +void prst_restart_watchdog_start() { + k_timer_start(&restart_timer, K_SECONDS(CONFIG_PRST_ZB_RESTART_WATCHDOG_TIMEOUT_SEC), K_MSEC(0)); } -static void prst_restart_watchdog_stop() { +void prst_restart_watchdog_stop() { k_timer_stop(&restart_timer); } diff --git a/code/nrf-connect/samples/zigbee/src/restart_handler.h b/code/nrf-connect/samples/zigbee/src/restart_handler.h index 9c4e6a5..5c3a8ad 100644 --- a/code/nrf-connect/samples/zigbee/src/restart_handler.h +++ b/code/nrf-connect/samples/zigbee/src/restart_handler.h @@ -1,9 +1,7 @@ #ifndef _PRST_ZB_RESTART_HANDLER_H_ #define _PRST_ZB_RESTART_HANDLER_H_ -static const int PRST_ZB_RESET_TIMEOUT = 5 * 60; - -static void prst_restart_watchdog_start; -static void prst_restart_watchdog_stop; +void prst_restart_watchdog_start(); +void prst_restart_watchdog_stop(); #endif // _PRST_ZB_RESTART_HANDLER_H_