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.

how could we design samplelight device to control two or more light ?

Hi 

     there is a sample code (sample light )which was supply by zstack ,it is ok to control one light in the device。

     if  there is two light were connected  in the same device。

     how could we change the sample code to achieve it ?

    

     as i though , it needs adding a new endpoint,one endpoint control one light 。

     and  is that ok to copy  zcl_samplelight.c   ,zcl_samplelight_data.c,zcl_samplelight.h     as zcl_samplelight-1.c   ,zcl_samplelight_data-1.c,zcl_samplelight-1.h

     then just change the endpiont value and all samplelight name to samplelight-1?

     Or  there is more step need to be do ?

BR

  • You need to use multiple endpoint on your device. You can refer to processors.wiki.ti.com/.../Multi-endpoint_device_implementation
  • Hi Yikai
    i also did not know how to get key events

    there is a word "the registered task that has received a key event may need to pass it to other tasks."

    but how could i do that ?

    now it seems that the keyevents only being get by the first registered endpoint


    just like that
    Example 1 : samplelight1 get the key event and samplelight could not get it

    {
    .....
    zclsamplelight1_event_loop,
    zclSampleLight_event_loop
    }

    Example 2 : samplelight get the key event and samplelight1 could not get it

    {
    .....
    zclsamplelight_event_loop,
    zclSampleLight1_event_loop
    }


    BR
  • Sorry for i careless, i got the point 。 i am tring
  • You can process key event in zclsamplelight_event_loop. There is no need to have two event loop.

  • do you mean two endpoint only use the same taskID?
  • Basically, yes.
  • but when we register the zcl call back function,

    is that like

      // Register the ZCL General Cluster Library callback functions
      zclGeneral_RegisterCmdCallbacks( SAMPLELIGHT1_ENDPOINT, &zclSampleLight_CmdCallbacks );

      // Register the ZCL General Cluster Library callback functions
      zclGeneral_RegisterCmdCallbacks( SAMPLELIGHT2_ENDPOINT, &zclSampleLight_CmdCallbacks );

    static zclGeneral_AppCallbacks_t zclSampleLight1_CmdCallbacks =
    {
      zclSampleLight1_BasicResetCB,            // Basic Cluster Reset command
      zclSampleLight1_IdentifyCB,              // Identify command
    #ifdef ZCL_EZMODE
      NULL,                                   // Identify EZ-Mode Invoke command
      NULL,                                   // Identify Update Commission State command
    #endif
      NULL,                                   // Identify Trigger Effect command
      zclSampleLight1_IdentifyQueryRspCB,      // Identify Query Response command
      zclSampleLight1_OnOffCB,                 // On/Off cluster commands
      。。。
    };

    static zclGeneral_AppCallbacks_t zclSampleLight2_CmdCallbacks =
    {
      zclSampleLight2_BasicResetCB,            // Basic Cluster Reset command
      zclSampleLight2_IdentifyCB,              // Identify command
    #ifdef ZCL_EZMODE
      NULL,                                   // Identify EZ-Mode Invoke command
      NULL,                                   // Identify Update Commission State command
    #endif
      NULL,                                   // Identify Trigger Effect command
      zclSampleLight2_IdentifyQueryRspCB,      // Identify Query Response command
      zclSampleLight2_OnOffCB,                 // On/Off cluster commands
      。。。
    };

    anyway,there is not only ZCL callback function,but also a lot function need to be different with each endpoint,so i think if all control was used same task

    that will be so complicated

  • What else do you need to be different for each endpoint?

  • yeah ,maybe there is not any more function need to be different with each endpoint,

    void zclSampleLight_Init( byte task_id )
    {
      zclSampleLight_TaskID = task_id;

      // Set destination address to indirect
      zclSampleLight_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent;
      zclSampleLight_DstAddr.endPoint = 0;
      zclSampleLight_DstAddr.addr.shortAddr = 0;

      // This app is part of the Home Automation Profile
      zclHA_Init( &zclSampleLight_SimpleDesc );
      // This app is part of the Home Automation Profile
      zclHA_Init( &zclSampleLight1_SimpleDesc );
     
      // Register the ZCL General Cluster Library callback functions for light
      zclGeneral_RegisterCmdCallbacks( SAMPLELIGHT_ENDPOINT, &zclSampleLight_CmdCallbacks );
      // Register the ZCL General Cluster Library callback functions for light1
      zclGeneral_RegisterCmdCallbacks( SAMPLELIGHT1_ENDPOINT, &zclSampleLight1_CmdCallbacks );
     
      // Register the application's attribute list
      zcl_registerAttrList( SAMPLELIGHT_ENDPOINT, zclSampleLight_NumAttributes, zclSampleLight_Attrs );
      // Register the application's attribute list
      zcl_registerAttrList( SAMPLELIGHT1_ENDPOINT, zclSampleLight1_NumAttributes, zclSampleLight1_Attrs );
     
      // Register the Application to receive the unprocessed Foundation command/response messages
      zcl_registerForMsg( zclSampleLight_TaskID );

    #ifdef ZCL_DISCOVER
      // Register the application's command list
      zcl_registerCmdList( SAMPLELIGHT_ENDPOINT, zclCmdsArraySize, zclSampleLight_Cmds );
      zcl_registerCmdList( SAMPLELIGHT1_ENDPOINT, zclCmdsArraySize, zclSampleLight1_Cmds );
    #endif

      // Register for all key events - This app will handle all key events
      RegisterForKeys( zclSampleLight_TaskID );

      // Register for a sampleLight endpoint
      afRegister( &sampleLight_TestEp );
      // Register for a sampleLight1 endpoint
      afRegister( &sampleLight1_TestEp );
    #ifdef ZCL_EZMODE
      // Register EZ-Mode
      zcl_RegisterEZMode( &zclSampleLight_RegisterEZModeData );

    zcl_RegisterEZMode( &zclSampleLight1_RegisterEZModeData );

      // Register with the ZDO to receive Match Descriptor Responses
      ZDO_RegisterForZDOMsg(task_id, Match_Desc_rsp);
    #endif

    #ifdef ZCL_DIAGNOSTIC
      // Register the application's callback function to read/write attribute data.
      // This is only required when the attribute data format is unknown to ZCL.
      zcl_registerReadWriteCB( SAMPLELIGHT_ENDPOINT, zclDiagnostic_ReadWriteAttrCB, NULL );

     zcl_registerReadWriteCB( SAMPLELIGHT1_ENDPOINT, zclDiagnostic_ReadWriteAttrCB, NULL );

    #endif
    }

    but i am curious about how could the ZC  knows  there are two endpoint on the new ZD while success joining the network?

    i found that the structure of the zdoIncomingMsg_t which came from the  zclxxx_ProcessZDOMsgs( zdoIncomingMsg_t *pMsg )

    typedef struct
    {
      osal_event_hdr_t hdr;
      zAddrType_t      srcAddr;
      uint8            wasBroadcast;
      cId_t            clusterID;
      uint8            SecurityUse;
      uint8            TransSeq;
      uint8            asduLen;
      uint16           macDestAddr;
      uint8            *asdu;
      uint16           macSrcAddr;
    } zdoIncomingMsg_t;

    there is not any item about the endpoint info

  • When there is a device join Zigbee network, it will broadcast end node announcement with its short and IEEE address. You can use ZDP_ActiveEPReq to request active endpoint.

  • hi yikai,

           when a device ZED joining the network, i could catch the  Device_annce,and i use ZDP_ActiveEPReq(&pMsg->srcAddr,pMsg->srcAddr.addr.shortAddr,0);

           but i could not catch Active_EP_rsp ,

          does it need to do something in the ZED side?

    static void zclIASCIE_ProcessZDOMsgs( zdoIncomingMsg_t *pMsg )
    {


      zclEZMode_ActionData_t data;
      ZDO_MatchDescRsp_t *pMatchDescRsp;
      ZDO_ActiveEndpointRsp_t *pActiveEndpoint;
     
      switch(pMsg->clusterID)
      {
          
      case Device_annce: // recevie a new device and pritnf its IEEE
      
        // get the endpiont of the devices 
        ZDP_ActiveEPReq(&pMsg->srcAddr,pMsg->srcAddr.addr.shortAddr,0);

         break;
     
      case Active_EP_rsp:
          pActiveEndpoint = ZDO_ParseEPListRsp( pMsg );
    #ifdef UartShow
      HalUARTWrite(0,"Get ActiveEndpoint Success\n", sizeof("Get ActiveEndpoint Success\n"));
    #endif

          osal_mem_free( pActiveEndpoint );
          break;      
      
      default:
        break;
         
      }
    }

  • oh ,sorry , i forgot to regsiter the Active_EP_req
  • Yes, you have to to regsiter the Active_EP_rsp.
  • could i adding ZDO_ACTIVEEP_REQUEST complies options in the ZC side?
  • Yes, you can.
  • Adding the complies option will cause a lot of warning “ Warning[Pe047]: incompatible redefinition of macro "ZDO_ACTIVEEP_REQUEST" happen。

    i have resistor the Active_EP_rsp, but when the samplelight (ZED including two endpoint) finish join,
    i also could catch the Active_EP_rsp》》》
  • You can define MT_ZDO_FUNC instead of ZDO_ACTIVEEP_REQUEST. THis will include ZDO_ACTIVEEP_REQUEST define.
  • Hi Yikai , the right method of getting Active_EP_rsp should be like this

    1. define the Msg type : ZDO_DeviceAnnce_t Imsg;
    2. parse the address :ZDO_ParseDeviceAnnce(pMsg, &Imsg);
    3. adding the address in the function
    zAddrType_t dstAddr;
    dstAddr.addrMode = Addr16Bit;
    dstAddr.addr.shortAddr = Imsg.nwkAddr;

    ZDP_ActiveEPReq(&dstAddr,dstAddr.addr.shortAddr,0);

    if you getting the address in zdoIncomingMsg_t *pMsg directly,and adding in the function like this
    ZDP_ActiveEPReq(&pMsg->srcAddr,pMsg->srcAddr.addr.shortAddr,0);

    you couldn't get anything ...
  • Yes, I know this. You can refer to my replies in e2e.ti.com/.../1396652