Re: Zephyr ble nrf52840 how to enable indications


Lawrence King
 

Hi Teijo

 

I’m not sure if this code fragment solves your problem

 

 

        /** @brief LE connection parameter update request.

         *

         *  This callback notifies the application that a remote device

         *  is requesting to update the connection parameters. The

         *  application accepts the parameters by returning true, or

         *  rejects them by returning false. Before accepting, the

         *  application may also adjust the parameters to better suit

         *  its needs.

         *

         *  It is recommended for an application to have just one of these

         *  callbacks for simplicity. However, if an application registers

         *  multiple it needs to manage the potentially different

         *  requirements for each callback. Each callback gets the

         *  parameters as returned by previous callbacks, i.e. they are not

         *  necessarily the same ones as the remote originally sent.

         *

         *  @param conn Connection object.

         *  @param param Proposed connection parameters.

         *

         *  @return true to accept the parameters, or false to reject them.

         */

static bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param)

{

        time_stamp_print();

        printf("le_param_req() - interval_min=%d, interval_max=%d, latency=%d, timeout=%d\n", param->interval_min, param->interval_min, param->latency, param->timeout);

        return(true);

}

        /** @brief The parameters for an LE connection have been updated.

         *

         *  This callback notifies the application that the connection

         *  parameters for an LE connection have been updated.

         *

         *  @param conn Connection object.

         *  @param interval Connection interval.

         *  @param latency Connection latency.

         *  @param timeout Connection supervision timeout.

         */

static void le_param_updated(struct bt_conn *conn, u16_t interval, u16_t latency, u16_t timeout)

{

        time_stamp_print();

        printf("le_param_updated() - interval=%d, latency=%d, timeout=%d", interval, latency, timeout);

        if (interval==6) {

                // the Android Pixel3 requests this first

                printf("\n");

                return;

        }

        if (interval==39) {

                // the Samsung J7 requests this

                return;

        }

        if (interval==36) {

                // the iPad and the Pixel3 requests this

                printf("\n");

                return;

        }

        printf(" - UNKNOWN interval=%d\n",interval);

}

 

#if defined(CONFIG_BT_SMP)

        /** @brief Remote Identity Address has been resolved.

         *

         *  This callback notifies the application that a remote

         *  Identity Address has been resolved

         *

         *  @param conn Connection object.

         *  @param rpa Resolvable Private Address.

         *  @param identity Identity Address.

         */

static void identity_resolved(struct bt_conn *conn,

                                  const bt_addr_le_t *rpa,

                                  const bt_addr_le_t *identity)

{

        time_stamp_print();

        printf("identity_resolved() - called\n");

}

#endif /* CONFIG_BT_SMP */

 

#if defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR)

        /** @brief The security level of a connection has changed.

         *

         *  This callback notifies the application that the security level

         *  of a connection has changed.

         *

         *  @param conn Connection object.

         *  @param level New security level of the connection.

         *  @param err Security error. Zero for success, non-zero otherwise.

         */

static void security_changed(struct bt_conn *conn, bt_security_t level,

                                 enum bt_security_err err)

{

        time_stamp_print();

        printf("security_changed() - level=%d, err=%d\n", level, err);

        // if the iphone selects pair then level==2 otherwise level==1 and err==8

        if (level==2) {

        }

}

#endif /* defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR) */

 

static struct bt_conn_cb conn_callbacks = {

        .connected = connected,

        .disconnected = disconnected,

        .le_param_req=le_param_req,

        .le_param_updated=le_param_updated,

#if defined(CONFIG_BT_SMP)

        .identity_resolved=identity_resolved,

#endif /* CONFIG_BT_SMP */

#if defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR)

        .security_changed=security_changed,

#endif /* defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR) */

};

 

 

main()

{

        rc = bt_enable(bt_ready);

        if (rc != 0) {

                printf("blue_init() - bt_enable() failed (err %d)\n", rc);

                return;

        }

        bt_conn_cb_register(&conn_callbacks);

}

 

At the time I wrote this code the examples in the zephyr never set the callbacks beyond .connected and .disconnected so it took me a while to figure out that there were more callbacks available from the bt stack.

 

Lawrence King

Principal Developer

+1(416)627-7302

 

From: devel@... <devel@...> On Behalf Of Teijo Kauppi
Sent: Friday, February 21, 2020 6:21 AM
To: devel@...
Subject: [Zephyr-devel] Zephyr ble nrf52840 how to enable indications

 

Hi,

 

I've tinkering with bluetooth/peripheral and bluetooth/central_hr/ examples and i have a questions:

1. How i enable indications in central code so that function vnd_ccc_cfg_changed in peripheral is called so cental can receive indications?

2. In central side subscribe_params have notify callback but no indication. I assumed that callback is for both notify and indication. if not is there another way to receive indications

 

Thanks

Join devel@lists.zephyrproject.org to automatically receive all group messages.