nrf5/bluetooth: Adding possibility to configure whether advertisment should be connectable or not.
This commit is contained in:
parent
ce6221ef61
commit
0559be4ffc
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
p.advertise(data=adv_packet, connectable=False)
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user