<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Zigbee SDK 4.1 -&amp;gt; Light Control Example -&amp;gt; Light Switch binding &amp;amp; finding button not working</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/79418/zigbee-sdk-4-1---light-control-example---light-switch-binding-finding-button-not-working</link><description>Hello everyone, 
 In the Light Control Example of Zigbee SDK 4.1 there is a Light Switch with a couple of button assignments. 
 Used board: PCA10056 
 
 (Light switch) Button 1 
 
 When the light bulb has been turned off, pressing this button once turns</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 08 Sep 2021 13:01:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/79418/zigbee-sdk-4-1---light-control-example---light-switch-binding-finding-button-not-working" /><item><title>RE: Zigbee SDK 4.1 -&gt; Light Control Example -&gt; Light Switch binding &amp; finding button not working</title><link>https://devzone.nordicsemi.com/thread/328613?ContentTypeID=1</link><pubDate>Wed, 08 Sep 2021 13:01:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:095dfe99-6d76-4e6a-98ef-37cb367529b6</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You are correct that button 4 is unassigned in the light switch code, and that Finding and Binding is not implemented there. You can add this&amp;nbsp;functionality to your application with the following steps:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Add a case for the button event for button 4 in buttons_handler(), BSP_EVENT_KEY_3.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;case BSP_EVENT_KEY_3:
    toggle_find_n_bind();
    return;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You need a function to start the Finding and Binding procedure.&amp;nbsp;This is the toggle_find_n_bind() function you call when button 4 is pressed, as shown above:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Function to start the Finding &amp;amp; Binding Procedure.
 *        If the Finding &amp;amp; Binding Procedure was already started, cancel it.
 */
static zb_void_t toggle_find_n_bind(void)
{
    zb_ret_t zb_err_code;

    zb_err_code = zb_bdb_finding_binding_initiator(LIGHT_SWITCH_ENDPOINT, finding_n_binding_cb);
    if (zb_err_code == RET_OK)
    {
        bsp_board_led_on(FINDING_N_BINDING_STATE_LED);
        NRF_LOG_INFO(&amp;quot;F&amp;amp;B: Started Finding &amp;amp; Binding procedure.&amp;quot;);
    }
    else if (zb_err_code == RET_BUSY)
    {
        zb_bdb_finding_binding_initiator_cancel();
    }
    else if (zb_err_code == RET_INVALID_STATE)
    {
        NRF_LOG_WARNING(&amp;quot;Device not yet commissionned!&amp;quot;);
    }
    else
    {
        ZB_ERROR_CHECK(zb_err_code);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In &lt;span&gt;toggle_find_n_bind,&lt;/span&gt;&amp;nbsp;you&amp;nbsp;initiate the Finding and Binding procedure with&amp;nbsp;zb_bdb_finding_binding_initiator(), which takes in the user callback for the procedure as a parameter,&amp;nbsp;finding_n_binding_cb(). This callback can be implemented like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Callback to finding and binding procedure.
 *
 * @param[IN]   status  Procedure status.
 * @param[IN]   addr    Found device address.
 * @param[IN]   ep      Found device endpoint.
 * @param[IN]   cluster Common cluster ID.
 *
 * @return      Returned boolean value is used to decide if found device&amp;#39;s cluster (ID given as parameter) should be bound.
 */
static zb_bool_t finding_n_binding_cb(zb_int16_t status, zb_ieee_addr_t addr, zb_uint8_t ep, zb_uint16_t cluster)
{
    zb_bool_t ret = ZB_FALSE;
    zb_char_t addr_buf[2 * 8 + 1];    /* 8 bytes (2 characters) plus one byte for null-terminator. */
    
    UNUSED_RETURN_VALUE(ieee_addr_to_str(addr_buf, sizeof(addr_buf), addr));

    switch (status)
    {
        case ZB_BDB_COMM_BIND_SUCCESS:
            NRF_LOG_INFO(&amp;quot;Successfully bound node %s ep %hd cluster %hd&amp;quot;,  NRF_LOG_PUSH(addr_buf), ep, cluster);
            break;

        case ZB_BDB_COMM_BIND_FAIL:
            NRF_LOG_INFO(&amp;quot;Failed to bind node %s ep %hd cluster %hd&amp;quot;, NRF_LOG_PUSH(addr_buf), ep, cluster);
            break;

        case ZB_BDB_COMM_BIND_ASK_USER:
            switch (cluster)
            {
                case ZB_ZCL_CLUSTER_ID_ON_OFF:
                case ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL:
                case ZB_ZCL_CLUSTER_ID_IDENTIFY:
                case ZB_ZCL_CLUSTER_ID_COLOR_CONTROL:
                    NRF_LOG_INFO(&amp;quot;Trying to bind node %s ep %hd cluster %hd&amp;quot;, NRF_LOG_PUSH(addr_buf), ep, cluster);
                    ret = ZB_TRUE;
                    break;
                default:
                    /* We are not interested in this cluster. */
                    break;
            }
            break;

        default:
            /* Should not happen */
            break;
    }

    return ret;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The Zigbee stack will generate the signal&amp;nbsp;ZB_BDB_SIGNAL_FINDING_AND_BINDING_INITIATOR_FINISHED when the Finding and Binding initiator has completed.&amp;nbsp;You do not need to do anything with this signal, but you can use it if you want to get the status of the Finding and Binding procedure, to see if it was successful. If you want to do this, you can handle the signal in the zboss_signal_handler. Inside the switch there, add a case for&amp;nbsp;ZB_BDB_SIGNAL_FINDING_AND_BINDING_INITIATOR_FINISHED:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;        case ZB_BDB_SIGNAL_FINDING_AND_BINDING_INITIATOR_FINISHED:
            {
                zb_zdo_signal_fb_initiator_finished_params_t * f_n_b_status = ZB_ZDO_SIGNAL_GET_PARAMS(p_sg_p, zb_zdo_signal_fb_initiator_finished_params_t);
                switch(f_n_b_status-&amp;gt;status)
                {
                    case ZB_ZDO_FB_INITIATOR_STATUS_SUCCESS:
                        NRF_LOG_INFO(&amp;quot;F&amp;amp;B: Remote peer has been bound&amp;quot;);
                        break;

                    case ZB_ZDO_FB_INITIATOR_STATUS_CANCEL:
                        NRF_LOG_INFO(&amp;quot;F&amp;amp;B: Initiator process was canceled&amp;quot;);
                        break;

                    case ZB_ZDO_FB_INITIATOR_STATUS_ALARM:
                        NRF_LOG_INFO(&amp;quot;F&amp;amp;B: Initiator process was timed out&amp;quot;);
                        break;

                    case ZB_ZDO_FB_INITIATOR_STATUS_ERROR:
                        NRF_LOG_ERROR(&amp;quot;F&amp;amp;B: Error.&amp;quot;);
                        break;

                    default:
                        NRF_LOG_ERROR(&amp;quot;F&amp;amp;B: Unknown error (status %d)&amp;quot;, f_n_b_status-&amp;gt;status);
                        break;
                }
            }
            break;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>