summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Ruben Bakke <glennbakke@gmail.com>2017-04-02 18:34:56 +0200
committerGlenn Ruben Bakke <glennbakke@gmail.com>2017-04-02 18:34:56 +0200
commit0559be4ffc74ae0b8a28837d4155cfbcb2588860 (patch)
treefec54bdb885c93e61957f3fa660e06b5f16c2bfe
parentce6221ef61b33780e21b202be352c840e1c3848e (diff)
nrf5/bluetooth: Adding possibility to configure whether advertisment should be connectable or not.
-rw-r--r--nrf5/bluetooth/ble_drv.c6
-rw-r--r--nrf5/bluetooth/ble_uart.c2
-rw-r--r--nrf5/examples/ubluepy_eddystone.py2
-rw-r--r--nrf5/modules/ubluepy/modubluepy.h1
-rw-r--r--nrf5/modules/ubluepy/ubluepy_peripheral.c11
5 files changed, 18 insertions, 4 deletions
diff --git a/nrf5/bluetooth/ble_drv.c b/nrf5/bluetooth/ble_drv.c
index f71ef09a5..45b07f18c 100644
--- a/nrf5/bluetooth/ble_drv.c
+++ b/nrf5/bluetooth/ble_drv.c
@@ -548,7 +548,11 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) {
// initialize advertising params
memset(&m_adv_params, 0, sizeof(m_adv_params));
- m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_IND;
+ if (p_adv_params->connectable) {
+ m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_IND;
+ } else {
+ m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_NONCONN_IND;
+ }
m_adv_params.p_peer_addr = NULL; // undirected advertisement
m_adv_params.fp = BLE_GAP_ADV_FP_ANY;
m_adv_params.interval = MSEC_TO_UNITS(100, UNIT_0_625_MS); // approx 8 ms
diff --git a/nrf5/bluetooth/ble_uart.c b/nrf5/bluetooth/ble_uart.c
index b3bad7c41..f9a88fbcc 100644
--- a/nrf5/bluetooth/ble_uart.c
+++ b/nrf5/bluetooth/ble_uart.c
@@ -213,6 +213,8 @@ void ble_uart_init0(void) {
m_rx_ring_buffer.end = 0;
m_rx_ring_buffer.elems = m_rx_ring_buffer_data;
+ adv_data.connectable = true;
+
(void)ble_drv_advertise_data(&adv_data);
while (m_cccd_enabled != true) {
diff --git a/nrf5/examples/ubluepy_eddystone.py b/nrf5/examples/ubluepy_eddystone.py
index c004e6c70..c8abd5aea 100644
--- a/nrf5/examples/ubluepy_eddystone.py
+++ b/nrf5/examples/ubluepy_eddystone.py
@@ -55,4 +55,4 @@ def generate_eddystone_adv_packet(url):
def start():
adv_packet = generate_eddystone_adv_packet("micropython")
p = Peripheral()
- p.advertise(data=adv_packet) \ No newline at end of file
+ p.advertise(data=adv_packet, connectable=False) \ No newline at end of file
diff --git a/nrf5/modules/ubluepy/modubluepy.h b/nrf5/modules/ubluepy/modubluepy.h
index 42a1ae940..1560fa046 100644
--- a/nrf5/modules/ubluepy/modubluepy.h
+++ b/nrf5/modules/ubluepy/modubluepy.h
@@ -150,6 +150,7 @@ typedef struct _ubluepy_advertise_data_t {
uint8_t num_of_services;
uint8_t * p_data;
uint8_t data_len;
+ bool connectable;
} ubluepy_advertise_data_t;
typedef struct _ubluepy_scanner_obj_t {
diff --git a/nrf5/modules/ubluepy/ubluepy_peripheral.c b/nrf5/modules/ubluepy/ubluepy_peripheral.c
index 48748f75f..567093328 100644
--- a/nrf5/modules/ubluepy/ubluepy_peripheral.c
+++ b/nrf5/modules/ubluepy/ubluepy_peripheral.c
@@ -169,14 +169,15 @@ STATIC mp_obj_t peripheral_set_conn_handler(mp_obj_t self_in, mp_obj_t func) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_set_conn_handler_obj, peripheral_set_conn_handler);
-/// \method advertise(device_name, [service=[service1, service2, ...]], [data=bytearray])
-/// Start advertising.
+/// \method advertise(device_name, [service=[service1, service2, ...]], [data=bytearray], [connectable=True])
+/// Start advertising. Connectable advertisment type by default.
///
STATIC mp_obj_t peripheral_advertise(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_device_name, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_services, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_data, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
+ { MP_QSTR_connectable, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
};
// parse args
@@ -187,6 +188,7 @@ STATIC mp_obj_t peripheral_advertise(mp_uint_t n_args, const mp_obj_t *pos_args,
mp_obj_t device_name_obj = args[0].u_obj;
mp_obj_t service_obj = args[1].u_obj;
mp_obj_t data_obj = args[2].u_obj;
+ mp_obj_t connectable_obj = args[3].u_obj;
ubluepy_advertise_data_t adv_data;
memset(&adv_data, 0, sizeof(ubluepy_advertise_data_t));
@@ -219,6 +221,11 @@ STATIC mp_obj_t peripheral_advertise(mp_uint_t n_args, const mp_obj_t *pos_args,
}
}
+ adv_data.connectable = true;
+ if (connectable_obj != mp_const_none && !(mp_obj_is_true(connectable_obj))) {
+ adv_data.connectable = false;
+ }
+
(void)ble_drv_advertise_data(&adv_data);
return mp_const_none;