2024-04-25 04:38 AM - edited 2024-04-25 05:56 AM
I'm trying to find a way to get the connection status of the Zigbee Network.
Our application can successfully join a network. We have also implemented persistence and are able to rejoin a previously setup Zigbee Coordinator. But I haven't found a way to tell if the local device is actually joined to the network or not. Also, I have no way to tell if the network connection has been lost or interrupted (e.g. due to weak signal).
Does the Zigbee Library provide a way to register a callback or a status function to poll this information?
I need to be able to detect if the local device is no longer joined to the network. Or when it is unable to find its configured network.
Regards,
Ozzy
Solved! Go to Solution.
2024-04-26 05:58 AM
Hello @Oswalt,
Join Indication will be triggered on the parent side to detect that a new join has been initiated from the router or End device, the callback will be then generated with the ID ZB_MSG_FILTER_JOIN_IND indicating either an Association or NWK Rejoin.
On the Child side, when the join is completed successfully, the status of ZbStartupWait returns ZB_STATUS_SUCCESS, so this could be used to detect the join from the end device app.
On the other hand, ZB_MSG_FILTER_LEAVE_IND is used on both coordinator and end device to detect a leave network., this could be tested when performing a ZbZdoLeaveReq .
Kind regards,
Ouadi
2024-04-25 06:59 AM - edited 2024-04-25 07:00 AM
Hello @Oswalt,
To retrieve the network status from the M4 application side, there is an API used to register a callback with a filter parameter ZbMsgFilterRegister to be called at the startup inside the function APP_ZIGBEE_StackLayersInit.
The callback will be raised in case of an update of the network status, you can have a look on the structure ZbNwkNetworkStatusCodeT that contains the list of the network status you can use.
For example, to detect the lost of the parent from the end device side, you can use a ZB_NWK_STATUS_CODE_PARENT_LINK_FAILURE that will be triggered as an indication in the callback as follow :
ZbMsgFilterRegister(zigbee_app_info.zb, ZB_MSG_FILTER_STATUS_IND, ZB_MSG_INTERNAL_PRIO + 1, app_zb_msg_filter_cb, NULL); //( to be called inside APP_ZIGBEE_StackLayersInit func after end point config)
/**
* @brief Zigbee Message Filter callback
* @param zb, id, msg, arg
* @retval zb_msg_filter_rc
*/
enum zb_msg_filter_rc app_zb_msg_filter_cb(struct ZigBeeT *zb, uint32_t id, void *msg, void *arg)
{
if (id == ZB_MSG_FILTER_STATUS_IND) {
struct ZbNlmeNetworkStatusIndT *ind = msg;
switch (ind->status) {
case ZB_NWK_STATUS_CODE_PARENT_LINK_FAILURE:
/* Set a flag for application to attempt to rejoin network */
/* Since we will handle this in the application, tell stack
* to not process this message further by returning ZB_MSG_DISCARD. */
APP_DBG("Network Lost / Parent Link Failure");
increment_rejoin++;
Counter_rejoin=increment_rejoin%8;
if (Counter_rejoin==7) {
HW_TS_Create(CFG_TIM_ZIGBEE_APP_ONOFF_BACK_TO_ONESHOT, &TS_ID1, hw_ts_SingleShot, APP_ZIGBEE_Rejoin_cb);
HW_TS_Start(TS_ID1, 10*HW_TS_SERVER_1S_NB_TICKS);
}
return ZB_MSG_DISCARD;
default:
break;
}
}
return ZB_MSG_CONTINUE;
}
Best regards,
Ouadi
2024-04-25 12:53 PM - edited 2024-04-26 04:36 AM
Hi @Ouadi, thanks for your suggestion. However, it doesn't work as expected.
I've registered the filter callback in APP_ZIGBEE_StackLayerInit:
static void APP_ZIGBEE_StackLayersInit(void)
{
APP_DBG("APP_ZIGBEE_StackLayersInit");
zigbee_app_info.zb = ZbInit(0U, NULL, &zigbee_logger);
assert(zigbee_app_info.zb != NULL);
/* Create the endpoint and cluster(s) */
APP_ZIGBEE_ConfigEndpoints();
ZbMsgFilterRegister(zigbee_app_info.zb, ZB_MSG_FILTER_NLME, ZB_MSG_INTERNAL_PRIO + 1, zigbee_msg_filter_cb, NULL);
/* Configure the joining parameters */
zigbee_app_info.join_status = (enum ZbStatusCodeT)0x01; /* init to error status */
zigbee_app_info.join_delay = HAL_GetTick(); /* now */
zigbee_app_info.startupControl = ZbStartTypeJoin;
/* Initialization Complete */
zigbee_app_info.has_init = true;
// Start network join
UTIL_SEQ_SetTask(1U << CFG_TASK_ZIGBEE_NETWORK_FORM, CFG_SCH_PRIO_0);
}
The zigbee_msg_filter_cb() function gets invoked several times in short succession, but the status is always zero (ZB_NWK_STATUS_CODE_NO_ROUTE_AVAILABLE). I've also tried using ZB_MSG_FILTER_NLME in the hopes that I could detect join and leave indications, but those are never occurring.
2024-04-26 05:58 AM
Hello @Oswalt,
Join Indication will be triggered on the parent side to detect that a new join has been initiated from the router or End device, the callback will be then generated with the ID ZB_MSG_FILTER_JOIN_IND indicating either an Association or NWK Rejoin.
On the Child side, when the join is completed successfully, the status of ZbStartupWait returns ZB_STATUS_SUCCESS, so this could be used to detect the join from the end device app.
On the other hand, ZB_MSG_FILTER_LEAVE_IND is used on both coordinator and end device to detect a leave network., this could be tested when performing a ZbZdoLeaveReq .
Kind regards,
Ouadi