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.

Z-stack Home 1.2.2 HA profile Light Toggling

Other Parts Discussed in Thread: Z-STACK

Which file i can get port & pin configuration of led connected in light project for toggling,on and off process under home automation in z-stack home 1.2.2?

  • There is no sample code for this.
  • ok how can i implement this. any idea?
    how these would be implemented in smart Rf evaluation boards?
  • You can try to claim a key_press_count and init it to 0. When there is a key pressed and key_press_count is 0, you can increase key_press_count and start a event to check key_press_count for example 3 seconds later. Then, increase key_press_count when a key press during this period. When the 3 seconds event comes, you check the total number of key_press_count and deal with related behavior you want.
  • i have enabled ISR_KEYINTERRUPT,defined PUSHx_POLARITY as ACTIVE_HIGH and interrupt edge as falling edge. every time i debug, false interrupt occurs once even if there is no key press(later it senses key press correctly). key is externally pulled up with 10K resistor. how to troubleshoot this? i had tried by changing the polarity and edge configuration but issue not solved.
  • You suppose to revise hal_key.c not hal_board_cfg.h. Please refer to SW6 implementation in hal_key.c.
  • i have configured keys based on my hardware(key at P0_0) so only revised hal_board_cfg.h. Dono how false interrupt is not detected now at the P0_0 but its detected at sw6(P0_1). I didn't make any changes to sw6 pin configuration. just added code similar to sw6 for P0_0. it may be due to P0_1 having no connection.

    Do we need to register any callback for zb_HandleOsalEvent? in original z-stack home1.2.2 doorlock,this function is not called. I had called this function to process the key press count but this function is not getting called.I am not able to set any breakpoint in this function.
  • I don't understand what you are doing. According to my experiences, it is better to revised hal_key.c to handle P0.0 as GPI interrupt. You can revise SW6 which is original used by P0.1 to P0.0. Then, you can add "if ( keys & HAL_KEY_SW_6 )" in XXX_HandleKeys to process it.
  • Hi Yikai,

    this post is not related to false key interrupt. I have included my revised code for processing functions based on key press count. in P0.0 interrupt it will start event for counting the number of key press. after 10 sec(KEY_PRESS_COUNT_WAIT_TIME) zb_HandleOsalEvent() should be called which in turn will call Process_Key_Press_Event() which is used to count the number of times key is pressed and process according to that.

    I am not able to set any breakpoint in zb_HandleOsalEvent() and Process_Key_Press_Event(). These functions are not called as after 10sec of first time key is pressed,HAL_KEY_SW_7_PRESS_COUNT should be 0 but it keeps on incrementing at each switch press.

    uint8 HAL_KEY_SW_7_PRESS_COUNT = 0;	//global  variable to count the number of key press
    #define KEY_PRESS_COUNT_WAIT_TIME  10000
    #define KEY_PRESS_COUNT_EVENT     0x0100
    #define RESET_TO_FACTORY_EVENT    0x0200
    
    HAL_ISR_FUNCTION( halKeyPort0Isr, P0INT_VECTOR )
    {
      HAL_ENTER_ISR();
      if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT)	//sw7 connected to P0.0
      {
        if(HAL_KEY_SW_7_PRESS_COUNT == 0)   
        {
    	//start event to calculate and process the key press count
          osal_start_timerEx (zclSampleDoorLock_TaskID, KEY_PRESS_COUNT_EVENT, KEY_PRESS_COUNT_WAIT_TIME);
        }
        HAL_KEY_SW_7_PRESS_COUNT++;	//increment count on key press
      } 
      HAL_KEY_SW_7_PXIFG = 0;
      HAL_KEY_CPU_PORT_0_IF = 0;
      .
      .
    }
    
    
    //defined in zcl_sampledoorlock.c file 
    void zb_HandleOsalEvent( uint16 event )
    {
      if( event & KEY_PRESS_COUNT_EVENT)
      {
        osal_stop_timerEx (zclSampleDoorLock_TaskID, KEY_PRESS_COUNT_EVENT);
        Process_Key_Press_Event();
        event &= (~KEY_PRESS_COUNT_EVENT); 
      }
      if( event & RESET_TO_FACTORY_EVENT)	//factory reset microcontroller
      {
        event &= (~RESET_TO_FACTORY_EVENT);  
        zgWriteStartupOptions(ZG_STARTUP_SET, (ZCD_STARTOPT_DEFAULT_NETWORK_STATE | ZCD_STARTOPT_DEFAULT_CONFIG_STATE));
        ZDApp_ResetTimerStart(3000);
      }
    }
    
    void Process_Key_Press_Event( void )
    {
      if(HAL_KEY_SW_7_PRESS_COUNT == 3)     //set event to factory reset microcontroller when key is pressed 3 times
      {
        osal_set_event ( zclSampleDoorLock_TaskID, RESET_TO_FACTORY_EVENT); //set event to factory reset microcontroller
        HAL_KEY_SW_7_PRESS_COUNT=0;		//reset key press count
      }
      if(HAL_KEY_SW_7_PRESS_COUNT == 5)    
      {
        //do some process
      }
    }
    

  • If your revision is based on sampledoorlock, application event should be processed in zclSampleDoorLock_event_loop not zb_HandleOsalEvent.
  • 1)HAL_KEY_SW_7_PRESS_COUNT value gets incremented randomly on switch press. most of the time, its incremented randomly when i press key multiple times. sometimes it increments by 2 sometimes by 3 etc. is it due to key debounce? if so then what change should i make in the P0 ISR?
  • Where do you increase the count?
  • HAL_ISR_FUNCTION( halKeyPort0Isr, P0INT_VECTOR )

    {

     HAL_ENTER_ISR();

     if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT) //sw7 connected to P0.0

     {

       if(HAL_KEY_SW_7_PRESS_COUNT == 0)  

       {

    //start event to calculate and process the key press count

         osal_start_timerEx (zclSampleDoorLock_TaskID, KEY_PRESS_COUNT_EVENT, KEY_PRESS_COUNT_WAIT_TIME);

       }

       HAL_KEY_SW_7_PRESS_COUNT++; //increment count on key press

     }

     HAL_KEY_SW_7_PXIFG = 0;

     HAL_KEY_CPU_PORT_0_IF = 0;

     .

     .

    }

  • I would suggest you to increase the count in xxx_HandleKeys.
  • processing in HandleKeys often misses the keypress increment when pressed multiple times as it takes some time to process HandleKeys.
  • Try to increase the count in HalKeyPoll().
  • Hi Yikai,

    I have included code for sending ZCL command using AF_DATA_REQUEST. For testing whether data is received, i am sending command from zed to zc. Is it correct?

    i am getting following error for    

    dstAddr.addr.shortAddr = 0; and

    srcEP.endPoint=SAMPLEDOORLOCK_ENDPOINT;

    Error[Pe154]: expression must have struct or union type

        afAddrType_t *dstAddr;
        endPointDesc_t *srcEP;
        uint8 *buf;
        uint8 *transID;
        dstAddr.addr.shortAddr = 0;
        dstAddr->addrMode=afAddr16Bit;
        srcEP.endPoint=SAMPLEDOORLOCK_ENDPOINT;
        buf[0]=0x08;//Frame control:command acts across entire profile,not manufacturer 		                //specific,command sent from client to server.
        buf[1]=0x01;//transaction seq no
        buf[2]=0x01;//command identifier:Unlock door
        transID[0]=0x01;
        AF_DataRequest( dstAddr, srcEP,
                               ZCL_CLUSTER_ID_CLOSURES_DOOR_LOCK, 3, buf, transID,
                               AF_DEFAULT_RADIUS,0 );

  • Try to change dstAddr to the following code:
    afAddrType_t dstAddr;
    dstAddr.addr.shortAddr = 0;
    dstAddr.addrMode=afAddr16Bit;

    AF_DataRequest( &dstAddr, srcEP,
    ZCL_CLUSTER_ID_CLOSURES_DOOR_LOCK, 3, buf, transID,
    AF_DEFAULT_RADIUS,0 );
  • what to do to solve this error? error received while opening iar workbench

  • Which IAR version do you use? To build Z-Stack Home 1.2.2, you will need IAR EWARM 7.30.4.
  • IAR EWARM 7.30.4 is needed for simplink(cc2560) right? for cc2530,i am using iar version9.10.3
  • Yes, IAR ARM is for CC2538 and CC26xx. I forget you use CC2530. The formal version to build Z-Stack Home 1.2.2 is IAR EW8051 9.10.1 which can be download at www.iar.com/.../ti-wireless
  • i don't think its iar version issue. the problem comes when i start iar workbench that time the error is received and its not while opening Z-Stack Home 1.2.2 example code.
  • Yes, I know. However, I have no problem using IAR EW8051 9.10.1 download from the link so I suggest you to try it.
  • same problem exists with IAR EW8051 9.10.1 also.
  • Maybe try to remove all IAR products and reinstall to see if it works.
  • Ya, after uninstalling all iar products, error is not received.

    please check again whether AF_DATA_REQUEST fn is correct or not. now error is not received in dstAddr but data is not received at zc. i have checked this by placing breakpoint in case ZCL_INCOMING_MSG: of zc.

        afAddrType_t dstAddr;
        endPointDesc_t srcEP;
        uint8 *buf;
        uint8 *transID;
        dstAddr.addr.shortAddr = 0;
        dstAddr.addrMode=afAddr16Bit;
        srcEP.endPoint=SAMPLEDOORLOCK_ENDPOINT;
        buf[0]=0x08;//Frame control:command acts across entire profile,not manufacturer 		                //specific,command sent from client to server.
        buf[1]=0x01;//transaction seq no
        buf[2]=0x01;//command identifier:Unlock door
        transID[0]=0x01;
        AF_DataRequest( &dstAddr, &srcEP,
                               ZCL_CLUSTER_ID_CLOSURES_DOOR_LOCK, 3, buf, transID,
                               AF_DEFAULT_RADIUS,0 );
    r

  • Do you use Packet sniffer to check if the message is sent out?
  • ya. in sniffer it shows data transmission from zed to zcafdata.psd

  • i can also read active endpoint,simple descriptor using hyperterminal. i want to check by sending data through hyperterminal.can you please tell what sample data(data field of AF_DATA_REQUEST MT Command) i should send.
  • I suggest you set a breakpoint at "if ( *msgPtr == AF_INCOMING_MSG_CMD )" statement in zcl_event_loop() of receiver side and debug it.
  • its not received in "if ( *msgPtr == AF_INCOMING_MSG_CMD )" statement in zcl_event_loop()
  • i have tested by sending AF_DATA_REQUEST MT Command from zc to zed. it hits breakpoint in case ZCL_INCOMING_MSG in zed. i will test by sending data using AF_DataRequest api from zc to zed and see if data is received at zed.
  • What is simpleDesc in your srcEP when you call AF_DataRequest? I see an unknown Profile ID in your sniffer log and I suspect this is the problem.

  • My sniffer has some problem and it often shows wrong device description like profile id,EP etc

    Here i have included Active EP Request and Response,Simple desc Request and Response. Here you can see device description are received correctly through hyper terminal.

    I will modify program to send data from zc to zed using Af_Datarequest() and check whether data is received at zed.

  • I use Ubiqua packet analyzer to check your sniffer log and see there is problem on profile ID. I also check your code and don't see you assign simple descriptor in srcEP.
  • There is a simpleDesc pointer in endPointDesc_t
    {
    byte endPoint;
    byte *task_id;
    SimpleDescriptionFormat_t *simpleDesc;
    afNetworkLatencyReq_t latencyReq;
    } endPointDesc_t;

    I don't see you assign it in your code.
  • Ya i got now what do you want to say. Will fill corresponding fields for simpledesc and check again.
  • Yes, please try it to see if it works.
  • here i have included sniffer log and my revised code for af data request. now also data is not received at zc. i have used default parameters values as used in original z-stack.

    2210.b.psd

    static cId_t bindingInClusters1[] =
    {
      ZCL_CLUSTER_ID_GEN_ON_OFF,
      ZCL_CLUSTER_ID_CLOSURES_DOOR_LOCK
    };
    #define ZCLSAMPLEDOORLOCK_BINDINGLIST1 (sizeof(bindingInClusters1) / sizeof(bindingInClusters1[0]))
    
    AddrType_t dstAddr;
        endPointDesc_t srcEP;
        uint8 *buf;
        uint8 *transID;
        dstAddr.addr.shortAddr = 0;
        dstAddr.addrMode=afAddr16Bit;
        srcEP.endPoint=SAMPLEDOORLOCK_ENDPOINT;
        srcEP.simpleDesc->EndPoint=SAMPLEDOORLOCK_ENDPOINT;
        srcEP.simpleDesc->AppProfId=ZCL_HA_PROFILE_ID;
        srcEP.simpleDesc->AppDeviceId=ZCL_HA_DEVICEID_DOOR_LOCK;
        srcEP.simpleDesc->AppNumInClusters=ZCLSAMPLEDOORLOCK_BINDINGLIST1;
        srcEP.simpleDesc->pAppInClusterList=bindingInClusters1;
        srcEP.simpleDesc->AppNumOutClusters=ZCLSAMPLEDOORLOCK_BINDINGLIST1;
        srcEP.simpleDesc->pAppOutClusterList=bindingInClusters1;		//used in cluster temporarly
        buf[0]=0x08;//Frame control:command acts across entire profile,not manufacturer specific,command sent from client to 		//server.
        buf[1]=0x01;//transaction seq no
        buf[2]=0x01;//command identifier:Unlock door
        transID[0]=0x01;
        AF_DataRequest( &dstAddr, &srcEP,
                               ZCL_CLUSTER_ID_CLOSURES_DOOR_LOCK, 3, buf, transID,
                               AF_DEFAULT_RADIUS,0 );

  • May I know what your ZC and ZED are based on which Z-Stack example and what you intend to do I your application?
  • currently i am using SampleDoorLock of z-stack home 1.2.2 for both, one device i have configured as zc and other as zed.
    Actually i want to replace code for all my sensors in simple app z-stack 2.5.1a to z-stack home 1.2.2 so that it will be compatible with 3rd party devices. For this i want to send data to and from zc.
  • If your ZC and ZED are both samplDoorLock, I think there might be problem to receive command. ZCL command has direction, for example, you can only send ZCL on/off command from SmapleSwitch to SampleLight but not reverse. If you mean to use DoorLock examples to send command from ZED to ZC, I suppose you have to config SampleDoorlock as ZC and DoorlockController as ZED.
  • i want to send command from zc to zed and zed to zc for all my sensors in my application. so after configuring SampleDoorlock as ZC and DoorlockController as ZED,will i be able to send command from zc to zed and vice versa?
  • I suppose you have to manipulate in/out clusters on both ZC and ZED to have this capability.
  • Do you mean to say using correct in/out cluster while sending command from zed to zc and vice versa?
    in cluster of SampleDoorlock is defined in else case of ZCL_EZMODE. i have defined ZCL_EZMODE(don't know more about it but only know that it helps in faster nwk formation). so do i need to define again as i have defined it again seperately?
  • Yes, you have to define correct in clusters in simple descriptor of a device to receive command.
  • now zc is able to receive data from zed. i was not using destination endpoint in destination address. that's why it was not receiving. but now also two problems are there.
    1)zc is not receiving data always. i need to send twice or thrice although both are in close vicinity.
    2)for sending data from zed i had placed breakpoint in P0 ISR and AF_DataRequest(). what i find is if i remove breakpoint in P0 ISR then AF_DataRequest is not called. keeping breakpoint in P0 ISR always calls AF_DataRequest() without a single miss. What parameter i am missing?
    1 and 2 are indepenent.
  • 1. What is the time difference between your two concussive AF_DataRequest? I mean, do you call AF_DataRequest too fast?
    2. I don't think it is a good idea to put AF_DataRequest in ISR.
  • 1)No i am calling with delay of 5sec and even more.
    2)i am not calling AF_DataRequest in ISR but calling in handle key press event. i said to check whether key is detected correctly and AF_DataRequest is called on switch press i had placed break point in ISR and AF_DataRequest(). so if i remove breakpoint in isr and keep only in AF_DataRequest then breakpoint is not hit but keeping breakpoint in isr,key is detected every time and fn called without miss.