[BitCloud] ZigBee NWK Leave frame when a device leaves on its own - Page 1
Forum section: electronics / general

author: rfleming
author_rank: Regular Contributor
timestamp: July 28, 2016, 03:38:45 am
content: Hi guys (Alex),I've been looking at a few different units I have on hand with ZigBee and have found that when a router leaves the network on its own it broadcasts a "NWK Leave" frame. When this is done, I'm not 100% but it appears to clear up some of my tables on my coordinator such that when I get the device to join by association, my coorindator handles the announce frame issued by the new router.On the other hand, if the NWK Leave frame was not issued over the network when I do a normal MGMT_LEAVE through a ZDP Request, the command is only handled internally on the router. So when I go to join the network by association once more, it gets authorization (event BC_EVENT_ACCESS_REQUEST is triggered), but the announce event isn't.In summation, it appears that when a router leaves locally, no command is issued over the network. Thus when it joins the network once more by association its like it never left.Cheers,Ryan.

author: ataradov
author_rank: Super Contributor
timestamp: July 28, 2016, 04:19:34 am
content: The only thing that come to mind are CS_LEAVE_REJOIN_CONTROL_ID and CS_LEAVE_NON_REJOIN_CONTROL_ID parameters. Both have "silent" member.But it is normally set to 0 and none of the standard applications change it. But will not hurt to check.

author: rfleming
author_rank: Regular Contributor
timestamp: November 21, 2016, 05:26:27 am
content: FYI.Finally found after spending a lot of time looking for it...If I am trying to get a node like a router to leave the network on its own, I should use a "NWK_LeaveReq_t" query passed to "NWK_LeaveReq" function. It doesn't appear to be documented anyway. Kind of just went searching through specifications and source code for things that resembled this.Assigning the extended address member (deviceAddress) to 0. Assigning this to 0 will send a bradcast frame instead...yay!Ryan.

author: ataradov
author_rank: Super Contributor
timestamp: November 21, 2016, 05:31:23 am
content: Actually, the correct way is to use ZDP command. Both WSNDemo and ZLLDemo contain examples of this. For example, here is the code from WSNDemo:Code:case APP_LEAVING_NETWORK_STATE:{//Get the pointer to the request's payloadZDO_MgmtLeaveReq_t *zdpLeaveReq = &leaveReq.req.reqPayload.mgmtLeaveReq;visualizeNwkLeaving();//Configure parameters of the leave network ZDP requestleaveReq.ZDO_ZdpResp = appZdpLeaveResp; //Set the callback functionleaveReq.reqCluster = MGMT_LEAVE_CLID; //Set the request' typeleaveReq.dstAddrMode = APS_EXT_ADDRESS;COPY_EXT_ADDR(leaveReq.dstAddress.extAddress, *MAC_GetExtAddr());zdpLeaveReq->deviceAddr = 0; //The current node is requested to leave the networkzdpLeaveReq->rejoin = 0; //Without rejoining the network after leaving itzdpLeaveReq->removeChildren = 1; //Command all end device children to leave the network as wellzdpLeaveReq->reserved = 0;//Send the configure ZDP request to the stackZDO_ZdpReq(&leaveReq);}break;I don't see how this can not send a frame, especially with removeChildren set to "1".

author: rfleming
author_rank: Regular Contributor
timestamp: November 21, 2016, 06:20:18 am
content: While you're arguably correct, when I issue this exact command (ctrl-c + ctrl-v) on my router code, it will only leave locally without broadcasting the NWK Leave frame, or any other frame. The NWK Leave frame is required when leaving a network else the coordinator will not know it has left, thus leaving a lot of information in various tables.Testing your example, after I have issued the command and utilising the following callback:Code:void LeaveMe(ZDO_ZdpResp_t *zdpResp){//PDS_Delete(PDS_ALL_EXISTENT_MEMORY);//clears both default and user space PDSPDS_Delete(BC_ALL_MEMORY_MEM_ID);//clears all default PDS. Leaves user space in tactHAL_WarmReset();}This happens:Router Restarts and is awaiting a nwk to joinI Permit Joining on the CoordinatorRouter joins the network as if it had never been in it at allThe Coordinator Assigns the same node ID as it previously didThe Router sends an announce frame over the networkThe Coordinator responds to BC_EVENT_ACCESS_REQUEST but not the BC_ZDP_DEVICE_ANNOUNCE_RECEIVED eventAll the information between the two units is kind of...fked. If the coordinator sends any commands to the router, zdp, zcl or others, the router responds correctly, but the coordinator doesn't wont acknowledge the response.Reboot the Coordinator, everything works fineIn this process I also tried setting theCode:zdpLeaveReq->deviceAddr = 0;to my routers extended address and issuing the ZDP Command to my coordinator (from router), actioning my router to leave. It once again would leave, but still did not send the NWK Leave broadcast frame. It appears that this frame would only be sent over the network if another device addressing my router as the device to leave. Thus my router would only leave when processing a request from an external device, not its own and not as a response.So my solution before broadcasts this frame manually and leaves the network as wellYay fixed