I am new to Zigbee and I've been trying simple data transfer between two JN5168-001-M00 modules , using Zigbee 3.0 ( JN-SW- 4170 ) and Application Note AN 1229.
The destination get notified correctly when a message arrives , yet I couldn't read the payload successfully.
on the SED node
PDUM_thAPduInstance myInstance =PDUM_hAPduAllocateAPduInstance(apduMyData);
PDUM_u16APduInstanceWriteNBO(myInstance,0,"b",5);
ZPS_teStatus myStatus= ZPS_eAplAfBroadcastDataReq(myInstance,1234,1,255,ZPS_E_BROADCAST_ZC_ZR,ZPS_E_APL_AF_UNSECURE,0,NULL);
on the coordinator endpoint
uint8 u8Payload;
PDUM_u16APduInstanceReadNBO(sStackEvent.uEvent.sApsDataIndEvent.hAPduInst,0,'b',&u8Payload);
whatever the message I try at the SED node , when I check the payload of the coming message it gives 0.
Any one can help ?
Thanks in advance .
已解决! 转到解答。
Certainly odd, I just added a ReadNBO (lines 11-14), rebuild SED and broadcast from Coordinator and it works.
case ZPS_EVENT_APS_DATA_INDICATION:
{
DBG_vPrintf(TRACE_APP, "APP: APP_taskEndPoint: ZPS_EVENT_AF_DATA_INDICATION\n");
/* Process incoming cluster messages for this endpoint... */
DBG_vPrintf(TRACE_APP, " Data Indication:\r\n");
DBG_vPrintf(TRACE_APP, " Profile :%x\r\n",sStackEvent.uEvent.sApsDataIndEvent.u16ProfileId);
DBG_vPrintf(TRACE_APP, " Cluster :%x\r\n",sStackEvent.uEvent.sApsDataIndEvent.u16ClusterId);
DBG_vPrintf(TRACE_APP, " EndPoint:%x\r\n",sStackEvent.uEvent.sApsDataIndEvent.u8DstEndpoint);
uint8 u8TempPayload;
uint16 u16bytesread;
u16bytesread = PDUM_u16APduInstanceReadNBO(sStackEvent.uEvent.sApsDataIndEvent.hAPduInst,0,"b",&u8TempPayload);
DBG_vPrintf(TRACE_APP, "Read: %d, Data: %c", u16bytesread, u8TempPayload);
/* free the application protocol data unit (APDU) once it has been dealt with */
PDUM_eAPduFreeAPduInstance(sStackEvent.uEvent.sApsDataIndEvent.hAPduInst);
}
Do you have any APDU changes to ZBProAppTemplate.zpscfg ?
Edit: I'll try the reverse like your case, SED -> Coordinator.
Just hardcoded a quick broadcast code to the SED. It works.
PUBLIC void vWakeCallBack(void)
{
/* schedule device to go to sleep, then poll for data */
DBG_vPrintf(TRACE_APP, "APP: Polling for data\n");
ZPS_eAplZdoPoll();
//
uint8 u8TransactionSequenceNumber;
ZPS_tsNwkNib * thisNib;
thisNib = ZPS_psNwkNibGetHandle(ZPS_pvAplZdoGetNwkHandle());
PDUM_thAPduInstance hAPduInst;
hAPduInst = PDUM_hAPduAllocateAPduInstance(apduMyData);
uint16 u16Offset = 0;
uint16 i;
// Fill hAPDU payload
u16Offset = 0;
uint8 buffer[] = "idontknow";
for (i = 0; i < 5; i++) {
u16Offset += PDUM_u16APduInstanceWriteNBO(hAPduInst, u16Offset,"b", *(buffer + i));
DBG_vPrintf(TRUE, "%c", *(buffer + i));
}
PDUM_eAPduInstanceSetPayloadSize(hAPduInst, u16Offset);
DBG_vPrintf(TRUE, "Size : %d\nSending : \n", PDUM_u16APduInstanceGetPayloadSize(hAPduInst));
if (hAPduInst == PDUM_INVALID_HANDLE)
{
DBG_vPrintf(TRUE, "PDUM_INVALID_HANDLE\n");
} else {
ZPS_teStatus eStatus;
ZPS_teAplAfSecurityMode eSecurityMode = (ZPS_E_APL_AF_SECURE_NWK);
eStatus = ZPS_eAplAfBroadcastDataReq( hAPduInst,
0x1337,
0x01,
0x01,
ZPS_E_BROADCAST_ZC_ZR, // Dest: All Coordinator & Routers
eSecurityMode,
0,
&u8TransactionSequenceNumber
);
}
}
Result from Coordinator,
APP: APP_taskEndPoint: ZPS_EVENT_AF_DATA_INDICATION
Data Indication:
Profile :1234
Cluster :1337
From :4e99
EndPoint:1
Payload Length:5
Payload : idont
Hello davidashraf , mario_castaneda,
i am transmitting data from SED to Coordinator, as per above discussion.
But can you tell me how to get ack from Coordinator because i want reply from coordinator that my Message is delivered or not?
please need your help!
Thank You for your Time!
Hi, please have a search for 'PDUM_u16APduInstanceWriteNBO' in the file "C:\NXP\bstudio_nxp\sdk\JN-SW-4170\Components\ZCIF\Source\zcl.c" for some usage on that API.
Try to also set the setsize or setpayloadsize.
Hi , Thanks for your reply
I've tried this and I don't think the problem is in writing the payload at the sender node
I tried debugging the instance returned on event occurrence at the receiver node and it gives me invalid handle!
This is how I deal with the coming message
uint8 u8Payload;
PDUM_u16APduInstanceReadNBO(sStackEvent.uEvent.sApsDataIndEvent.hAPduInst,0,'b',&u8Payload);
on trying to print the value of 'u8Payload' it always gives me '0' not matter the actual payload I wrote on the sender node
and also by trying checking the handle 'sStackEvent.uEvent.sApsDataIndEvent.hAPduInst' it gives invalid handle!
Sorry, did not see this part.
The destination get notified correctly when a message arrives , yet I couldn't read the payload successfully.
Please have a look at appZdpExtraction.c under the function zps_bAplZdpUnpackNwkUpdateNotifyResponse.
Can you show me the code you tried at the coordinator for sending , please ?
maybe the problem is in sending as I already tried the same code you used for receiving ,yet still failing to read payload correctly
Sending as broadcast or else, you need to access the network table to fetch router's address, etc etc.
Usage:
APP_vSendPayload_Bcast(tempbuf,9,CLUSTER_ID);
Parameters:
tempbuf = array of bytes,
length = length to send,
CLUSTER ID = get from zps_gen.h
Edit: Oh it sends to endpoint 0x01
PUBLIC void APP_vSendPayload_Bcast(const uint8 *buffer, uint16 length, uint16 clusterID) {
uint8 u8TransactionSequenceNumber;
ZPS_tsNwkNib * thisNib;
thisNib = ZPS_psNwkNibGetHandle(ZPS_pvAplZdoGetNwkHandle());
PDUM_thAPduInstance hAPduInst;
hAPduInst = PDUM_hAPduAllocateAPduInstance(apduMyData);
uint16 u16Offset = 0;
uint16 i;
// Fill hAPDU payload
u16Offset = 0;
if (length < PDUM_u16APduGetSize(hAPduInst)) {
for (i = 0; i < length; i++) {
u16Offset += PDUM_u16APduInstanceWriteNBO(hAPduInst, u16Offset,"b", *(buffer + i));
DBG_vPrintf(TRACE_TRANSMIT, "%c", *(buffer + i));
}
PDUM_eAPduInstanceSetPayloadSize(hAPduInst, u16Offset);
} else {
DBG_vPrintf(TRACE_TRANSMIT, "ERR: Payload length exceeded\n");
}
DBG_vPrintf(TRACE_TRANSMIT, "Size : %d\nSending : \n", PDUM_u16APduInstanceGetPayloadSize(hAPduInst));
if (hAPduInst == PDUM_INVALID_HANDLE)
{
DBG_vPrintf(TRACE_TRANSMIT, "PDUM_INVALID_HANDLE\n");
} else {
ZPS_teStatus eStatus;
ZPS_teAplAfSecurityMode eSecurityMode = (ZPS_E_APL_AF_SECURE_NWK);
eStatus = ZPS_eAplAfBroadcastDataReq( hAPduInst,
clusterID,
0x01,
0x01,
ZPS_E_BROADCAST_ZC_ZR, // Dest: All Coordinator & Routers
eSecurityMode,
0,
&u8TransactionSequenceNumber
);
}
}
I tried that but
when I debug as follows at the receiving node
if (sStackEvent.uEvent.sApsDataIndEvent.hAPduInst==PDUM_INVALID_HANDLE)
{
DBG_vPrintf(TRACE_APP, "Invalid Handle \n");
}else{
DBG_vPrintf(TRACE_APP, "Valid Handle\n");
}
It gives " Invalid Handle "!
Also when trying to read the payload :
u16BytesRead=PDUM_u16APduInstanceReadNBO(sStackEvent.uEvent.sApsDataIndEvent.hAPduInst,u16PayloadPos,"b",&u8Payload);
DBG_vPrintf(TRACE_APP, " PayloadSize:%x\r\n",u16BytesRead);
It gives 0!
You need to call your ReadNBO routine at :
vHandleStackEvent in app_router or
APP_vtaskMyEndPoint in app_endpoint
It gets cleared as soon as it exits the function vHandleStackEvent or APP_vtaskMyEndPoint.
The stack processes the Event only once then forgets all about it as soon as it leaves the 2 function above.
You may not declare ZPS_tsAfEvent sStackEvent; anywhere in the program and ReadNBO it.
( at least I think what is happening here )
I am trying to send from a SED to the coordinator
I call ReadNBO at : APP_vtaskMyEndPoint in app_endpoint
The strange thing is that the message arrives and get collected
and by debugging :
DBG_vPrintf(TRACE_APP, " Profile :%x\r\n",sStackEvent.uEvent.sApsDataIndEvent.u16ProfileId);
DBG_vPrintf(TRACE_APP, " Cluster :%x\r\n",sStackEvent.uEvent.sApsDataIndEvent.u16ClusterId);
DBG_vPrintf(TRACE_APP, " EndPoint:%x\r\n",sStackEvent.uEvent.sApsDataIndEvent.u8DstEndpoint);t doesn't make any sens
it gives the right data ( profile ID , cluster ID , Dest End point )
only it fails to read the payload and finds the apdu instance invalid!!
Certainly odd, I just added a ReadNBO (lines 11-14), rebuild SED and broadcast from Coordinator and it works.
case ZPS_EVENT_APS_DATA_INDICATION:
{
DBG_vPrintf(TRACE_APP, "APP: APP_taskEndPoint: ZPS_EVENT_AF_DATA_INDICATION\n");
/* Process incoming cluster messages for this endpoint... */
DBG_vPrintf(TRACE_APP, " Data Indication:\r\n");
DBG_vPrintf(TRACE_APP, " Profile :%x\r\n",sStackEvent.uEvent.sApsDataIndEvent.u16ProfileId);
DBG_vPrintf(TRACE_APP, " Cluster :%x\r\n",sStackEvent.uEvent.sApsDataIndEvent.u16ClusterId);
DBG_vPrintf(TRACE_APP, " EndPoint:%x\r\n",sStackEvent.uEvent.sApsDataIndEvent.u8DstEndpoint);
uint8 u8TempPayload;
uint16 u16bytesread;
u16bytesread = PDUM_u16APduInstanceReadNBO(sStackEvent.uEvent.sApsDataIndEvent.hAPduInst,0,"b",&u8TempPayload);
DBG_vPrintf(TRACE_APP, "Read: %d, Data: %c", u16bytesread, u8TempPayload);
/* free the application protocol data unit (APDU) once it has been dealt with */
PDUM_eAPduFreeAPduInstance(sStackEvent.uEvent.sApsDataIndEvent.hAPduInst);
}
Do you have any APDU changes to ZBProAppTemplate.zpscfg ?
Edit: I'll try the reverse like your case, SED -> Coordinator.
Just hardcoded a quick broadcast code to the SED. It works.
PUBLIC void vWakeCallBack(void)
{
/* schedule device to go to sleep, then poll for data */
DBG_vPrintf(TRACE_APP, "APP: Polling for data\n");
ZPS_eAplZdoPoll();
//
uint8 u8TransactionSequenceNumber;
ZPS_tsNwkNib * thisNib;
thisNib = ZPS_psNwkNibGetHandle(ZPS_pvAplZdoGetNwkHandle());
PDUM_thAPduInstance hAPduInst;
hAPduInst = PDUM_hAPduAllocateAPduInstance(apduMyData);
uint16 u16Offset = 0;
uint16 i;
// Fill hAPDU payload
u16Offset = 0;
uint8 buffer[] = "idontknow";
for (i = 0; i < 5; i++) {
u16Offset += PDUM_u16APduInstanceWriteNBO(hAPduInst, u16Offset,"b", *(buffer + i));
DBG_vPrintf(TRUE, "%c", *(buffer + i));
}
PDUM_eAPduInstanceSetPayloadSize(hAPduInst, u16Offset);
DBG_vPrintf(TRUE, "Size : %d\nSending : \n", PDUM_u16APduInstanceGetPayloadSize(hAPduInst));
if (hAPduInst == PDUM_INVALID_HANDLE)
{
DBG_vPrintf(TRUE, "PDUM_INVALID_HANDLE\n");
} else {
ZPS_teStatus eStatus;
ZPS_teAplAfSecurityMode eSecurityMode = (ZPS_E_APL_AF_SECURE_NWK);
eStatus = ZPS_eAplAfBroadcastDataReq( hAPduInst,
0x1337,
0x01,
0x01,
ZPS_E_BROADCAST_ZC_ZR, // Dest: All Coordinator & Routers
eSecurityMode,
0,
&u8TransactionSequenceNumber
);
}
}
Result from Coordinator,
APP: APP_taskEndPoint: ZPS_EVENT_AF_DATA_INDICATION
Data Indication:
Profile :1234
Cluster :1337
From :4e99
EndPoint:1
Payload Length:5
Payload : idont
Hello Lim,
I was little bit confuse about this data transfer between SED to Co-ordinator.
but after so many try and error it become successful :smileyhappy: to data transfer between SED to CO-Ordinator.
But,
Now i am trying to send data from Co-Ordinator to SED and i don't know how to start from co-ordinator.
need your help.
Thank You for Your Time!
Hello Sir,
I am doing the same thing but its showing me error
!!! Alignment error
i check the code this error comes after
thisNib = ZPS_psNwkNibGetHandle(ZPS_pvAplZdoGetNwkHandle());
i read thisNib Value its show
thisNib Read : 4001944
i think problem is in this line--> hAPduInst = PDUM_hAPduAllocateAPduInstance(apduMyData);
After that i saw below message
!!! Alignment error
u32PICMR = 0 : u32PICSR = 8
u32PICMSR = 0 : u32IPMR = 4
u32IHPR = 7 : u32AINT = 8 u32PINT 0
EPCR = 8840b : EEAR = deadbf55
then long values comes continuously
4007a18 : 0000000c
4007a1c : 0008840b
4007a20 : deadbf55
4007a24 : 00000000
4007a28 : 00000007
4007a2c : 00000004
4007a30 : 00000008
4007a34 : 00000000
4007a38 : 00000000
Like this and
after that my
device reset by watchdog timer
APP: Power Up
APP: Watchdog timer has reset device!
:smileysad: too bad for me.
can i get your help.
Please need your help!
Thank you for your Time!
Hi,Lim.I use this code to send and read data in the 1184 demo project. But when try to continuouos send data,everything seems ok with the first tow datas, but the coordinator can't receive any data after that while the debug message from the enddevice show show the data is sent successfully.And when enddevice sends the 8th data, the debug message began to show "No free MCPS request descriptor" error. Has you ever encountered this problem?
Hello Sir,
I am working on ZigBeePro Stack. I have install ZPS Editor.
and set parameter as per JN-UG-3113 PDF.
i create APDU by name "TestApdu" in Sleeping Endevice.
i have added screen shot so you will understand better.
how to remove that error?
please suggest me something.
i am really stuck on it.
Thank You For Your Reply.