Zigbee Data receive and send function implementation

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

Zigbee Data receive and send function implementation

539 次查看
tushar_verma
Contributor I

Hi,

We are using FRDM-KW41Z board and SDK latest version, I have tried working upon sample code of zigbee 3.0 coordinator and router and tried to implement data send and receive function given below

I have implemented data receive and data send function on both coordinator and router application 
void Send_Data(uint8* data,uint8 len){

         uint8 pSeqNum;
         PDUM_thAPduInstance hAPduInst = PDUM_hAPduAllocateAPduInstance(apduZDP);
         uint16 u16Offset = 0;
         uint16 i;
 
         int PDUM_STATE = PDUM_eAPduInstanceSetPayloadSize(hAPduInst, len);
 
         if(PDUM_STATE == 0)
            DBG_vPrintf(TRUE, "PDUM_OK\n");
         else
            DBG_vPrintf(TRUE, "PDUM_STATE %d\n",PDUM_STATE);
 
         for (i = 0; i < len; i++) {
         u16Offset += PDUM_u16APduInstanceWriteNBO(hAPduInst, u16Offset,"a", *(data + i));
         DBG_vPrintf(TRUE, "%c", *(data + i));
         }
 
         DBG_vPrintf(TRUE, "Size : %d\n Sending : \n", PDUM_u16APduInstanceGetPayloadSize(hAPduInst));
 
         if (hAPduInst == PDUM_INVALID_HANDLE){
               DBG_vPrintf(TRUE, "PDUM_INVALID_HANDLE\n");
               return;
         }
         else {
        for(uint16_t pos = 0; pos < u16Offset; pos++) {
                    DBG_vPrintf(TRUE, "------%c", hAPduInst->au8Storage[pos]);
                }
           ZPS_teStatus eStatus;
           ZPS_teAplAfSecurityMode eSecurityMode = (ZPS_E_APL_AF_SECURE_NWK);
 
           eStatus = ZPS_eAplAfBroadcastDataReq(hAPduInst,
                                        0x0013,
                                                0x01,
                                                0x01,
                                                ZPS_E_BROADCAST_ZC_ZR,
                                                eSecurityMode,
                                                0,
                                                &pSeqNum
                                                );
 
           if(eStatus != ZPS_E_SUCCESS)
           DBG_vPrintf(TRUE, "ZPS_E_state %x\n",eStatus);
           else if(eStatus == ZPS_E_SUCCESS)
           DBG_vPrintf(TRUE, "Send success\n");
     PDUM_eAPduFreeAPduInstance(hAPduInst);
}
}

void vDataReceive(PDUM_thAPduInstance hAPduInst)
{
shell_write("In Received\n");
    uint16 u16Offset = 0;
    uint16 payloadSize = PDUM_u16APduInstanceGetPayloadSize(hAPduInst);
 
    DBG_vPrintf(TRUE,"Payloadsize = %d\n",payloadSize);
 
     uint8 value = 0;
   // char *receivedString = (char *)malloc(payloadSize + 1);
 
         PDUM_u16APduInstanceReadNBO(hAPduInst,u16Offset,"b",&value);
         //receivedString[payloadSize] = '\0';
 
    PDUM_eAPduFreeAPduInstance(hAPduInst);
    DBG_vPrintf(TRUE, "Received Data: data = %d\n", value);
   // free(receivedString);
}
 
you can call Send_data function in shell.c file where you are receiving your data in buffer from shell
and you can call data receive function in APP_ZCL_vEventHandler( &psZpsAfEvent->sStackEvent) function like this ( vDataReceive(psStackEvent->uEvent.sApsDataIndEvent.hAPduInst))


warm regards
Tushar Nimesh

 

标签 (2)
0 项奖励
回复
1 回复

506 次查看
Ricardo_Zamora
NXP TechSupport
NXP TechSupport

Hello Tushar,

 

Hope you are doing well. What SDK version are you using?

 

Could you please help me confirm that the devices can communicate correctly? Using those examples without modifications.

For this, please refer to AN12061-MKW41Z-AN-Zigbee-3-0-Base-Device (Path: SDK_FRDM-KW41Z\docs\wireless\Zigbee\Application Notes).

 

Please let me know your findings.

 

Regards,

Ricardo

0 项奖励
回复