Skip to content

Commit

Permalink
samples: Demonstrate conn param update issue
Browse files Browse the repository at this point in the history
Demonstrates the issue with ignored peripheral initiated connection
parameter updates.

Signed-off-by: Thomas Stenersen <[email protected]>
  • Loading branch information
Thomas Stenersen committed Oct 2, 2020
1 parent ee2c66a commit 9a9e240
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions samples/bluetooth/peripheral_hr/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ CONFIG_BT_BAS=y
CONFIG_BT_HRS=y
CONFIG_BT_DEVICE_NAME="Zephyr Heartrate Sensor"
CONFIG_BT_DEVICE_APPEARANCE=833

CONFIG_BT_AUTO_PHY_UPDATE=n
CONFIG_BT_AUTO_DATA_LEN_UPDATE=n
CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n
22 changes: 22 additions & 0 deletions samples/bluetooth/peripheral_hr/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_err.h>
#include <bluetooth/conn.h>
#include <bluetooth/uuid.h>
#include <bluetooth/gatt.h>
#include <bluetooth/services/bas.h>
#include <bluetooth/services/hrs.h>

struct bt_conn *default_conn;
static struct k_delayed_work conn_update_work;

static const struct bt_data ad[] = {
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
Expand All @@ -32,13 +34,33 @@ static const struct bt_data ad[] = {
BT_UUID_16_ENCODE(BT_UUID_DIS_VAL))
};

static void conn_param_update_cb(struct k_work * work)
{
static int conn_int = 20;
if (!default_conn) {
return;
}

int err = bt_conn_le_param_update(default_conn, BT_LE_CONN_PARAM(conn_int, conn_int, 0, 400));
if (err) {
printk("Conn param update failed (err %d)\n", err);
bt_conn_disconnect(default_conn, BT_HCI_ERR_LOCALHOST_TERM_CONN);
}

k_delayed_work_submit(&conn_update_work, K_MSEC(1000));
printk("Called conn update\n");
conn_int += 40;
}

static void connected(struct bt_conn *conn, uint8_t err)
{
if (err) {
printk("Connection failed (err 0x%02x)\n", err);
} else {
default_conn = bt_conn_ref(conn);
printk("Connected\n");
k_delayed_work_init(&conn_update_work, conn_param_update_cb);
k_delayed_work_submit(&conn_update_work, K_MSEC(500));
}
}

Expand Down

0 comments on commit 9a9e240

Please sign in to comment.