Send text data to a specific Zigbee Node with HA (NXP Zigbee HA)

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Send text data to a specific Zigbee Node with HA (NXP Zigbee HA)

跳至解决方案
5,205 次查看
dmsherazi
Contributor IV

I have a Zigbee End-device based on JN5168, I want to realize it as a lock that is battery powered. Apart from accepting the HA lock cluster commands, I need to send some custom data (some text as commands) for extra features that I want to add to the system. How can I send such data and receive it at lock? Do I have to implement a custom cluster along or is there another way?

标签 (1)
标记 (3)
1 解答
3,999 次查看
davidashraf
Contributor V

Hello dostshah

You can try the way mentioned in the following thread
https://community.nxp.com/thread/445724 

Regards

在原帖中查看解决方案

7 回复数
4,000 次查看
davidashraf
Contributor V

Hello dostshah

You can try the way mentioned in the following thread
https://community.nxp.com/thread/445724 

Regards

3,999 次查看
dmsherazi
Contributor IV

Thanks a lot, davidashraf‌. for pointing in the right direction. I am a newbie in ZigBee development please bear with me.

I am sending some data string "Hellow Zigbee!" from a coordinator as a broadcast on cluster id 0x0008 as below.

uint8 u8TransactionSequenceNumber;
ZPS_tsNwkNib *thisNib;
thisNib = ZPS_psNwkNibGetHandle(ZPS_pvAplZdoGetNwkHandle());
PDUM_thAPduInstance hAPduInst;
hAPduInst = PDUM_hAPduAllocateAPduInstance(apduZDP);

uint16 u16Offset = 0;
uint16 i;

// Fill hAPDU payload
u16Offset = 0;
uint8 buffer[] = "Hello Zigbee!";
for (i = 0;i< strlen(buffer);i++) {
    u16Offset += PDUM_u16APduInstanceWriteNBO(hAPduInst, u16Offset,"b", buffer[i]);
    DBG_vPrintf(TRUE,"%c", buffer[i]);
}
PDUM_eAPduInstanceSetPayloadSize(hAPduInst, u16Offset);
DBG_vPrintf(TRUE,"\nSize : %d\nSending : \n",PDUM_u16APduInstanceGetPayloadSize(hAPduInst));


if (hAPduInst == PDUM_INVALID_HANDLE){
    DBG_vPrintf(TRUE,"PDUM_INVALID_HANDLE\n");
} 
else {
    DBG_vPrintf(TRUE,"PDUM_VALID_HANDLE\n");
    ZPS_teStatus eStatus;
    ZPS_teAplAfSecurityMode eSecurityMode = (ZPS_E_APL_AF_SECURE_NWK);

    eStatus = ZPS_eAplAfBroadcastDataReq(hAPduInst,
                                     0x0008,
                                     0x01,
                                     0x0B,
                                     ZPS_E_BROADCAST_ALL,               //     Dest: All Coordinator & Routers
                                     eSecurityMode,
                                     0,
                                     &u8TransactionSequenceNumber
    );
    if(eStatus != ZPS_E_SUCCESS){
        PDUM_eAPduFreeAPduInstance(hAPduInst);
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I plan to receive this broadcast message on the other ZigBee device which is a Dimmable Light 0x0008 that is developed using the source code example of Dimmable Light in the HA demo (JN-AN-1189-ZigBee-HA-Demo).

I am trying to catch these messages in there but I am unable to even get an indication of a broadcast message there. I couldn't find any example or help else where. Can you please help me out with the code snippet or any instructions to achieve my goal.

If I am correct  I need to catch the incoming broadcast messages in the function below. That means that when a Broadcast message is sent it should print the Debug messages and pass the event to sCallbackEvent.

/****************************************************************************
 *
 * NAME: ZCL_Task
 *
 * DESCRIPTION:
 * ZCL Task for the Light
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
OS_TASK(ZCL_Task)
{

    ZPS_tsAfEvent sStackEvent;
    tsZCL_CallBackEvent sCallBackEvent;
    sCallBackEvent.pZPSevent = &sStackEvent;
    DBG_vPrintf(TRACE_ZCL, "\nZCL_Task event11:%d",sStackEvent.eType);
    /* If there is a stack event to process, pass it on to ZCL */
    sStackEvent.eType = ZPS_EVENT_NONE;
    if ( OS_eCollectMessage(APP_msgZpsEvents_ZCL, &sStackEvent) == OS_E_OK)
    {
        DBG_vPrintf(TRACE_ZCL, "\nZCL_Task hh  event:%d",sStackEvent.eType);
        sCallBackEvent.eEventType = E_ZCL_CBET_ZIGBEE_EVENT;
        vZCL_EventHandler(&sCallBackEvent);
    }

}

and then I can get it in the following function

/****************************************************************************
 *
 * NAME: APP_ZCL_cbGeneralCallback
 *
 * DESCRIPTION:
 * General callback for ZCL events
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void APP_ZCL_cbGeneralCallback(tsZCL_CallBackEvent *psEvent)
{
    switch (psEvent->eEventType)
    {


    case E_ZCL_CBET_UNHANDLED_EVENT:
        DBG_vPrintf(TRACE_ZCL, "\nEVT: Unhandled Event\r\n");
        break;

    case E_ZCL_CBET_READ_ATTRIBUTES_RESPONSE:
        DBG_vPrintf(TRACE_ZCL, "\nEVT: Read attributes response");
        break;

    case E_ZCL_CBET_READ_REQUEST:
        DBG_vPrintf(TRACE_ZCL, "\nEVT: Read request");
        break;

    case E_ZCL_CBET_DEFAULT_RESPONSE:
        DBG_vPrintf(TRACE_ZCL, "\nEVT: Default response");
        break;

    case E_ZCL_CBET_ERROR:
        DBG_vPrintf(TRACE_ZCL, "\nEVT: Error");
        break;

    case E_ZCL_CBET_TIMER:
        DBG_vPrintf(TRACE_ZCL, "\nEVT: Timer");
        break;

    case E_ZCL_CBET_ZIGBEE_EVENT:
        DBG_vPrintf(TRACE_ZCL, "\nEVT: ZigBee");
        break;

    case E_ZCL_CBET_CLUSTER_CUSTOM:
        DBG_vPrintf(TRACE_ZCL, "\nEP EVT: Custom");
        break;

    default:
        DBG_vPrintf(TRACE_ZCL, "\nInvalid event type");
        break;
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I would be really thankful for help and support in this regard.

3,999 次查看
davidashraf
Contributor V

Hello dostshah‌ 
I haven't had much time working with Zigbee 3.0 but I am willing to help as unfortunately sometimes Admins take much time here to respond.

As far as I know
Generally , and like you read in the thread I've mentioned before , the data you send is sent to the destination endpoint 
and upon reception an event is generated and the general callback queue the event holding the data received
This event is then received at endpoint task and data then can be extracted from it.

If you could get something from what I said you may be able to find a solution,but please tell me where is the file in which ZCL task is located in order to try to find out where the problem might be with you.


Another side note :
You say you want to broadcast to coordinator and routers only , yet you're using 

ZPS_E_BROADCAST_ALL,

instead of 

ZPS_E_BROADCAST_ZC_ZR,


I am waiting for your response and happy to help.

Regards

3,999 次查看
dmsherazi
Contributor IV

Thanks once again davidashraf‌. Here is the complete source code for HA demo GitHub - jdeltoft/NXP-Home-Automation.

The file is located in /Common_Light/Sourceapp_zcl_light_task.c   (NXP-Home-Automation/app_zcl_light_task.c at master · jdeltoft/NXP-Home-Automation · GitHub)

I used  ZPS_E_BROADCAST_ALL as I needed to send to all nodes.

3,999 次查看
davidashraf
Contributor V

Hello dostshah‌ 
When you try the method you mentioned , do you see any debug messages ?
Regards

3,999 次查看
dmsherazi
Contributor IV

Hi davidashraf‌, 

Solved by adding a ZPS_EVENT_APS_DATA_INDICATION case in the APP_ZCL_cbGeneralCallback as follows

PRIVATE void APP_ZCL_cbGeneralCallback(tsZCL_CallBackEvent *psEvent)
{
    switch (psEvent->eEventType){
         case ZPS_EVENT_APS_DATA_INDICATION: 
          ......

and fixing the destination endpoint. I was using 

0x0B,

which was not implemented in this Dimmable Light device that I was implementing.

3,999 次查看
davidashraf
Contributor V

dostshah
Nice work