Merge pull request #130 from oleo65/zigbee-schedule-steering-restart
Zigbee schedule steering restart
This commit is contained in:
commit
bcc5a853d0
5 changed files with 48 additions and 3 deletions
|
|
@ -16,8 +16,9 @@ target_sources(app PRIVATE
|
||||||
src/factory_reset.c
|
src/factory_reset.c
|
||||||
src/prst_zb_attrs.c
|
src/prst_zb_attrs.c
|
||||||
src/prst_zb_soil_moisture_defs.c
|
src/prst_zb_soil_moisture_defs.c
|
||||||
|
src/restart_handler.c
|
||||||
)
|
)
|
||||||
|
|
||||||
add_subdirectory(../../prstlib prstlib)
|
add_subdirectory(../../prstlib prstlib)
|
||||||
target_include_directories(app PRIVATE ../../prstlib/include)
|
target_include_directories(app PRIVATE ../../prstlib/include)
|
||||||
target_link_libraries(app PUBLIC prstlib)
|
target_link_libraries(app PUBLIC prstlib)
|
||||||
|
|
|
||||||
|
|
@ -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."
|
bool "Resetting via the reset pin will factory reset the device. Power cycling through battery replacement will not."
|
||||||
|
|
||||||
endchoice # PRST_ZB_FACTORY_RESET_METHOD
|
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
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
#include "prst_zb_attrs.h"
|
#include "prst_zb_attrs.h"
|
||||||
#include "prst_zb_endpoint_defs.h"
|
#include "prst_zb_endpoint_defs.h"
|
||||||
#include "prst_zb_soil_moisture_defs.h"
|
#include "prst_zb_soil_moisture_defs.h"
|
||||||
|
#include "restart_handler.h"
|
||||||
|
|
||||||
LOG_MODULE_REGISTER(app, CONFIG_LOG_DEFAULT_LEVEL);
|
LOG_MODULE_REGISTER(app, CONFIG_LOG_DEFAULT_LEVEL);
|
||||||
|
|
||||||
|
|
@ -128,9 +129,17 @@ void zboss_signal_handler(zb_bufid_t bufid) {
|
||||||
case ZB_BDB_SIGNAL_STEERING: // New network.
|
case ZB_BDB_SIGNAL_STEERING: // New network.
|
||||||
case ZB_BDB_SIGNAL_DEVICE_REBOOT: { // Previously joined network.
|
case ZB_BDB_SIGNAL_DEVICE_REBOOT: { // Previously joined network.
|
||||||
LOG_DBG("Steering complete. Status: %d", status);
|
LOG_DBG("Steering complete. Status: %d", status);
|
||||||
prst_led_flash(/*times=*/3);
|
|
||||||
if (status == RET_OK) {
|
if (status == RET_OK) {
|
||||||
|
LOG_DBG("Steering successful. Status: %d", status);
|
||||||
|
prst_led_flash(/*times=*/3);
|
||||||
k_timer_stop(&led_flashing_timer);
|
k_timer_stop(&led_flashing_timer);
|
||||||
|
prst_restart_watchdog_stop();
|
||||||
|
prst_led_off();
|
||||||
|
} else {
|
||||||
|
LOG_DBG("Steering failed. Status: %d", status);
|
||||||
|
prst_led_flash(7);
|
||||||
|
prst_restart_watchdog_start();
|
||||||
|
k_timer_stop(&led_flashing_timer); // Power saving
|
||||||
prst_led_off();
|
prst_led_off();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -139,6 +148,7 @@ void zboss_signal_handler(zb_bufid_t bufid) {
|
||||||
break;
|
break;
|
||||||
case ZB_ZDO_SIGNAL_LEAVE:
|
case ZB_ZDO_SIGNAL_LEAVE:
|
||||||
if (status == RET_OK) {
|
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);
|
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);
|
LOG_INF("Network left (leave type: %d)", leave_params->leave_type);
|
||||||
|
|
||||||
|
|
@ -149,7 +159,7 @@ void zboss_signal_handler(zb_bufid_t bufid) {
|
||||||
}
|
}
|
||||||
case ZB_ZDO_SIGNAL_SKIP_STARTUP: {
|
case ZB_ZDO_SIGNAL_SKIP_STARTUP: {
|
||||||
stack_initialised = true;
|
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));
|
k_timer_start(&led_flashing_timer, K_NO_WAIT, K_SECONDS(1));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
23
code/nrf-connect/samples/zigbee/src/restart_handler.c
Normal file
23
code/nrf-connect/samples/zigbee/src/restart_handler.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
#include "restart_handler.h"
|
||||||
|
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
#include <zephyr/logging/log.h>
|
||||||
|
#include <zigbee/zigbee_app_utils.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.");
|
||||||
|
// If the device is not commissioned, the rejoin procedure is started.
|
||||||
|
user_input_indicate();
|
||||||
|
}
|
||||||
|
|
||||||
|
K_TIMER_DEFINE(restart_timer, restart_network_steering_cb, NULL);
|
||||||
|
|
||||||
|
void prst_restart_watchdog_start() {
|
||||||
|
k_timer_start(&restart_timer, K_SECONDS(CONFIG_PRST_ZB_RESTART_WATCHDOG_TIMEOUT_SEC), K_MSEC(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void prst_restart_watchdog_stop() {
|
||||||
|
k_timer_stop(&restart_timer);
|
||||||
|
}
|
||||||
7
code/nrf-connect/samples/zigbee/src/restart_handler.h
Normal file
7
code/nrf-connect/samples/zigbee/src/restart_handler.h
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
#ifndef _PRST_ZB_RESTART_HANDLER_H_
|
||||||
|
#define _PRST_ZB_RESTART_HANDLER_H_
|
||||||
|
|
||||||
|
void prst_restart_watchdog_start();
|
||||||
|
void prst_restart_watchdog_stop();
|
||||||
|
|
||||||
|
#endif // _PRST_ZB_RESTART_HANDLER_H_
|
||||||
Loading…
Add table
Reference in a new issue