summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2016-02-10 12:17:37 +0200
committerAnas Nashif <anas.nashif@intel.com>2016-02-10 19:13:01 -0500
commit362579cc747a06c99ee345ac8c64742127d8ab75 (patch)
tree0cab3b4ab2fab15254d6faff25c0ae87e51623e3 /samples
parent7dc5596de70996f39f4f6a571ed8a9b963da0771 (diff)
Bluetooth: samples/peripheral_hr: Pass explicit connection to bt_gatt_notify
Change-Id: Ie854ddc3a20ae38df0501ffaa4026dd37c7ae7d8 Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Diffstat (limited to 'samples')
-rw-r--r--samples/bluetooth/peripheral_hr/src/main.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/samples/bluetooth/peripheral_hr/src/main.c b/samples/bluetooth/peripheral_hr/src/main.c
index 22cab799a..f310ffdd9 100644
--- a/samples/bluetooth/peripheral_hr/src/main.c
+++ b/samples/bluetooth/peripheral_hr/src/main.c
@@ -34,6 +34,8 @@
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
#define HEART_RATE_APPEARANCE 0x0341
+struct bt_conn *default_conn;
+
static int read_name(struct bt_conn *conn, const struct bt_gatt_attr *attr,
void *buf, uint16_t len, uint16_t offset)
{
@@ -168,6 +170,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
if (err) {
printk("Connection failed (err %u)\n", err);
} else {
+ default_conn = bt_conn_ref(conn);
printk("Connected\n");
}
}
@@ -183,6 +186,11 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
printk("Advertising failed to restart\n");
}
#endif
+
+ if (default_conn) {
+ bt_conn_unref(default_conn);
+ default_conn = NULL;
+ }
}
static struct bt_conn_cb conn_callbacks = {
@@ -257,7 +265,8 @@ void main(void)
hrm[0] = 0x06; /* uint8, sensor contact */
hrm[1] = 90 + (sys_rand32_get() % 20);
- bt_gatt_notify(NULL, &hrs_attrs[2], &hrm, sizeof(hrm));
+ bt_gatt_notify(default_conn, &hrs_attrs[2],
+ &hrm, sizeof(hrm));
}
/* Battery level simulation */
@@ -269,8 +278,8 @@ void main(void)
battery = 100;
}
- bt_gatt_notify(NULL, &bas_attrs[2], &battery,
- sizeof(battery));
+ bt_gatt_notify(default_conn, &bas_attrs[2],
+ &battery, sizeof(battery));
}
}
}