This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How could we set ZED to leave the network and rejoin again?

Other Parts Discussed in Thread: Z-STACK

Hi all。

         there  are two  devices  ZED and ZC。

         some  time  ZC will send Send a Management Leave request to ZED.

         The  ZED need  to leave the network  and  going to rejoin again , and it was set  hold auto start。

         1.  i regsiter Mgmt_Leave_req in APP init function.

        

  // Register with the ZDO to receive Mgmt_Leave_req
  ZDO_RegisterForZDOMsg(zclConnectSwitch_TaskID, Mgmt_Leave_req);

         2.  I add the case in zclConnectSwitch_ProcessZDOMsgs()

       

static void zclTest_ProcessZDOMsgs( zdoIncomingMsg_t *pMsg )
{

  ZStatus_t status = ZSuccess;
  
   switch (pMsg->clusterID)
  {

   case Mgmt_Leave_req:
      RemoteLeaveReq = TRUE;
      zclTest_BasicResetCB();
      ZDP_MgmtLeaveRsp( pMsg->TransSeq, &pMsg->srcAddr,status, pMsg->SecurityUse );
     break;
     
   default:
     break;
  }
}

3.  i do the  reset  in  zclTest_BasicResetCB();

 

void zclTest_BasicResetCB()
{
   zgWriteStartupOptions( ZG_STARTUP_SET, ZCD_STARTOPT_DEFAULT_NETWORK_STATE | ZCD_STARTOPT_DEFAULT_CONFIG_STATE );  
   
   NLME_LeaveReq_t leaveReq;
   osal_memset( &leaveReq, 0, sizeof( NLME_LeaveReq_t ) );

   if(RemoteLeaveReq == TRUE)
   {
     leaveReq.rejoin = TRUE;
   }
   else
   {  //local key long press  do not rejoin again
     leaveReq.rejoin = FALSE; 
   }

      if(RemoteLeaveReq == TRUE)
      {
        RemoteLeaveReq = FALSE;
        ZDOInitDevice( 0 );
      }
      else
      {
        MT_SysCommandProcessing( aProcessCmd );
      }

}     

but  when it receive the remote  leave request, it could  not restart to search the new  network  

and it just always  rejoin  the previous network although  it was  stop permit join !

  • You should use the following code to do reset device.

    // Set the NV startup option to force a "new" join.
    zgWriteStartupOptions( ZG_STARTUP_SET, ZCD_STARTOPT_DEFAULT_NETWORK_STATE );

    // The device has been in the UNAUTH state, so reset
    // Note: there will be no return from this call
    SystemResetSoft();
  • thanks yikai

    so  there is no need to add NLME_LeaveReq( NLME_LeaveReq_t* req )?

    BR!

  • It depends on your application. You can do it to notify device's parent node.
  • when ZED receive the ZDP_MgmtLeaveReq(), there is will be a ZDP_MgmtLeaveRsp() ;


    if NLME_LeaveReq( NLME_LeaveReq_t* req ) is just add for notify his parent node,

    what is the different between ZDP_MgmtLeaveRsp() and NLME_LeaveReq( NLME_LeaveReq_t* req )?
  • If your device receives ZDP_MgmtLeaveReq, device would response with ZDP_MgmtLeaveRsp which is done by Z-Stack automatically and device won't need to send NLME_LeaveReq in this case.
  • so is that mean those two function was depend on whether the leave motion is passive or active?


    if the ZED leave the network was cause by long press of the local key , maybe i should choose to to use NLME_LeaveReq。

    or if the leave motion was caused by remote Cmd ( ZDP_MgmtLeaveReq ) ,Maybe ZDP_MgmtLeaveRsp is the best choose?

    BR!
  • Yes, that's correct.
  • Hi yikai

            i  have  do a test  of  the Management Leave request Cmd。

         

            when  ZED receive the Management Leave request Cmd it  will do  the below step

            {

            // Set the NV startup option to force a "new" join.
            zgWriteStartupOptions( ZG_STARTUP_SET, ZCD_STARTOPT_DEFAULT_NETWORK_STATE );

            // The device has been in the UNAUTH state, so reset
            // Note: there will be no return from this call
            SystemResetSoft();

            }

             but  the  ZED could not  start  to research  (sending beacon request ) again.

             ZC management leave request cmd is just like below :

          

             

          the ZED enable HOLD AUTO START , is  that matter with the device could not  researching  network ?

         or  is that relate with the Rejoin parameter of  Management  Leave Request cmd  ?(But i have  set it TRUE)

    BR!

        

             

  • Yes, I think it is because of HOLD_AUTO_START. You should disable it.

  • OK, thank you for answer!


    So the Rejoin parameter of Management Leave Request cmd is not make any sense for ZED。

    anyway what is ZDApp_LeaveReset( );

    should we use it while the ZED doing the leave motion?
  • If you disable HOLD_AUTO_START, the device would do rejoin or not according to Rejoin parameter of Management Leave Request.  ZDApp_LeaveReset is used for setuping a device reset due to a leave indication/confirm.

  • yeah , but the HOLD_AUTO_START is the Compile Options。and we want the device start to search the network after key press。
    so i think that is OK.


    But i try to find out the different of ZDApp_LeaveReset () , but it seems nothing happen whether i add it in the leave process or not .

    So i am curious about what is the meaning of “reset due to a leave indication/confirm”

    BR!
  • If you send a management leave request to device and device receives it, ZDApp_LeaveReset should be called. You can set a breakpoint in ZDApp_LeaveReset to verify this.
  • should be called?

    so it mean the zstack will auto call it,no matter i have not call it in the APP code。
  • Yes, ZDApp_LeaveReset would be called by ZDO_LeaveInd or ZDO_LeaveCnf in Z-Stack.