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 to make two Generic APP autobind (i.e no need to press switch for binding two generic APP)

Other Parts Discussed in Thread: CC2538, Z-STACK

Hello All,

I am using zstack mesh 1.0.0 and cc2538.

i am successfully able to bind two generic App device (ZC and ZR) and i am able to send and  receive msg properly but i hav a problem ->

1) to make two device bind we needed to press sw 2 or sw 4 on both the device then they start binding process and after that we can send and receive the data... but i dont want to press the switch for binding....

what i want is that as soon as i switched on the device they should start the binding process and should be able to communicate properly..... in short -> i dont want to press sw for binding it should be auto-binding....

is there anyone who can help me how can i do that ?

how can i remove the manual binding press in generic app project ?

anyone plz help me to solve this issue....

Thanks & Regards,

Maneesh singh

  • You can try to send end device binding request or start ez-mode from both ZC and ZR after device gets ZDO_STATE_CHANGE. However, it is insecure and might be failure since the timing of ZDO_STATE_CHANGE between ZR and ZC might not be very closed. If ZC and ZR are powered on almost at the same time, my approach should work.
  • Hello YiKai Chen sir,

    Thanks for reply.........

    As u suggested i tried to implement EZ-MODE in Generic APP...... i took the reference from zstack HA temp sensor and thermostat projects....

    i tried to do same thing as given in these projects.....but i am getting an error and an warning saying that ->

    Error[Pe114]: function "GenericApp_EZModeCB" was referenced but not defined C:\Texas Instruments\Z-Stack Mesh 1.0.0\Projects\zstack\Samples\GenericApp - Copy\Source\GenericApp.c 161


    Warning[Pe177]: variable "GenericApp_RegisterEZModeData" was declared but never referenced C:\Texas Instruments\Z-Stack Mesh 1.0.0\Projects\zstack\Samples\GenericApp - Copy\Source\GenericApp.c 162

    even though i implemented the GenericApp_EZModeCB fn in my code ->

    static void GenericApp_EZModeCB( zlcEZMode_State_t state, zclEZMode_CBData_t *pData )
    {

    }

    and i am using GenericApp_RegisterEZModeData for registering EZ-Mode ->

    // Register EZ-Mode
    zcl_RegisterEZMode( &GenericApp_RegisterEZModeData );

    here is my code snapshot or you can code pieces which i wrote for EZ-MODE =>

    1) 

    #ifdef ZCL_EZMODE
    static void GenericApp_EZModeCB( zlcEZMode_State_t state, zclEZMode_CBData_t *pData );
    static const zclEZMode_RegisterData_t GenericApp_RegisterEZModeData =
    {
    &GenericApp_TaskID,
    GENERICAPP_EZMODE_NEXTSTATE_EVT,
    GENERICAPP_EZMODE_TIMEOUT_EVT,
    &GenericAppSeqNum,
    GenericApp_EZModeCB
    };

    // NOT ZCL_EZMODE, Use EndDeviceBind
    #else

    2)

    static zclGeneral_AppCallbacks_t GenericApp_CmdCallbacks =
    {
    NULL,                                                               // Basic Cluster Reset command
    GenericApp_IdentifyCB,                             // Identify command
    #ifdef ZCL_EZMODE
    NULL,                                                            // Identify EZ-Mode Invoke command
    NULL,                                                           // Identify Update Commission State command
    #endif
    NULL,                                                            // Identify Trigger Effect command
    GenericApp_IdentifyQueryRspCB,        // Identify Query Response command
    NULL,

    ...................

    }

    3) 

    // Register the ZCL General Cluster Library callback functions
    zclGeneral_RegisterCmdCallbacks( GENERICAPP_ENDPOINT, &GenericApp_CmdCallbacks );


    #ifdef ZCL_EZMODE

    // Register EZ-Mode
    zcl_RegisterEZMode( &GenericApp_RegisterEZModeData );

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

    4)

    #ifdef ZCL_EZMODE
    // going on to next state
    if ( events & GENERICAPP_EZMODE_NEXTSTATE_EVT )
    {
    zcl_EZModeAction ( EZMODE_ACTION_PROCESS, NULL ); // going on to next state
    return ( events ^ GENERICAPP_EZMODE_NEXTSTATE_EVT );
    }

    // the overall EZMode timer expired, so we timed out
    if ( events & GENERICAPP_EZMODE_TIMEOUT_EVT )
    {
    zcl_EZModeAction ( EZMODE_ACTION_TIMED_OUT, NULL ); // EZ-Mode timed out
    return ( events ^ GENERICAPP_EZMODE_TIMEOUT_EVT );
    }
    #endif // ZLC_EZMODE

     

    5) 

    void binding_started()
    {
    #ifdef ZCL_EZMODE
    zclEZMode_InvokeData_t ezModeData;
    // static uint16 clusterIDs[] = { ZCL_CLUSTER_ID_HVAC_THERMOSTAT }; // only bind on the Thermostat cluster
    static uint16 clusterIDs[] = { GENERICAPP_CLUSTERID };
    // Invoke EZ-Mode
    ezModeData.endpoint = GENERICAPP_ENDPOINT; // endpoint on which to invoke EZ-Mode
    if ( ( GenericApp_NwkState == DEV_ZB_COORD ) ||
    ( GenericApp_NwkState == DEV_ROUTER ) ||
    ( GenericApp_NwkState == DEV_END_DEVICE ) )
    {
    ezModeData.onNetwork = TRUE; // node is already on the network
    }
    else
    {
    ezModeData.onNetwork = FALSE; // node is not yet on the network
    }
    ezModeData.initiator = TRUE; // Thermostat is an initiator
    ezModeData.numActiveInClusters = 0;
    ezModeData.pActiveInClusterIDs = NULL;
    ezModeData.numActiveOutClusters = 1; // active output cluster
    ezModeData.pActiveOutClusterIDs = clusterIDs;
    zcl_InvokeEZMode( &ezModeData );

    #endif // ZCL_EZMODE
    }

    6) 

    static void GenericApp_EZModeCB( zlcEZMode_State_t state, zclEZMode_CBData_t *pData )
    {.......

    ..........  same as temp sensor and thermostat projects.....

    }

    7)

    in OSAL_GenericApp file i am adding these lines -->

    zcl_event_loop,  and 

    zcl_Init( taskID++ 

    8) i am attaching and sending you my source code along with this post for your reference.....plz check it once and tell me what i am doing wrong ? 

    plz once hav a look at my source code sir....plz...

    i am using zstack mesh 1.0.0 stack and cc2538 ....

    Thanks & Regards,

    Maneesh singh

  • Hello YiKai Chen sir,

    i am not attach the files in the post.... becoz no tab/button is provided in this new look of Forum.... there is a tab/button to post pics & other media but not the files.....so i am pasting my code here only...... 

    I am Highlighting the lines which i wrote for EZ-MODE in yellow colour =>

    Filename:       GenericApp.c
    
    /*********************************************************************
     * INCLUDES
     */
    #include "OSAL.h"
    #include "AF.h"
    #include "ZDApp.h"
    #include "ZDObject.h"
    #include "ZDProfile.h"
    
    #include "GenericApp.h"
    #include "DebugTrace.h"
    
    #include "zcl_ezmode.h"
    #include "zcl.h"
    #include "zcl_general.h"
    
    #if !defined( WIN32 ) || defined( ZBIT )
      #include "OnBoard.h"
    #endif
    
    /* HAL */
    #include "hal_lcd.h"
    #include "hal_led.h"
    #include "hal_key.h"
    #include "hal_uart.h"
    
    /* RTOS */
    #if defined( IAR_ARMCM3_LM )
    #include "RTOS_App.h"
    #endif
    
    
    /*********************************************************************
     * GLOBAL VARIABLES
     */
    uint8 GenericAppSeqNum;
     
    // This list should be filled with Application specific Cluster IDs.
    const cId_t GenericApp_ClusterList[GENERICAPP_MAX_CLUSTERS] =
    {
      GENERICAPP_CLUSTERID
    };
    
    const SimpleDescriptionFormat_t GenericApp_SimpleDesc =
    {
      GENERICAPP_ENDPOINT,              //  int Endpoint;
      GENERICAPP_PROFID,                //  uint16 AppProfId[2];
      GENERICAPP_DEVICEID,              //  uint16 AppDeviceId[2];
      GENERICAPP_DEVICE_VERSION,        //  int   AppDevVer:4;
      GENERICAPP_FLAGS,                 //  int   AppFlags:4;
      GENERICAPP_MAX_CLUSTERS,          //  byte  AppNumInClusters;
      (cId_t *)GenericApp_ClusterList,  //  byte *pAppInClusterList;
      GENERICAPP_MAX_CLUSTERS,          //  byte  AppNumInClusters;
      (cId_t *)GenericApp_ClusterList   //  byte *pAppInClusterList;
    };
    
    
    endPointDesc_t GenericApp_epDesc;
    
    
    /*********************************************************************
     * LOCAL VARIABLES
     */
    byte GenericApp_TaskID;   // Task ID for internal task/event processing
                              // This variable will be received when
                              // GenericApp_Init() is called.
    
    devStates_t GenericApp_NwkState;
    
    byte GenericApp_TransID;  // This is the unique message ID (counter)
    
    afAddrType_t GenericApp_DstAddr;
    
    // Number of recieved messages
    static uint16 rxMsgCount;
    
    // Time interval between sending messages
    static uint32 txMsgDelay = GENERICAPP_SEND_MSG_TIMEOUT;
    
    
    #ifdef ZCL_EZMODE
    static void GenericApp_EZModeCB( zlcEZMode_State_t state, zclEZMode_CBData_t *pData );
    static const zclEZMode_RegisterData_t GenericApp_RegisterEZModeData =
    {
      &GenericApp_TaskID,
      GENERICAPP_EZMODE_NEXTSTATE_EVT,
      GENERICAPP_EZMODE_TIMEOUT_EVT,
      &GenericAppSeqNum,
      GenericApp_EZModeCB
    };
    
    // NOT ZCL_EZMODE, Use EndDeviceBind
    #else
    
    /*********************************************************************
     * LOCAL FUNCTIONS
     */
    static void GenericApp_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg );
    static void GenericApp_HandleKeys( byte shift, byte keys );
    static void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pckt );
    static void GenericApp_SendTheMessage( void );

    static void binding_started(void); static void GenericApp_IdentifyCB( zclIdentify_t *pCmd ); static void GenericApp_IdentifyQueryRspCB( zclIdentifyQueryRsp_t *pRsp ); static void GenericApp_ProcessZDOMsgs( zdoIncomingMsg_t *pMsg ); #if defined( IAR_ARMCM3_LM ) static void GenericApp_ProcessRtosMessage( void ); #endif /********************************************************************* * ZCL General Profile Callback table */ static zclGeneral_AppCallbacks_t GenericApp_CmdCallbacks = { NULL, // Basic Cluster Reset command GenericApp_IdentifyCB, // Identify command #ifdef ZCL_EZMODE NULL, // Identify EZ-Mode Invoke command NULL, // Identify Update Commission State command #endif NULL, // Identify Trigger Effect command GenericApp_IdentifyQueryRspCB, // Identify Query Response command NULL, // On/Off cluster command NULL, // On/Off cluster enhanced command Off with Effect NULL, // On/Off cluster enhanced command On with Recall Global Scene NULL, // On/Off cluster enhanced command On with Timed Off #ifdef ZCL_LEVEL_CTRL NULL, // Level Control Move to Level command NULL, // Level Control Move command NULL, // Level Control Step command NULL, // Level Control Stop command #endif #ifdef ZCL_GROUPS NULL, // Group Response commands #endif #ifdef ZCL_SCENES NULL, // Scene Store Request command NULL, // Scene Recall Request command NULL, // Scene Response command #endif #ifdef ZCL_ALARMS NULL, // Alarm (Response) commands #endif #ifdef SE_UK_EXT NULL, // Get Event Log command NULL, // Publish Event Log command #endif NULL, // RSSI Location command NULL // RSSI Location Response command }; /********************************************************************* * @fn GenericApp_Init * * */ void GenericApp_Init( uint8 task_id ) { GenericApp_TaskID = task_id; GenericApp_NwkState = DEV_INIT; GenericApp_TransID = 0; // Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here. // If the hardware is other parts of the device add it in main(). GenericApp_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent; GenericApp_DstAddr.endPoint = 0; GenericApp_DstAddr.addr.shortAddr = 0; // Fill out the endpoint description. GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT; GenericApp_epDesc.task_id = &GenericApp_TaskID; GenericApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc; GenericApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &GenericApp_epDesc ); // Register the ZCL General Cluster Library callback functions zclGeneral_RegisterCmdCallbacks( GENERICAPP_ENDPOINT, &GenericApp_CmdCallbacks ); // Register for all key events - This app will handle all key events RegisterForKeys( GenericApp_TaskID ); #ifdef ZCL_EZMODE // Register EZ-Mode zcl_RegisterEZMode( &GenericApp_RegisterEZModeData ); // Register with the ZDO to receive Match Descriptor Responses ZDO_RegisterForZDOMsg(task_id, Match_Desc_rsp); #endif // Update the display #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "GenericApp", HAL_LCD_LINE_1 ); #endif ZDO_RegisterForZDOMsg( GenericApp_TaskID, End_Device_Bind_rsp ); ZDO_RegisterForZDOMsg( GenericApp_TaskID, Match_Desc_rsp ); binding_started();
    #if defined( IAR_ARMCM3_LM ) // Register this task with RTOS task initiator RTOS_RegisterApp( task_id, GENERICAPP_RTOS_MSG_EVT ); #endif } /********************************************************************* * @fn GenericApp_ProcessEvent * */ uint16 GenericApp_ProcessEvent( uint8 task_id, uint16 events ) { afIncomingMSGPacket_t *MSGpkt; afDataConfirm_t *afDataConfirm; char *pstrnew = "sending fails"; // Data Confirmation message fields byte sentEP; ZStatus_t sentStatus; byte sentTransID; // This should match the value sent (void)task_id; // Intentionally unreferenced parameter if ( events & SYS_EVENT_MSG ) { MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( GenericApp_TaskID ); while ( MSGpkt ) { switch ( MSGpkt->hdr.event ) { case ZDO_CB_MSG: GenericApp_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt ); break; case KEY_CHANGE: GenericApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys ); break; case AF_DATA_CONFIRM_CMD: // This message is received as a confirmation of a data packet sent. // The status is of ZStatus_t type [defined in ZComDef.h] // The message fields are defined in AF.h afDataConfirm = (afDataConfirm_t *)MSGpkt; sentEP = afDataConfirm->endpoint; (void)sentEP; // This info not used now sentTransID = afDataConfirm->transID; (void)sentTransID; // This info not used now sentStatus = afDataConfirm->hdr.status; // Action taken when confirmation is received. if ( sentStatus != ZSuccess ) { HalLcdWriteString ( pstrnew, HAL_LCD_LINE_2 ); // The data wasn't delivered -- Do something } break; case AF_INCOMING_MSG_CMD: GenericApp_MessageMSGCB( MSGpkt ); break; case ZDO_STATE_CHANGE: GenericApp_NwkState = (devStates_t)(MSGpkt->hdr.status); if ( (GenericApp_NwkState == DEV_ZB_COORD) || (GenericApp_NwkState == DEV_ROUTER) || (GenericApp_NwkState == DEV_END_DEVICE) ) { #ifdef ZCL_EZMODE zcl_EZModeAction( EZMODE_ACTION_NETWORK_STARTED, NULL ); #endif // ZCL_EZMODE // Start sending "the" message in a regular interval. osal_start_timerEx( GenericApp_TaskID, GENERICAPP_SEND_MSG_EVT, txMsgDelay ); } break; default: break; } // Release the memory osal_msg_deallocate( (uint8 *)MSGpkt ); // Next MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( GenericApp_TaskID ); } // return unprocessed events return (events ^ SYS_EVENT_MSG); } // Send a message out - This event is generated by a timer // (setup in GenericApp_Init()). if ( events & GENERICAPP_SEND_MSG_EVT ) { // Send "the" message GenericApp_SendTheMessage(); // Setup to send message again osal_start_timerEx( GenericApp_TaskID, GENERICAPP_SEND_MSG_EVT, txMsgDelay ); // return unprocessed events return (events ^ GENERICAPP_SEND_MSG_EVT); } #if defined( IAR_ARMCM3_LM ) // Receive a message from the RTOS queue if ( events & GENERICAPP_RTOS_MSG_EVT ) { // Process message from RTOS queue GenericApp_ProcessRtosMessage(); // return unprocessed events return (events ^ GENERICAPP_RTOS_MSG_EVT); } #endif if ( events & GENERICAPP_IDENTIFY_TIMEOUT_EVT ) { if ( GenericApp_IdentifyTime > 0 ) { GenericApp_IdentifyTime--; } GenericApp_ProcessIdentifyTimeChange(); return ( events ^ GENERICAPP_IDENTIFY_TIMEOUT_EVT ); }
    #ifdef ZCL_EZMODE // going on to next state if ( events & GENERICAPP_EZMODE_NEXTSTATE_EVT ) { zcl_EZModeAction ( EZMODE_ACTION_PROCESS, NULL ); // going on to next state return ( events ^ GENERICAPP_EZMODE_NEXTSTATE_EVT ); } // the overall EZMode timer expired, so we timed out if ( events & GENERICAPP_EZMODE_TIMEOUT_EVT ) { zcl_EZModeAction ( EZMODE_ACTION_TIMED_OUT, NULL ); // EZ-Mode timed out return ( events ^ GENERICAPP_EZMODE_TIMEOUT_EVT ); } #endif // ZLC_EZMODE // Discard unknown events return 0; } /***************************************************/ void binding_started() { #ifdef ZCL_EZMODE zclEZMode_InvokeData_t ezModeData; // static uint16 clusterIDs[] = { ZCL_CLUSTER_ID_HVAC_THERMOSTAT }; // only bind on the Thermostat cluster static uint16 clusterIDs[] = { GENERICAPP_CLUSTERID }; // Invoke EZ-Mode ezModeData.endpoint = GENERICAPP_ENDPOINT; // endpoint on which to invoke EZ-Mode if ( ( GenericApp_NwkState == DEV_ZB_COORD ) || ( GenericApp_NwkState == DEV_ROUTER ) || ( GenericApp_NwkState == DEV_END_DEVICE ) ) { ezModeData.onNetwork = TRUE; // node is already on the network } else { ezModeData.onNetwork = FALSE; // node is not yet on the network } ezModeData.initiator = TRUE; // Thermostat is an initiator ezModeData.numActiveInClusters = 0; ezModeData.pActiveInClusterIDs = NULL; ezModeData.numActiveOutClusters = 1; // active output cluster ezModeData.pActiveOutClusterIDs = clusterIDs; zcl_InvokeEZMode( &ezModeData ); #endif // ZCL_EZMODE } /********************************************************************* * @fn GenericApp_ProcessZDOMsgs() * * @brief Process response messages * * @param none * * @return none */ static void GenericApp_ProcessZDOMsgs( zdoIncomingMsg_t *pMsg ) { zclEZMode_ActionData_t data; ZDO_MatchDescRsp_t *pMatchDescRsp; // Let EZ-Mode know of the Match Descriptor Response if ( pMsg->clusterID == Match_Desc_rsp ) { pMatchDescRsp = ZDO_ParseEPListRsp( pMsg ); data.pMatchDescRsp = pMatchDescRsp; zcl_EZModeAction( EZMODE_ACTION_MATCH_DESC_RSP, &data ); osal_mem_free( pMatchDescRsp ); }

    /* switch ( inMsg->clusterID ) { case End_Device_Bind_rsp: if ( ZDO_ParseBindRsp( inMsg ) == ZSuccess ) { // Light LED HalLedSet( HAL_LED_4, HAL_LED_MODE_ON ); } #if defined( BLINK_LEDS ) else { // Flash LED to show failure HalLedSet ( HAL_LED_4, HAL_LED_MODE_FLASH ); } #endif break; case Match_Desc_rsp: { ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( inMsg ); if ( pRsp ) { if ( pRsp->status == ZSuccess && pRsp->cnt ) { GenericApp_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; GenericApp_DstAddr.addr.shortAddr = pRsp->nwkAddr; // Take the first endpoint, Can be changed to search through endpoints GenericApp_DstAddr.endPoint = pRsp->epList[0]; // Light LED HalLedSet( HAL_LED_4, HAL_LED_MODE_ON ); } osal_mem_free( pRsp ); } } break; } */ } /********************************************************************* * @fn GenericApp_HandleKeys * * @brief Handles all key events for this device. */ static void GenericApp_HandleKeys( uint8 shift, uint8 keys ) { zAddrType_t dstAddr; // Shift is used to make each button/switch dual purpose. if ( shift ) { if ( keys & HAL_KEY_SW_1 ) { } if ( keys & HAL_KEY_SW_2 ) { } if ( keys & HAL_KEY_SW_3 ) { } if ( keys & HAL_KEY_SW_4 ) { } } else { if ( keys & HAL_KEY_SW_1 ) { #if defined( SWITCH1_BIND ) // We can use SW1 to simulate SW2 for devices that only have one switch, keys |= HAL_KEY_SW_2; #elif defined( SWITCH1_MATCH ) // or use SW1 to simulate SW4 for devices that only have one switch keys |= HAL_KEY_SW_4; #else // Normally, SW1 changes the rate that messages are sent if ( txMsgDelay > 100 ) { // Cut the message TX delay in half txMsgDelay /= 2; } else { // Reset to the default txMsgDelay = GENERICAPP_SEND_MSG_TIMEOUT; } #endif } if ( keys & HAL_KEY_SW_2 ) { HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF ); // Initiate an End Device Bind Request for the mandatory endpoint dstAddr.addrMode = Addr16Bit; dstAddr.addr.shortAddr = 0x0000; // Coordinator ZDP_EndDeviceBindReq( &dstAddr, NLME_GetShortAddr(), GenericApp_epDesc.endPoint, GENERICAPP_PROFID, GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList, GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList, FALSE ); } if ( keys & HAL_KEY_SW_3 ) { } if ( keys & HAL_KEY_SW_4 ) { HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF ); // Initiate a Match Description Request (Service Discovery) dstAddr.addrMode = AddrBroadcast; dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR; ZDP_MatchDescReq( &dstAddr, NWK_BROADCAST_SHORTADDR, GENERICAPP_PROFID, GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList, GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList, FALSE ); } } } /********************************************************************* * @fn GenericApp_MessageMSGCB * */ static void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pkt ) { switch ( pkt->clusterId ) { case GENERICAPP_CLUSTERID: rxMsgCount += 1; // Count this message HalLedSet ( HAL_LED_4, HAL_LED_MODE_BLINK ); // Blink an LED #if defined( LCD_SUPPORTED ) HalLcdWriteString( (char*)pkt->cmd.Data, HAL_LCD_LINE_1 ); HalLcdWriteStringValue( "Total Rcvd packet:", rxMsgCount, 10, HAL_LCD_LINE_2 ); #elif defined( WIN32 ) WPRINTSTR( pkt->cmd.Data ); #endif break; } } /********************************************************************* * @fn GenericApp_SendTheMessage * */ static void GenericApp_SendTheMessage( void ) { char theMessageData[] = "Hello i am cc2538 ZED"; if ( AF_DataRequest( &GenericApp_DstAddr, &GenericApp_epDesc, GENERICAPP_CLUSTERID, (byte)osal_strlen( theMessageData ) + 1, //<= it is lenght of buffere (byte *)&theMessageData, &GenericApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) { // Successfully requested to be sent. } else { // Error occurred in request to send. } } #if defined( IAR_ARMCM3_LM ) /********************************************************************* * @fn GenericApp_ProcessRtosMessage */ static void GenericApp_ProcessRtosMessage( void ) { osalQueue_t inMsg; if ( osal_queue_receive( OsalQueue, &inMsg, 0 ) == pdPASS ) { uint8 cmndId = inMsg.cmnd; uint32 counter = osal_build_uint32( inMsg.cbuf, 4 ); switch ( cmndId ) { case CMD_INCR: counter += 1; /* Increment the incoming counter */ /* Intentionally fall through next case */ case CMD_ECHO: { userQueue_t outMsg; outMsg.resp = RSP_CODE | cmndId; /* Response ID */ osal_buffer_uint32( outMsg.rbuf, counter ); /* Increment counter */ osal_queue_send( UserQueue1, &outMsg, 0 ); /* Send back to UserTask */ break; } default: break; /* Ignore unknown command */ } } } #endif /********************************************************************* * @fn GenericApp_IdentifyCB * */ static void GenericApp_IdentifyCB( zclIdentify_t *pCmd ) { GenericApp_IdentifyTime = pCmd->identifyTime; GenericApp_ProcessIdentifyTimeChange(); } /********************************************************************* * @fn GenericApp_IdentifyQueryRspCB * */ static void GenericApp_IdentifyQueryRspCB( zclIdentifyQueryRsp_t *pRsp ) { (void)pRsp; #ifdef ZCL_EZMODE { zclEZMode_ActionData_t data; data.pIdentifyQueryRsp = pRsp; zcl_EZModeAction ( EZMODE_ACTION_IDENTIFY_QUERY_RSP, &data ); } #endif } /********************************************************************* * @fn GenericApp_ProcessIdentifyTimeChange * */ static void GenericApp_ProcessIdentifyTimeChange( void ) { if ( GenericApp_IdentifyTime > 0 ) { osal_start_timerEx( GenericApp_TaskID, GENERICAPP_IDENTIFY_TIMEOUT_EVT, 1000 ); HalLedBlink ( HAL_LED_4, 0xFF, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME ); } osal_stop_timerEx( GenericApp_TaskID, GENERICAPP_IDENTIFY_TIMEOUT_EVT ); } /********************************************************************* * @fn GenericApp_EZModeCB * */ static void GenericApp_EZModeCB( zlcEZMode_State_t state, zclEZMode_CBData_t *pData ) { #ifdef LCD_SUPPORTED char szLine[20]; char *pStr; uint8 err; #endif // time to go into identify mode if ( state == EZMODE_STATE_IDENTIFYING ) { GenericApp_IdentifyTime = (EZMODE_TIME / 1000); // convert to seconds GenericApp_ProcessIdentifyTimeChange(); } // autoclosing, show what happened (success, cancelled, etc...) if( state == EZMODE_STATE_AUTOCLOSE ) { #ifdef LCD_SUPPORTED pStr = NULL; err = pData->sAutoClose.err; if ( err == EZMODE_ERR_SUCCESS ) { pStr = "EZMode: Success"; } HalLcdWriteString ( pStr, HAL_LCD_LINE_2 ); #endif } // finished, either show DstAddr/EP, or nothing (depending on success or not) if ( state == EZMODE_STATE_FINISH ) { // turn off identify mode GenericApp_IdentifyTime = 0; GenericApp_ProcessIdentifyTimeChange(); #ifdef LCD_SUPPORTED // if successful, inform user which nwkaddr/ep we bound to pStr = NULL; err = pData->sFinish.err; if ( err == EZMODE_ERR_SUCCESS ) { // "EZDst:1234 EP:34" osal_memcpy(szLine, "EZDst:", 6); zclHA_uint16toa( pData->sFinish.nwkaddr, &szLine[6]); osal_memcpy(&szLine[10], " EP:", 4); _ltoa( pData->sFinish.ep, (void *)(&szLine[14]), 16 ); // _ltoa NULL terminates pStr = szLine; } else if ( err == EZMODE_ERR_BAD_PARAMETER ) { pStr = "EZMode: BadParm"; } else if ( err == EZMODE_ERR_CANCELLED ) { pStr = "EZMode: Cancel"; } else if ( err == EZMODE_ERR_NOMATCH ) { pStr = "EZMode: NoMatch"; // not a match made in heaven } else { pStr = "EZMode: TimeOut"; } HalLcdWriteString ( pStr, HAL_LCD_LINE_2 ); #endif // LCD_SUPPORTED // show main UI screen 3 seconds after completing EZ-Mode // osal_start_timerEx( GenericApp_TaskID, SAMPLETHERMOSTAT_MAIN_SCREEN_EVT, 3000 ); } } #endif // ZCL_EZMODE /********************************************************************* */

  • Hello YiKai Chen sir,

    i am not attach the files in the post.... becoz no tab/button is provided in this new look of Forum.... there is a tab/button to post pics & other media but not the files.....so i am pasting my code here only...... 

    I am Highlighting the lines which i wrote for EZ-MODE in yellow colour =>

    Filename:       GenericApp.c
    
    /*********************************************************************
     * INCLUDES
     */
    #include "OSAL.h"
    #include "AF.h"
    #include "ZDApp.h"
    #include "ZDObject.h"
    #include "ZDProfile.h"
    
    #include "GenericApp.h"
    #include "DebugTrace.h"
    
    #include "zcl_ezmode.h"
    #include "zcl.h"
    #include "zcl_general.h"
    
    #if !defined( WIN32 ) || defined( ZBIT )
      #include "OnBoard.h"
    #endif
    
    /* HAL */
    #include "hal_lcd.h"
    #include "hal_led.h"
    #include "hal_key.h"
    #include "hal_uart.h"
    
    /* RTOS */
    #if defined( IAR_ARMCM3_LM )
    #include "RTOS_App.h"
    #endif
    
    
    /*********************************************************************
     * GLOBAL VARIABLES
     */
    uint8 GenericAppSeqNum;
     
    // This list should be filled with Application specific Cluster IDs.
    const cId_t GenericApp_ClusterList[GENERICAPP_MAX_CLUSTERS] =
    {
      GENERICAPP_CLUSTERID
    };
    
    const SimpleDescriptionFormat_t GenericApp_SimpleDesc =
    {
      GENERICAPP_ENDPOINT,              //  int Endpoint;
      GENERICAPP_PROFID,                //  uint16 AppProfId[2];
      GENERICAPP_DEVICEID,              //  uint16 AppDeviceId[2];
      GENERICAPP_DEVICE_VERSION,        //  int   AppDevVer:4;
      GENERICAPP_FLAGS,                 //  int   AppFlags:4;
      GENERICAPP_MAX_CLUSTERS,          //  byte  AppNumInClusters;
      (cId_t *)GenericApp_ClusterList,  //  byte *pAppInClusterList;
      GENERICAPP_MAX_CLUSTERS,          //  byte  AppNumInClusters;
      (cId_t *)GenericApp_ClusterList   //  byte *pAppInClusterList;
    };
    
    
    endPointDesc_t GenericApp_epDesc;
    
    
    /*********************************************************************
     * LOCAL VARIABLES
     */
    byte GenericApp_TaskID;   // Task ID for internal task/event processing
                              // This variable will be received when
                              // GenericApp_Init() is called.
    
    devStates_t GenericApp_NwkState;
    
    byte GenericApp_TransID;  // This is the unique message ID (counter)
    
    afAddrType_t GenericApp_DstAddr;
    
    // Number of recieved messages
    static uint16 rxMsgCount;
    
    // Time interval between sending messages
    static uint32 txMsgDelay = GENERICAPP_SEND_MSG_TIMEOUT;
    
    
    #ifdef ZCL_EZMODE
    static void GenericApp_EZModeCB( zlcEZMode_State_t state, zclEZMode_CBData_t *pData );
    static const zclEZMode_RegisterData_t GenericApp_RegisterEZModeData =
    {
      &GenericApp_TaskID,
      GENERICAPP_EZMODE_NEXTSTATE_EVT,
      GENERICAPP_EZMODE_TIMEOUT_EVT,
      &GenericAppSeqNum,
      GenericApp_EZModeCB
    };
    
    // NOT ZCL_EZMODE, Use EndDeviceBind
    #else
    
    /*********************************************************************
     * LOCAL FUNCTIONS
     */
    static void GenericApp_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg );
    static void GenericApp_HandleKeys( byte shift, byte keys );
    static void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pckt );
    static void GenericApp_SendTheMessage( void );

    static void binding_started(void); static void GenericApp_IdentifyCB( zclIdentify_t *pCmd ); static void GenericApp_IdentifyQueryRspCB( zclIdentifyQueryRsp_t *pRsp ); static void GenericApp_ProcessZDOMsgs( zdoIncomingMsg_t *pMsg ); #if defined( IAR_ARMCM3_LM ) static void GenericApp_ProcessRtosMessage( void ); #endif /********************************************************************* * ZCL General Profile Callback table */ static zclGeneral_AppCallbacks_t GenericApp_CmdCallbacks = { NULL, // Basic Cluster Reset command GenericApp_IdentifyCB, // Identify command #ifdef ZCL_EZMODE NULL, // Identify EZ-Mode Invoke command NULL, // Identify Update Commission State command #endif NULL, // Identify Trigger Effect command GenericApp_IdentifyQueryRspCB, // Identify Query Response command NULL, // On/Off cluster command NULL, // On/Off cluster enhanced command Off with Effect NULL, // On/Off cluster enhanced command On with Recall Global Scene NULL, // On/Off cluster enhanced command On with Timed Off #ifdef ZCL_LEVEL_CTRL NULL, // Level Control Move to Level command NULL, // Level Control Move command NULL, // Level Control Step command NULL, // Level Control Stop command #endif #ifdef ZCL_GROUPS NULL, // Group Response commands #endif #ifdef ZCL_SCENES NULL, // Scene Store Request command NULL, // Scene Recall Request command NULL, // Scene Response command #endif #ifdef ZCL_ALARMS NULL, // Alarm (Response) commands #endif #ifdef SE_UK_EXT NULL, // Get Event Log command NULL, // Publish Event Log command #endif NULL, // RSSI Location command NULL // RSSI Location Response command }; /********************************************************************* * @fn GenericApp_Init * * */ void GenericApp_Init( uint8 task_id ) { GenericApp_TaskID = task_id; GenericApp_NwkState = DEV_INIT; GenericApp_TransID = 0; // Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here. // If the hardware is other parts of the device add it in main(). GenericApp_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent; GenericApp_DstAddr.endPoint = 0; GenericApp_DstAddr.addr.shortAddr = 0; // Fill out the endpoint description. GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT; GenericApp_epDesc.task_id = &GenericApp_TaskID; GenericApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc; GenericApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &GenericApp_epDesc ); // Register the ZCL General Cluster Library callback functions zclGeneral_RegisterCmdCallbacks( GENERICAPP_ENDPOINT, &GenericApp_CmdCallbacks ); // Register for all key events - This app will handle all key events RegisterForKeys( GenericApp_TaskID ); #ifdef ZCL_EZMODE // Register EZ-Mode zcl_RegisterEZMode( &GenericApp_RegisterEZModeData ); // Register with the ZDO to receive Match Descriptor Responses ZDO_RegisterForZDOMsg(task_id, Match_Desc_rsp); #endif // Update the display #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "GenericApp", HAL_LCD_LINE_1 ); #endif ZDO_RegisterForZDOMsg( GenericApp_TaskID, End_Device_Bind_rsp ); ZDO_RegisterForZDOMsg( GenericApp_TaskID, Match_Desc_rsp ); binding_started();
    #if defined( IAR_ARMCM3_LM ) // Register this task with RTOS task initiator RTOS_RegisterApp( task_id, GENERICAPP_RTOS_MSG_EVT ); #endif } /********************************************************************* * @fn GenericApp_ProcessEvent * */ uint16 GenericApp_ProcessEvent( uint8 task_id, uint16 events ) { afIncomingMSGPacket_t *MSGpkt; afDataConfirm_t *afDataConfirm; char *pstrnew = "sending fails"; // Data Confirmation message fields byte sentEP; ZStatus_t sentStatus; byte sentTransID; // This should match the value sent (void)task_id; // Intentionally unreferenced parameter if ( events & SYS_EVENT_MSG ) { MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( GenericApp_TaskID ); while ( MSGpkt ) { switch ( MSGpkt->hdr.event ) { case ZDO_CB_MSG: GenericApp_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt ); break; case KEY_CHANGE: GenericApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys ); break; case AF_DATA_CONFIRM_CMD: // This message is received as a confirmation of a data packet sent. // The status is of ZStatus_t type [defined in ZComDef.h] // The message fields are defined in AF.h afDataConfirm = (afDataConfirm_t *)MSGpkt; sentEP = afDataConfirm->endpoint; (void)sentEP; // This info not used now sentTransID = afDataConfirm->transID; (void)sentTransID; // This info not used now sentStatus = afDataConfirm->hdr.status; // Action taken when confirmation is received. if ( sentStatus != ZSuccess ) { HalLcdWriteString ( pstrnew, HAL_LCD_LINE_2 ); // The data wasn't delivered -- Do something } break; case AF_INCOMING_MSG_CMD: GenericApp_MessageMSGCB( MSGpkt ); break; case ZDO_STATE_CHANGE: GenericApp_NwkState = (devStates_t)(MSGpkt->hdr.status); if ( (GenericApp_NwkState == DEV_ZB_COORD) || (GenericApp_NwkState == DEV_ROUTER) || (GenericApp_NwkState == DEV_END_DEVICE) ) { #ifdef ZCL_EZMODE zcl_EZModeAction( EZMODE_ACTION_NETWORK_STARTED, NULL ); #endif // ZCL_EZMODE // Start sending "the" message in a regular interval. osal_start_timerEx( GenericApp_TaskID, GENERICAPP_SEND_MSG_EVT, txMsgDelay ); } break; default: break; } // Release the memory osal_msg_deallocate( (uint8 *)MSGpkt ); // Next MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( GenericApp_TaskID ); } // return unprocessed events return (events ^ SYS_EVENT_MSG); } // Send a message out - This event is generated by a timer // (setup in GenericApp_Init()). if ( events & GENERICAPP_SEND_MSG_EVT ) { // Send "the" message GenericApp_SendTheMessage(); // Setup to send message again osal_start_timerEx( GenericApp_TaskID, GENERICAPP_SEND_MSG_EVT, txMsgDelay ); // return unprocessed events return (events ^ GENERICAPP_SEND_MSG_EVT); } #if defined( IAR_ARMCM3_LM ) // Receive a message from the RTOS queue if ( events & GENERICAPP_RTOS_MSG_EVT ) { // Process message from RTOS queue GenericApp_ProcessRtosMessage(); // return unprocessed events return (events ^ GENERICAPP_RTOS_MSG_EVT); } #endif if ( events & GENERICAPP_IDENTIFY_TIMEOUT_EVT ) { if ( GenericApp_IdentifyTime > 0 ) { GenericApp_IdentifyTime--; } GenericApp_ProcessIdentifyTimeChange(); return ( events ^ GENERICAPP_IDENTIFY_TIMEOUT_EVT ); }
    #ifdef ZCL_EZMODE // going on to next state if ( events & GENERICAPP_EZMODE_NEXTSTATE_EVT ) { zcl_EZModeAction ( EZMODE_ACTION_PROCESS, NULL ); // going on to next state return ( events ^ GENERICAPP_EZMODE_NEXTSTATE_EVT ); } // the overall EZMode timer expired, so we timed out if ( events & GENERICAPP_EZMODE_TIMEOUT_EVT ) { zcl_EZModeAction ( EZMODE_ACTION_TIMED_OUT, NULL ); // EZ-Mode timed out return ( events ^ GENERICAPP_EZMODE_TIMEOUT_EVT ); } #endif // ZLC_EZMODE // Discard unknown events return 0; } /***************************************************/ void binding_started() { #ifdef ZCL_EZMODE zclEZMode_InvokeData_t ezModeData; // static uint16 clusterIDs[] = { ZCL_CLUSTER_ID_HVAC_THERMOSTAT }; // only bind on the Thermostat cluster static uint16 clusterIDs[] = { GENERICAPP_CLUSTERID }; // Invoke EZ-Mode ezModeData.endpoint = GENERICAPP_ENDPOINT; // endpoint on which to invoke EZ-Mode if ( ( GenericApp_NwkState == DEV_ZB_COORD ) || ( GenericApp_NwkState == DEV_ROUTER ) || ( GenericApp_NwkState == DEV_END_DEVICE ) ) { ezModeData.onNetwork = TRUE; // node is already on the network } else { ezModeData.onNetwork = FALSE; // node is not yet on the network } ezModeData.initiator = TRUE; // Thermostat is an initiator ezModeData.numActiveInClusters = 0; ezModeData.pActiveInClusterIDs = NULL; ezModeData.numActiveOutClusters = 1; // active output cluster ezModeData.pActiveOutClusterIDs = clusterIDs; zcl_InvokeEZMode( &ezModeData ); #endif // ZCL_EZMODE } /********************************************************************* * @fn GenericApp_ProcessZDOMsgs() * * @brief Process response messages * * @param none * * @return none */ static void GenericApp_ProcessZDOMsgs( zdoIncomingMsg_t *pMsg ) { zclEZMode_ActionData_t data; ZDO_MatchDescRsp_t *pMatchDescRsp; // Let EZ-Mode know of the Match Descriptor Response if ( pMsg->clusterID == Match_Desc_rsp ) { pMatchDescRsp = ZDO_ParseEPListRsp( pMsg ); data.pMatchDescRsp = pMatchDescRsp; zcl_EZModeAction( EZMODE_ACTION_MATCH_DESC_RSP, &data ); osal_mem_free( pMatchDescRsp ); }
    } /********************************************************************* * @fn GenericApp_HandleKeys * * @brief Handles all key events for this device. */ static void GenericApp_HandleKeys( uint8 shift, uint8 keys ) { ........same as in the Generic App code......
    But now i dont want to to use key press for binding two Generic App device i want to do autobinding } /********************************************************************* * @fn GenericApp_MessageMSGCB * */ static void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pkt ) { switch ( pkt->clusterId ) { case GENERICAPP_CLUSTERID: rxMsgCount += 1; // Count this message HalLedSet ( HAL_LED_4, HAL_LED_MODE_BLINK ); // Blink an LED #if defined( LCD_SUPPORTED ) HalLcdWriteString( (char*)pkt->cmd.Data, HAL_LCD_LINE_1 ); HalLcdWriteStringValue( "Total Rcvd packet:", rxMsgCount, 10, HAL_LCD_LINE_2 ); #elif defined( WIN32 ) WPRINTSTR( pkt->cmd.Data ); #endif break; } } /********************************************************************* * @fn GenericApp_SendTheMessage * */ static void GenericApp_SendTheMessage( void ) { char theMessageData[] = "Hello i am cc2538 ZED"; if ( AF_DataRequest( &GenericApp_DstAddr, &GenericApp_epDesc, GENERICAPP_CLUSTERID, (byte)osal_strlen( theMessageData ) + 1, //<= it is lenght of buffere (byte *)&theMessageData, &GenericApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) { // Successfully requested to be sent. } else { // Error occurred in request to send. } } /********************************************************************* * @fn GenericApp_IdentifyCB * */ static void GenericApp_IdentifyCB( zclIdentify_t *pCmd ) { GenericApp_IdentifyTime = pCmd->identifyTime; GenericApp_ProcessIdentifyTimeChange(); } /********************************************************************* * @fn GenericApp_IdentifyQueryRspCB * */ static void GenericApp_IdentifyQueryRspCB( zclIdentifyQueryRsp_t *pRsp ) { (void)pRsp; #ifdef ZCL_EZMODE { zclEZMode_ActionData_t data; data.pIdentifyQueryRsp = pRsp; zcl_EZModeAction ( EZMODE_ACTION_IDENTIFY_QUERY_RSP, &data ); } #endif } /********************************************************************* * @fn GenericApp_ProcessIdentifyTimeChange * */ static void GenericApp_ProcessIdentifyTimeChange( void ) { if ( GenericApp_IdentifyTime > 0 ) { osal_start_timerEx( GenericApp_TaskID, GENERICAPP_IDENTIFY_TIMEOUT_EVT, 1000 ); HalLedBlink ( HAL_LED_4, 0xFF, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME ); } osal_stop_timerEx( GenericApp_TaskID, GENERICAPP_IDENTIFY_TIMEOUT_EVT ); } /********************************************************************* * @fn GenericApp_EZModeCB * */ static void GenericApp_EZModeCB( zlcEZMode_State_t state, zclEZMode_CBData_t *pData ) { #ifdef LCD_SUPPORTED char szLine[20]; char *pStr; uint8 err; #endif // time to go into identify mode if ( state == EZMODE_STATE_IDENTIFYING ) { GenericApp_IdentifyTime = (EZMODE_TIME / 1000); // convert to seconds GenericApp_ProcessIdentifyTimeChange(); } // autoclosing, show what happened (success, cancelled, etc...) if( state == EZMODE_STATE_AUTOCLOSE ) { #ifdef LCD_SUPPORTED pStr = NULL; err = pData->sAutoClose.err; if ( err == EZMODE_ERR_SUCCESS ) { pStr = "EZMode: Success"; } HalLcdWriteString ( pStr, HAL_LCD_LINE_2 ); #endif } // finished, either show DstAddr/EP, or nothing (depending on success or not) if ( state == EZMODE_STATE_FINISH ) { // turn off identify mode GenericApp_IdentifyTime = 0; GenericApp_ProcessIdentifyTimeChange(); #ifdef LCD_SUPPORTED // if successful, inform user which nwkaddr/ep we bound to pStr = NULL; err = pData->sFinish.err; if ( err == EZMODE_ERR_SUCCESS ) { // "EZDst:1234 EP:34" osal_memcpy(szLine, "EZDst:", 6); zclHA_uint16toa( pData->sFinish.nwkaddr, &szLine[6]); osal_memcpy(&szLine[10], " EP:", 4); _ltoa( pData->sFinish.ep, (void *)(&szLine[14]), 16 ); // _ltoa NULL terminates pStr = szLine; } else if ( err == EZMODE_ERR_BAD_PARAMETER ) { pStr = "EZMode: BadParm"; } else if ( err == EZMODE_ERR_CANCELLED ) { pStr = "EZMode: Cancel"; } else if ( err == EZMODE_ERR_NOMATCH ) { pStr = "EZMode: NoMatch"; // not a match made in heaven } else { pStr = "EZMode: TimeOut"; } HalLcdWriteString ( pStr, HAL_LCD_LINE_2 ); #endif // LCD_SUPPORTED // show main UI screen 3 seconds after completing EZ-Mode // osal_start_timerEx( GenericApp_TaskID, SAMPLETHERMOSTAT_MAIN_SCREEN_EVT, 3000 ); } } #endif // ZCL_EZMODE /********************************************************************* */
  • EZ-mode is defined by ZIgbee HA profile but GenericAPP uses private profile. I had suggested you to send end device binding request when ZC/ZED goes to ZDO_STATE_CHANGE. You don't have to use EZ-mode unless you think it is mandatory.
  • Hello YiKai Chen sir,

    Thanks for reply.....

    as u suggested i did the same things ... now i am sending end device binding request when ZC/ZED goes to ZDO_STATE_CHANGE as follows ->

    zAddrType_t dstAddr;

    case ZDO_STATE_CHANGE:

    GenericApp_NwkState = (devStates_t)(MSGpkt->hdr.status);
    if ( (GenericApp_NwkState == DEV_ZB_COORD) ||
    (GenericApp_NwkState == DEV_ROUTER) ||
    (GenericApp_NwkState == DEV_END_DEVICE) )
    {
    // Start sending "the" message in a regular interval.
    osal_start_timerEx( GenericApp_TaskID,
    GENERICAPP_SEND_MSG_EVT,
    txMsgDelay );
    }

    dstAddr.addrMode = Addr16Bit;
    dstAddr.addr.shortAddr = 0x0000; // Coordinator
    ZDP_EndDeviceBindReq ( &dstAddr, NLME_GetShortAddr(),
                                                    GenericApp_epDesc.endPoint,
                                                    GENERICAPP_PROFID,
                                                    GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList,
                                                    GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList,
                                                    FALSE  );

    break;

    but i am facing one problem ->

    1) i made one device as ZR and one as ZC......... and in ZR i  set a breakpoint at ZDP_EndDeviceBindReq()  and i noticed that it keep sending beacon request and keep hitting the breakpoint but not getting bind with the ZC.... becoz of that ZR is not able to send / receive the msg.....

    here is the screen shot which i am attaching with this mail...

     

    plz check it and tell me what i am doing wrong ?

    why it is keep hitting ZDP_EndDeviceBindReq() fn and sending continues Beacon request but not getting bind with ZC....

    plz help me.....

    and will you plz tell how to  send source files in forum.....earlier one tab/button was provided to attach and send source file but now in this new look i am not seeing that tab/button for sending files...... 

    Thanks & Regards,

    Maneesh singh 

  • Try the following revision
    GenericApp_NwkState = (devStates_t)(MSGpkt->hdr.status);
    if ( (GenericApp_NwkState == DEV_ZB_COORD) ||
    (GenericApp_NwkState == DEV_ROUTER) ||
    (GenericApp_NwkState == DEV_END_DEVICE) )
    {
    // Start sending "the" message in a regular interval.
    osal_start_timerEx( GenericApp_TaskID,
    GENERICAPP_SEND_MSG_EVT,
    txMsgDelay );

    dstAddr.addrMode = Addr16Bit;
    dstAddr.addr.shortAddr = 0x0000; // Coordinator
    ZDP_EndDeviceBindReq ( &dstAddr, NLME_GetShortAddr(),
    GenericApp_epDesc.endPoint,
    GENERICAPP_PROFID,
    GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList,
    GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList,
    FALSE );
    }
    break;
  • Hello YiKai Chen sir,
    Thanks for reply.....
    as u suggested i tried the same and now it is working....
    but some times binding gets fails and not able to connect but out of 10 times 6-7 times this approach works fine.....
    but is there anything we can do so that chances of this failure we can reduce to NULL ?

    plz give me some suggestion sir........

    Thanks & Regards,
    Maneesh Singh
  • Hello YiKai Chen sir,
    i want to ask u one thing that---> is this possible to configure UART in GenericAPP ? say if i want to use UART 0 then can i use it in GenericAPP?
    and if yes then can u tell me steps to make UART work in Generic APP...
    i am using Zstack mesh 1.0.0

    Thanks & Regards,
    Maneesh singh
  • Since you want to trigger binding automatically, I suggest you send end device binding when ZDO_STATE_CHANGE and you have to turn on ZC and ZED almost at the same time. In this way, they would enter ZDO_STATE_CHANGE almost at the same time and send out end device binding.