This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2538: Send/Receive data between devices on network

Part Number: CC2538
Other Parts Discussed in Thread: Z-STACK, CC2531

HI,
I am using CC2538 dev kit to enable the zigbee network and to esatblish the communication between devices on network. Where enable one of the device as Co-ordinator and one more has End device.
Trying to send the data buf from one to other.

  char *pBuf = "Hi,welcome. We both are on same network, Cheers";
    
    /**/

  endPointDesc_t *epDesc;
  afAddrType_t dstAddr;
  cId_t cId;
  uint8 transId, txOpts, radius;
  uint8 cmd0, cmd1;
  uint8 retValue = ZFailure;
  uint16 dataLen, tempLen;

  
    / Destination address /
  dstAddr.addrMode = AddrBroadcast;
//  dstAddr.addrMode = AddrNotPresent;
  dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR_DEVALL;
//    dstAddr.addrMode = Addr16Bit;
//    dstAddr.addr.shortAddr = _NIB.nwkCoordAddress;
    
    / Destination endpoint /
    dstAddr.endPoint = *pBuf++;
    dstAddr.panId = _NIB.nwkPanId;
    
     / Source endpoint /
//  epDesc = afFindEndPointDesc(*pBuf++);
  epDesc = &ZDApp_epDesc;

  / ClusterId /
  cId = osal_build_uint16( pBuf );
  pBuf +=2;

  / TransId /
  transId = *pBuf++;

  / TxOption /
  txOpts = *pBuf++;

  / Radius /
  radius = AF_DEFAULT_RADIUS;
  
  / Length /
    dataLen = strlen(pBuf);
    
    retValue = AF_DataRequest(&dstAddr, epDesc, cId, dataLen, pBuf, &transId, txOpts, radius);
    HalUARTWrite ( MT_UART_DEFAULT_PORT, "AF Send Msg Done\r\n", strlen("AF Send Msg Done\r\n") );
    
    switch(retValue){
    case afStatus_SUCCESS:
    HalUARTWrite ( MT_UART_DEFAULT_PORT, "afStatus_SUCCESS\r\n", strlen("afStatus_SUCCESS\r\n") );
    break;
    
    case afStatus_FAILED:
    HalUARTWrite ( MT_UART_DEFAULT_PORT, "afStatus_FAILED\r\n", strlen("afStatus_FAILED\r\n") );
    break;
    
    case afStatus_INVALID_PARAMETER:
    HalUARTWrite ( MT_UART_DEFAULT_PORT, "afStatus_INVALID_PARAMETER\r\n", strlen("afStatus_INVALID_PARAMETER\r\n") );
    break;
    
    case afStatus_MEM_FAIL:
    HalUARTWrite ( MT_UART_DEFAULT_PORT, "afStatus_MEM_FAIL\r\n", strlen("afStatus_MEM_FAIL\r\n") );
    break;
    
    case afStatus_NO_ROUTE:
    HalUARTWrite ( MT_UART_DEFAULT_PORT, "afStatus_NO_ROUTE\r\n", strlen("afStatus_NO_ROUTE\r\n") );
    break;
    
    default:
    HalUARTWrite ( MT_UART_DEFAULT_PORT, "afStatus unknown\r\n", strlen("afStatus unknown\r\n") );
    break;
      
    }

This is how I am trying to send from end device, and getting "case afStatus_SUCCESS" all the time and alse "AF_DATA_CONFIRM_CMD" also in the callback.
But no call back's at the co-ordinator side. Is it anything wrong in my case.
Even I tried in reverse also from Co-ordinator to end device same thing is happening, I mean sender is getting success return and ACK also but not visible at receiver.

Checking each and every step from "ZDP_IncomingData()" getting nothing.

And one more thing I am also trying to BIND both but its not happening, I mean Router and End devices are getting bind but same end device is not binding with Co-ordinator can I why it is.
Thanks.

  • You can refer to GenericApp example in Z-Stack 3.0 which shows you how to send "Hello World" between coordinator and end device.
  • Hi,
    I tried Generic App it is doing nothing, can I know position of sending in Generic App project
    Thanks
  • It's my mistake. GenericApp example in Z-Stack 3.0 doesn't show you how to send "Hello World" anymore. You can try to refer to GenericApp example in Z-Stack Mesh 1.0.0.
  • Hi Chen,
    I am not clear, I want to use "Zigbee Stack 3.0" only. Its our requirement.
    Is it anything wrong in my way of trying to send, trying to send for all the devices in a network. i am getting ACK from sender side so, I think it means Data is sent successfully. But Can't see at receiver device.
  • If you want to use Z-Stack 3.0, I suppose it has to be ZCl command based. You can try to create a customer cluster and attribute to use zcl_SendReportCmd to send the data.
  • Hi,

    Please see my code

     afAddrType_t dstAddr;
      
      dstAddr.addrMode = AddrBroadcast;
      dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR_DEVALL;
        dstAddr.endPoint = 0;
        dstAddr.panId = _NIB.nwkPanId;
        
        uint8 srcEP = (char)&ZDApp_epDesc;
        
        zclReportCmd_t *repCmd ;
        
        repCmd->attrList->attrID = 28;
        repCmd->attrList->dataType = 1;
        repCmd->attrList->attrData = "Hi Cheers, We are on same NW";
        repCmd->numAttr = 1;
        
      cId = osal_build_uint16( pBuf );
        uint8 dirtn = 0;
        uint8 disdfltresp = 0;
        uint8 seqnum = 0;
        retValue = zcl_SendReportCmd(srcEP, &dstAddr, cId, repCmd, dirtn, disdfltresp, seqnum);
        
        HalUARTWrite ( MT_UART_DEFAULT_PORT, "Send Msg Done\r\n", strlen("AF Send Msg Done\r\n") );
        
        if(retValue == ZSuccess){
        HalUARTWrite ( MT_UART_DEFAULT_PORT, "Send Msg Success\\r\n", strlen("AF Send Msg Success\r\n") );  
        }else{
        HalUARTWrite ( MT_UART_DEFAULT_PORT, "Send Msg Failed\\r\n", strlen("AF Send Msg Failed\r\n") );
        }

    I am trying like this, but geting failure return.

  • At least, dstAddr.endPoint should not be 0.
  • Hi,
    I changed dstAddr.endPoint to many +ve values, no update.
  • Try to use "dstAddr.addrMode = Addr16Bit" instead of "dstAddr.addrMode = AddrBroadcast".
  • Because you may be mistake something.Please check the following steps:
    1. Target end-device must register the 'endpoint' by calling afRegister();
    2. Current coordinator must register local 'endpoint' by calling afRegister() too;
    3. If coordinator want to sent "hello world" to target end-device , it must provide current registered 'endpoint' and target registered 'endpoint' at the same time,you must guarantee all 'endpoint' correctly.

    I have review your source code, the variable srcEP must registered by afRegister, dstAddr.endPoint must registered by afRegister on target device too.

  • Hi Chen,
    "dstAddr.addrMode = Addr16Bit" and "dstAddr.addr.shortAddr = _NIB.nwkCoordAddress;" but getting fail return
  •   afAddrType_t dstAddr;
      cId_t cId;
      
      uint8 retValue;
      
      
        dstAddr.addrMode = AddrBroadcast;
        dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR_DEVALL;
      
        / Registering Destination endpoint /
        
        uint8 destEP;
        endPointDesc_t *destEPDesc;
        destEPDesc->endPoint = destEP;
        afRegister( destEPDesc );
        / Destination endpoint /
        dstAddr.endPoint = destEPDesc->endPoint;
        
        dstAddr.panId = _NIB.nwkPanId;
        
    / Registering source endpoint /
        
        uint8 srcEP;
        endPointDesc_t *srcEPDesc;
        srcEPDesc->endPoint = srcEP;
        afRegister( srcEPDesc );
        
        
        cId = osal_build_uint16( pBuf );
        
        zclReportCmd_t *repCmd ;
        repCmd->attrList->attrID = 28;
        repCmd->attrList->dataType = 1;
        repCmd->attrList->attrData = pBuf;
        repCmd->numAttr = 1;
        
        uint8 dirtn = 0;
        uint8 disdfltresp = 0;
        uint8 seqnum = 0;
       
    
          retValue = zcl_SendReportCmd(srcEPDesc->endPoint, &dstAddr, cId, repCmd, dirtn, disdfltresp, seqnum);
        
          HalUARTWrite ( MT_UART_DEFAULT_PORT, "Send Msg Done\r\n", strlen("Send Msg Done\r\n") );
        
          if(retValue == ZSuccess){
            HalUARTWrite ( MT_UART_DEFAULT_PORT, "Send Msg Success\r\n", strlen("Send Msg Success\r\n") );  
          }else{
            HalUARTWrite ( MT_UART_DEFAULT_PORT, "Send Msg Failed\r\n", strlen("Send Msg Failed\r\n") );
          }

    Hi hold li,

    pls check my remade code,

    On Co-ordinator side: which is trying to send
    and on the End device side: which has to receive
    endPointDesc_t *epDesc;
    
      // Register the application's endpoint descriptor
      //  - This memory is allocated and never freed.
      epDesc = osal_mem_alloc( sizeof ( endPointDesc_t ) );
      if ( epDesc )
      {
        // Fill out the endpoint description.
        epDesc->endPoint = simpleDesc->EndPoint;
        epDesc->task_id = &zcl_TaskID;   // all messages get sent to ZCL first
        epDesc->simpleDesc = simpleDesc;
        epDesc->latencyReq = noLatencyReqs;
    
        // Register the endpoint description with the AF
        afRegister( epDesc );
      }

    it was done by cal in Generic App, which I am using.
    But the result is the application send is getting success, not getting any  ACK and receiving nothing at the End Device.

    Can you please find why its happening and to resolve.
    Thank you



  • Sorry for incomplete information.
    The first code is done at the co-ordinator side and second was already done by sample application Generic App at the End Device. I am trying to Send for Co-ordinator to End device.
  • You should use unicast if you want to send messages from coordinator to end device.
  • Hi,
    K the reason I am trying to send to all is I dont know how to get the device informations which are in network.
    I mean I connected my devices ZC and ZED in a network but from the Co-ordinator how can I check the my "ZED's short address and endpoint"
    As I don't know this only I am trying to Send to all.
  • Hi,
    I make as like in the document, now how can I Access or know the connected device info
  • If you follow the step 1 and 2 in the link, you would get devAnnce which is a ZDO_DeviceAnnce_t data structure which contains the following information of joined device.

    typedef struct
    {
    uint16 nwkAddr;
    uint8 extAddr[Z_EXTADDR_LEN];
    uint8 capabilities;
    } ZDO_DeviceAnnce_t;
  • Hi,
    I tried like this, but getting the defult values even after connected with ZED. I mean before connect and after connect getting same values

    ZDO_DeviceAnnce_t *ZDO_DeviceAnnce; sprintf(newBuf1, "ZED nwk Addr = %x \r\n", ZDO_DeviceAnnce->nwkAddr); HalUARTWrite ( MT_UART_DEFAULT_PORT, newBuf1, strlen(newBuf1) ); sprintf(newBuf1, "ZED ext Addr = %x \r\n", ZDO_DeviceAnnce->extAddr); HalUARTWrite ( MT_UART_DEFAULT_PORT, newBuf1, strlen(newBuf1) ); sprintf(newBuf1, "ZED capabilities = %x \r\n", ZDO_DeviceAnnce->capabilities); HalUARTWrite ( MT_UART_DEFAULT_PORT, newBuf1, strlen(newBuf1) );

    output:

    ZED nwk Addr = a0d
    ZED ext Addr = 21f382
    ZED capabilities = 0

  • ZDO_DeviceAnnce_t *ZDO_DeviceAnnce;
        
        sprintf(newBuf1, "ZED nwk Addr =       %x \r\n", ZDO_DeviceAnnce->nwkAddr);
        HalUARTWrite ( MT_UART_DEFAULT_PORT, newBuf1, strlen(newBuf1) );
        
        sprintf(newBuf1, "ZED ext Addr =       %x \r\n", ZDO_DeviceAnnce->extAddr);
        HalUARTWrite ( MT_UART_DEFAULT_PORT, newBuf1, strlen(newBuf1) );
        
        sprintf(newBuf1, "ZED capabilities =       %x \r\n", ZDO_DeviceAnnce->capabilities);
        HalUARTWrite ( MT_UART_DEFAULT_PORT, newBuf1, strlen(newBuf1) );



    Hi,
    I tried like this, but getting the defult values even after connected with ZED. I mean before connect and after connect getting same values
  • I think you use wrong way to print hex byte array, ZDO_DeviceAnnce->extAddr. It should be like

    sprintf(newBuf1, "ZED ext Addr = %x%x%x%x%x%x%x%x \r\n", ZDO_DeviceAnnce->extAddr[0],ZDO_DeviceAnnce->extAddr[1],ZDO_DeviceAnnce->extAddr[2],ZDO_DeviceAnnce->extAddr[3],ZDO_DeviceAnnce->extAddr[4],ZDO_DeviceAnnce->extAddr[5],ZDO_DeviceAnnce->extAddr[6],ZDO_DeviceAnnce->extAddr[7]);
  • Hi,
    I tried as like your suggetion but not showing any devices even after calling of ZDO_ParseDeviceAnnce() call by ProcessZDOMsg.
    Device announce is happening but "Endpoint Resp and Descriptor Resp" is not happening can I know when "Endpoint Resp and Descriptor Resp" will happen.
  • Does your application send active endpoint request and simple descriptor request?
  • I guess no, when I has to made these and how.
  • After you get end node announcement, you know device short address and you can use it to call API ZDP_ActiveEPReq to request active endpoint. After you get active endpoint, you can use short address and active endpoint to call ZDP_SimpleDescReq to request simple descriptor.
  • Hi,
    The Document you provide suggesting to use "ZDO_ParseDeviceAnnce" to parse Device announce and similarly "ZDO_ParseEPListRsp and ZDO_ParseSimpleDescRsp" to parse Endpoint list and Simple Desc responses.
    But you are saying to call "ZDP_ActiveEPReq and ZDP_SimpleDescReq" is it correct.

    "ZDO_CB_MSG" only I am processing.

    Just look at my code:
    case ZDO_CB_MSG:
    //To Handle End Node Announcement
    HalUARTWrite ( MT_UART_DEFAULT_PORT, "Processing ZDO Msg\r\n", strlen("Processing ZDO Msg\r\n") );
    zclSampleLight_ProcessZDOMsg((zdoIncomingMsg_t *)MSGpkt);
    break;


    and " After you get end node announcement, you know device short address " I think it is the node address of end device, I can't abl to see this till.
  • If you read the link from beginning, it says "...Then, we usually call ZDP_ActiveEPReq to request active endpoint and register a callback event in Z-Stack to receive active endpoint response and store it to device list. Finally, we can call ZDP_SimpleDescReq to request simple descriptor and register a callback event in Z-Stack to receive simple descriptor response and store it to device list too...."
  • Hi,
    After device announce, its storing
    typedef struct
    {
    uint16 nwkAddr;
    uint8 extAddr[Z_EXTADDR_LEN];
    uint8 capabilities;
    } ZDO_DeviceAnnce_t;

    But,
    ZDP_ActiveEPReq( dstAddr, NWKAddrOfInterest, SecurityEnable );

    ZDP_SimpleDescReq( zAddrType_t *dstAddr, uint16 nwkAddr,
    byte ep, byte SecurityEnable );

    I am confusing to send the arguements, how to get the arguements for above 2 calls
  • dstAddr and NWKAddrOfInterest are short address of device that you want to request. SecurityEnable can be set to 0.
  • static void zclSampleLight_ProcessZDOMsg( zdoIncomingMsg_t *pMsg ){
      ZDO_DeviceAnnce_t devAnnce;
      ZDO_ActiveEndpointRsp_t *pActiveEndpointRsp;
      ZDO_SimpleDescRsp_t simpleDescRsp;
      /**/
      zAddrType_t *dstAddr;
      uint16 nwkAddr;
      byte ep = 0;
      byte SecurityEnable = 0;
      /**/
    
      if ( pMsg->clusterID == Device_annce ){
          HalUARTWrite ( MT_UART_DEFAULT_PORT, "Parsing Device Announce\r\n", strlen("Parsing Device Announce\r\n") );
          ZDO_ParseDeviceAnnce( pMsg, &devAnnce );
          ZDP_ActiveEPReq( dstAddr, nwkAddr, SecurityEnable );
      }
    
      if ( pMsg->clusterID == Active_EP_rsp ){
          HalUARTWrite ( MT_UART_DEFAULT_PORT, "Parsing End point List Announce Response\r\n", strlen("Parsing End point List Announce Response\r\n") );
          pActiveEndpointRsp = ZDO_ParseEPListRsp( pMsg );
          ZDP_SimpleDescReq(dstAddr, nwkAddr, ep, SecurityEnable );
      }
    
      if ( pMsg->clusterID == Simple_Desc_rsp ){
          HalUARTWrite ( MT_UART_DEFAULT_PORT, "Parsing Simple Discript Response\r\n", strlen("Parsing Simple Discript Response\r\n") );
          ZDO_ParseSimpleDescRsp( pMsg, &simpleDescRsp );
      }
    }

    Please look my code, I am trying like this.
    But receiving only device Announce message nothing other than. 

  • You don't assign any address value to dstAddr and nwkAddr. Why do you think it would work normally by just give API null parameters?
  • Hi,
    I assaigned memory like this:
    osal_memset (dstAddr, 0x0, 16);
    osal_memset (&nwkAddr, 0x0, 16);

    Till device announce only happening. But every time I was getting defferent values of ZED NW Addr and ZED Ext Addr, I am calling like this

    ZDO_DeviceAnnce_t ZDO_DeviceAnnceNew;
    sprintf(newBuf1, "ZED nwk Addr = %x \r\n", ZDO_DeviceAnnceNew.nwkAddr);
    HalUARTWrite ( MT_UART_DEFAULT_PORT, newBuf1, strlen(newBuf1) );

    sprintf(newBuf1, "ZED ext Addr = %x %x %x %x %x %x %x %x \r\n", ZDO_DeviceAnnceNew.extAddr[0], ZDO_DeviceAnnceNew.extAddr[1],\
    ZDO_DeviceAnnceNew.extAddr[2], ZDO_DeviceAnnceNew.extAddr[3], ZDO_DeviceAnnceNew.extAddr[4], ZDO_DeviceAnnceNew.extAddr[5], \
    ZDO_DeviceAnnceNew.extAddr[6], ZDO_DeviceAnnceNew.extAddr[7]);
    HalUARTWrite ( MT_UART_DEFAULT_PORT, newBuf1, strlen(newBuf1) );

    sprintf(newBuf1, "ZED capabilities = %c \r\n", ZDO_DeviceAnnceNew.capabilities);
    HalUARTWrite ( MT_UART_DEFAULT_PORT, newBuf1, strlen(newBuf1) );

    Thank you.
  • Hi,
    Can I get the devices in network by calling neighbour LQI request
  • If you don't enable NV_RESTORE, short address might change when device resets and join the network. However, IEEE address shouldn't change. Can you show me your IEEE address result?
  • on ZC side or ZED side you are asking IEEE addr
  • On the side you see different IEEE address every time.
  • Hi,
    I am trying to read IEEE addr like this,

    int macaddr[8] = MT_SYS_GET_EXTADDR;
    sprintf(newBuf1, "IEEE Addr %x %x %x %x %x %x %x %x \r\n", macaddr[0], macaddr[1], macaddr[2], macaddr[3], \
    macaddr[4], macaddr[5], macaddr[6], macaddr[7] );

    O/P:
    IEEE Addr 4 0 0 0 0 0 0 0

    and
    sprintf(newBuf1, "IEEE Addr %x ", MT_SYS_GET_EXTADDR);

    O/P:
    IEEE Addr 4

    "SYS_GET_EXTADDR" not in my any projects so tried for "MT_SYS_GET_EXTADDR"
    and intialized the MT task too by defining MT_TASK macro TRUE
  • MT_SYS_GET_EXTADDR is a MACRO define so it won't give you IEEE address.
  • Then how to get the IEEE addr
  • Hi,
    I enable the "NV_RESTORE " in "nwk_globals.h" like,
    #define NV_RESTORE TRUE
  • If you intend to get the IEEE address of itself, you can use API NLME_GetExtAddr to get it.
  • To enable NV_RESTORE, you should add it in Project->Options-> C/C++ Compiler->Preprocessor->Defined symbols.

  • Hi,
    my main intention is to establish transmission between the devices in the network, specially from ZC to ZR or ZED and vice versa
  • I think if you play with SampleLight and SampleSwitch, they already show you the transmission between them.
  • In other way I am trying to bind the my ZC and ZED its not happening but its happening between ZR and ZED.
    Q1) How to achieve bind between ZC and ZED or ZR ?
    Q2) What is the bind limit for ZC, I mean what is the limit for 1 ZC to bind with ZR or ZED ?
  • I am trying these apps only but transmission is not found in any of the example projects, So I am struggling.
  • I suppose you are testing Z-Stack 3.0. Do you read Z-Stack 3.0 Sample Application User's Guide?
  • Yes, I read that. But it not seems transmission happening
  • When you test SampleLight (ZC) /SampleSwitch (ZED) , do you see SampleSwitch joins SampleLight? Do you use sniffer to check it?
  • Hi,
    I tried only Sample Light for both ZC and ZED. Ok now I will make Sample Switch has ZED, then I am not using Sniffer I don't know how to use Sniffer