Skip to content

Commit

Permalink
sleep for 3 minutes before trying to reconnect in case of network lost
Browse files Browse the repository at this point in the history
  • Loading branch information
devbis committed Nov 8, 2023
1 parent 081e2a9 commit 2d9743d
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/zb_appCb.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ ota_callBack_t sensorDevice_otaCb =
#endif

ev_timer_event_t *steerTimerEvt = NULL;
ev_timer_event_t *deviceRejoinBackoffTimerEvt = NULL;

/**********************************************************************
* FUNCTIONS
Expand All @@ -83,6 +84,18 @@ s32 sensorDevice_bdbNetworkSteerStart(void *arg){
return -1;
}

s32 sensorDevice_rejoinBackoff(void *arg){
if(zb_isDeviceFactoryNew()){
if(deviceRejoinBackoffTimerEvt){
TL_ZB_TIMER_CANCEL(&deviceRejoinBackoffTimerEvt);
}
return -1;
}

zb_rejoinReqWithBackOff(zb_apsChannelMaskGet(), g_bdbAttrs.scanDuration);
return 0;
}

/*********************************************************************
* @fn zbdemo_bdbInitCb
*
Expand Down Expand Up @@ -153,6 +166,9 @@ void zbdemo_bdbCommissioningCb(u8 status, void *arg){
if(steerTimerEvt){
TL_ZB_TIMER_CANCEL(&steerTimerEvt);
}
if(deviceRejoinBackoffTimerEvt){
TL_ZB_TIMER_CANCEL(&deviceRejoinBackoffTimerEvt);
}

#ifdef ZCL_POLL_CTRL
sensorDevice_zclCheckInStart();
Expand Down Expand Up @@ -191,12 +207,13 @@ void zbdemo_bdbCommissioningCb(u8 status, void *arg){
case BDB_COMMISSION_STA_NO_SCAN_RESPONSE:
case BDB_COMMISSION_STA_PARENT_LOST:
//zb_rejoinSecModeSet(REJOIN_INSECURITY);
zb_rejoinReqWithBackOff(zb_apsChannelMaskGet(), g_bdbAttrs.scanDuration);
sensorDevice_rejoinBackoff(NULL);
break;
case BDB_COMMISSION_STA_REJOIN_FAILURE:
if(!zb_isDeviceFactoryNew()){
zb_rejoinReqWithBackOff(zb_apsChannelMaskGet(), g_bdbAttrs.scanDuration);
}
if(!deviceRejoinBackoffTimerEvt){
// sleep for 3 minutes before reconnect if rejoin failed
deviceRejoinBackoffTimerEvt = TL_ZB_TIMER_SCHEDULE(sensorDevice_rejoinBackoff, NULL, 3 * 60 * 1000);
}
break;
default:
break;
Expand Down Expand Up @@ -246,6 +263,9 @@ void sensorDevice_otaProcessMsgHandler(u8 evt, u8 status)
void sensorDevice_leaveCnfHandler(nlme_leave_cnf_t *pLeaveCnf)
{
if(pLeaveCnf->status == SUCCESS){
if(deviceRejoinBackoffTimerEvt){
TL_ZB_TIMER_CANCEL(&deviceRejoinBackoffTimerEvt);
}
//zb_resetDevice();
}
}
Expand Down

0 comments on commit 2d9743d

Please sign in to comment.