Skip to main content
Joan Duran
Associate II
November 15, 2024
Solved

New device callback in Zigbee

Using the Zigbee stack as a coordinator, is there a callback available to notify when a new device is associated in the network?

We observe the following in the M0 log:

[M0] [00000015.076][PLATFORM] nwk_handle_assoc : Association accepted, sending response (0xb0dc, 0xa4c1383054f9cec1)

We can detect the new device in the ZB_NWK_NIB_ID_NeighborTable, but having a callback to trigger on association would be very helpful. I've checked the documentation and examples but haven’t found any information on this.

Thank you!

 

This topic has been closed for replies.
OuadiBest answer
ST Technical Moderator
November 15, 2024

Hi @Joan Duran,

You can use ZbMsgFilterRegister API at the startup (inside the func APP_ZIGBEE_StackLayersInit) to register the callback you want to use to retrieve any network status change. 

Please find below an example to detect a new device join : 

ZbMsgFilterRegister( stZigbeeAppInfo.pstZigbee, ZB_MSG_FILTER_JOIN_IND, ZB_MSG_DEFAULT_PRIO, APP_ZIGBEE_DeviceJointCallback, NULL );

static enum zb_msg_filter_rc APP_ZIGBEE_DeviceJointCallback( struct ZigBeeT * zb, uint32_t lId, void * pMessage, void * arg )
{
 struct ZbNlmeJoinIndT * pstJoinMessage;

 if ( lId == ZB_MSG_FILTER_JOIN_IND )
 {
 pstJoinMessage = ( struct ZbNlmeJoinIndT * )pMessage;

 switch ( pstJoinMessage->rejoinNetwork )
 {
 case ZB_NWK_REJOIN_TYPE_ASSOC :
 case ZB_NWK_REJOIN_TYPE_ORPHAN :
 case ZB_NWK_REJOIN_TYPE_NWKREJOIN :
 case ZB_NWK_REJOIN_TYPE_NWKCOMMISS_JOIN :
 case ZB_NWK_REJOIN_TYPE_NWKCOMMISS_REJOIN :
 /* A new Device has Join Network at MAC/NWK level */
 APP_ZIGBEE_SetNewDevice( pstJoinMessage->nwkAddr, pstJoinMessage->extAddr, pstJoinMessage->capabilityInfo );
 break;

 default :
 break;
 }
 }

 return( ZB_MSG_CONTINUE );
}

Best regards,

Ouadi

2 replies

Visitor II
November 15, 2024

Use the emberIncomingMessageHandler() callback to listen for ZDO_Device_Announce messages. Or you can also use  emberAfPluginNetworkSteeringDeviceJoinedCallback() (if using the Network Steering plugin) to detect when a device has joined.

 

OuadiBest answer
ST Technical Moderator
November 15, 2024

Hi @Joan Duran,

You can use ZbMsgFilterRegister API at the startup (inside the func APP_ZIGBEE_StackLayersInit) to register the callback you want to use to retrieve any network status change. 

Please find below an example to detect a new device join : 

ZbMsgFilterRegister( stZigbeeAppInfo.pstZigbee, ZB_MSG_FILTER_JOIN_IND, ZB_MSG_DEFAULT_PRIO, APP_ZIGBEE_DeviceJointCallback, NULL );

static enum zb_msg_filter_rc APP_ZIGBEE_DeviceJointCallback( struct ZigBeeT * zb, uint32_t lId, void * pMessage, void * arg )
{
 struct ZbNlmeJoinIndT * pstJoinMessage;

 if ( lId == ZB_MSG_FILTER_JOIN_IND )
 {
 pstJoinMessage = ( struct ZbNlmeJoinIndT * )pMessage;

 switch ( pstJoinMessage->rejoinNetwork )
 {
 case ZB_NWK_REJOIN_TYPE_ASSOC :
 case ZB_NWK_REJOIN_TYPE_ORPHAN :
 case ZB_NWK_REJOIN_TYPE_NWKREJOIN :
 case ZB_NWK_REJOIN_TYPE_NWKCOMMISS_JOIN :
 case ZB_NWK_REJOIN_TYPE_NWKCOMMISS_REJOIN :
 /* A new Device has Join Network at MAC/NWK level */
 APP_ZIGBEE_SetNewDevice( pstJoinMessage->nwkAddr, pstJoinMessage->extAddr, pstJoinMessage->capabilityInfo );
 break;

 default :
 break;
 }
 }

 return( ZB_MSG_CONTINUE );
}

Best regards,

Ouadi