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 to tell ZC when ZED leave network?



when ZED leave the network, which function should be used to  tell ZC ?

  • You can use ZDP_MgmtLeaveReq to do this.

  • hi Chen
                 do you have seen the below function of zstack

                 when  the ZED reset  to factory config, do it send a leave request(NLME_LeaveReq( &leaveReq ))?

                 is it same as ZDP_MgmtLeaveReq

               

                when i use ZDP_MgmtLeaveReq, does ZED need to wait ZDP_MgmtLeaveRsp  before Reset to factory?


     static void zclsampleXXX_BasicResetCB( void )
    {
       NLME_LeaveReq_t leaveReq;
       
       //delete the user item
       osal_nv_delete( ZONE_CIEADDRESS_AND_ENROLL_INFO, NV_CIEADDR_LEN+NV_EXTDATA_LEN);
       
      // Set every field to 0
      osal_memset( &leaveReq, 0, sizeof( NLME_LeaveReq_t ) );
     
      // This will enable the device to rejoin the network after reset.
      leaveReq.rejoin = TRUE;
     
      // Set the NV startup option to force a "new" join. //3
      zgWriteStartupOptions( ZG_STARTUP_SET, ZCD_STARTOPT_DEFAULT_NETWORK_STATE | ZCD_STARTOPT_DEFAULT_CONFIG_STATE );    
     
      // Leave the network, and reset afterwards
      if ( NLME_LeaveReq( &leaveReq ) != ZSuccess )
      {
        // Couldn't send out leave; prepare to reset anyway
        ZDApp_LeaveReset( FALSE );
      }
     
      // restart device
     MT_SysCommandProcessing( aProcessCmd );
     
     
    }

  • hi Chen

               i would like to enrich the question as  below

               the ZED was preform as HA device, and  there is a note as below in HA specific

              is that mean i need to use all of those function (ZDP_MgmtLeaveReq   and   NLME_LeaveReq( &leaveReq ) )

        

            Return to Factory Defaults
            In support of a return to factory default capability, HA devices shall implement the ZDO Management Leave server service.

            When invoked with a unicast address and the DeviceAddress set to NULL=0x00000000, the device shall implement a NWK Leave.

            When invoked with a broadcast address and the DeviceAddress set to NULL=0x00000000, the device shall wait the broadcast timeout period to
            allow the message to propagate through network, then the device shall implement a NWK Leave.

           Prior to execution of the NWK Leave in either case, processing in the device shall ensure all operating parameters are reset to allow a reset to factory
           defaults.


  • The effect of NLME_LeaveReq is similar to ZDP_MgmtLeaveReq. In my experience, I would wait for ZDP_MgmtLeaveRsp for a moment after ZED issues ZDP_MgmtLeaveReq. ZED would do factory reset anyway after a delay.

  • Hi  Chen

           when i  only involved   ZDP_MgmtLeaveReq(father_dstAddr, NLME_GetExtAddr(), FALSE,TRUE, 1)  in zclXXXX_BasicResetCB  function  of  ZED,

           The ZC will receive a MgmtLeaveReq Msg  in   ZDO_MSG_CB

          

            when i only involved the NLME_LeaveReq( &leaveReq )  in zclXXXX_BasicResetCB  function  of  ZED,

            The ZC can't  catch anything of Leave request Msg

            

            and if  i open MT_SysCommandProcessing( aProcessCmd );  no matter i use ZDP_MgmtLeaveReq  or NLME_LeaveReq in ZED

            The ZC can't catch anything, it seems  that ZED have not finish processed  the Leave function  then doing the factory reset....

     

          

           static void zclConnectSwitch_BasicResetCB( void )
    {
        
      // ZDO Management Leave server service
      zAddrType_t *father_dstAddr =NULL;
      father_dstAddr->addrMode = (afAddrMode_t)(afAddr16Bit);
      father_dstAddr->addr.shortAddr = NLME_GetCoordShortAddr();
      ZDP_MgmtLeaveReq(father_dstAddr, NLME_GetExtAddr(), FALSE,TRUE, 1);

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


      //NLME_LeaveReq_t leaveReq; 
      // Set every field to 0
      //osal_memset( &leaveReq, 0, sizeof( NLME_LeaveReq_t ) );
      // This will enable the device to rejoin the network after reset.
      //leaveReq.rejoin = TRUE;
      // Leave the network, and reset afterwards
    //  if ( NLME_LeaveReq( &leaveReq ) != ZSuccess )
    //  {
    //    // Couldn't send out leave; prepare to reset anyway
    //    ZDApp_LeaveReset( FALSE );
    //  }
     
      // restart device
     //MT_SysCommandProcessing( aProcessCmd );
     
     
    }

    there is nothing received by ZC?   although  i have registered  the Mgmt_Leave_req  ,adding  MT_ZDO_FUNC and MT_ZDO_MGMT in compile option   in the ZC

          

  • What is in your father_dstAddr? I sugget you using packet analyzer to check if your device send out leave request when issue this API ZDP_MgmtLeaveReq().
  • Hi Chen ,
    it doesn't matter ,i also change the dstaddr as broadcast Mode . because i need to tell all the devices on the network that which one has leaving.

    i make a test that involved ZDP_MgmtLeaveReq(father_dstAddr, NLME_GetExtAddr(), FALSE,TRUE, 1) by keypress.
    The ZC can catch the Leaving request Msg, and it seems take a long time, may be zstack set a delay of process Leave function.


    But i don't know how to use ZDP_MgmtLeaveReq in Factory Reset function.
    I don't know how long should i wait for zstack finish process ZDP_MgmtLeaveReq(), then i will process MT_SysCommandProcessing( aProcessCmd );

    if i haven't wait a "moment" , other device can't received the Leaving Msg