Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 30053c5

Browse files
author
iwahdan88
committed
esp32/modbt: Updated adv config to split info between adv packet and scan response.
1 parent 0ce93d4 commit 30053c5

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

esp32/mods/modbt.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ static volatile bt_obj_t bt_obj;
209209
static QueueHandle_t xScanQueue;
210210
static QueueHandle_t xGattsQueue;
211211

212+
static esp_ble_adv_data_t adv_data;
213+
static esp_ble_adv_data_t scan_rsp_data;
214+
212215
static const mp_obj_type_t mod_bt_connection_type;
213216
static const mp_obj_type_t mod_bt_service_type;
214217
static const mp_obj_type_t mod_bt_characteristic_type;
@@ -219,7 +222,7 @@ static const mp_obj_type_t mod_bt_gatts_char_type;
219222

220223
static esp_ble_adv_params_t bt_adv_params = {
221224
.adv_int_min = 0x20,
222-
.adv_int_max = 0x20,
225+
.adv_int_max = 0x40,
223226
.adv_type = ADV_TYPE_IND,
224227
.own_addr_type = BLE_ADDR_TYPE_PUBLIC,
225228
.channel_map = ADV_CHNL_ALL,
@@ -684,7 +687,7 @@ static mp_obj_t bt_init_helper(bt_obj_t *self, const mp_arg_val_t *args) {
684687
esp_ble_gattc_app_register(MOD_BT_CLIENT_APP_ID);
685688
esp_ble_gatts_app_register(MOD_BT_SERVER_APP_ID);
686689

687-
esp_ble_gatt_set_local_mtu(200);
690+
esp_ble_gatt_set_local_mtu(500);
688691

689692
self->init = true;
690693
}
@@ -989,7 +992,6 @@ STATIC mp_obj_t bt_set_advertisement (mp_uint_t n_args, const mp_obj_t *pos_args
989992
{ MP_QSTR_service_uuid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
990993
};
991994

992-
esp_ble_adv_data_t adv_data;
993995
mp_buffer_info_t manuf_bufinfo;
994996
mp_buffer_info_t srv_bufinfo;
995997
mp_buffer_info_t uuid_bufinfo;
@@ -1056,7 +1058,21 @@ STATIC mp_obj_t bt_set_advertisement (mp_uint_t n_args, const mp_obj_t *pos_args
10561058
adv_data.appearance = 0x00;
10571059
adv_data.flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT);
10581060

1061+
// copy all the info to the scan response
1062+
memcpy(&scan_rsp_data, &adv_data, sizeof(esp_ble_adv_data_t));
1063+
scan_rsp_data.set_scan_rsp = true;
1064+
// do not include the name or the tx power in the scan response
1065+
scan_rsp_data.include_name = false;
1066+
scan_rsp_data.include_txpower = false;
1067+
// do not include the service uuid or service data in the advertisement, only in the scan response
1068+
adv_data.manufacturer_len = 0;
1069+
adv_data.p_manufacturer_data = NULL;
1070+
adv_data.service_data_len = 0;
1071+
adv_data.p_service_data = NULL;
1072+
adv_data.service_uuid_len = 0;
1073+
adv_data.p_service_uuid = NULL;
10591074
esp_ble_gap_config_adv_data(&adv_data);
1075+
esp_ble_gap_config_adv_data(&scan_rsp_data);
10601076

10611077
// wait for the advertisement data to be configured
10621078
bt_gatts_event_result_t gatts_event;
@@ -1068,6 +1084,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bt_set_advertisement_obj, 1, bt_set_advertisem
10681084

10691085
STATIC mp_obj_t bt_advertise(mp_obj_t self_in, mp_obj_t enable) {
10701086
if (mp_obj_is_true(enable)) {
1087+
// some sensible time to wait for the advertisement configuration to complete
1088+
mp_hal_delay_ms(50);
10711089
esp_ble_gap_start_advertising(&bt_adv_params);
10721090
bt_obj.advertising = true;
10731091
} else {

0 commit comments

Comments
 (0)