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

Commit d5787f4

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

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,
@@ -794,7 +797,7 @@ static mp_obj_t bt_init_helper(bt_obj_t *self, const mp_arg_val_t *args) {
794797
esp_ble_gattc_app_register(MOD_BT_CLIENT_APP_ID);
795798
esp_ble_gatts_app_register(MOD_BT_SERVER_APP_ID);
796799

797-
esp_ble_gatt_set_local_mtu(200);
800+
esp_ble_gatt_set_local_mtu(500);
798801

799802
self->init = true;
800803
}
@@ -1209,7 +1212,6 @@ STATIC mp_obj_t bt_set_advertisement (mp_uint_t n_args, const mp_obj_t *pos_args
12091212
{ MP_QSTR_service_uuid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
12101213
};
12111214

1212-
esp_ble_adv_data_t adv_data;
12131215
mp_buffer_info_t manuf_bufinfo;
12141216
mp_buffer_info_t srv_bufinfo;
12151217
mp_buffer_info_t uuid_bufinfo;
@@ -1276,7 +1278,21 @@ STATIC mp_obj_t bt_set_advertisement (mp_uint_t n_args, const mp_obj_t *pos_args
12761278
adv_data.appearance = 0x00;
12771279
adv_data.flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT);
12781280

1281+
// copy all the info to the scan response
1282+
memcpy(&scan_rsp_data, &adv_data, sizeof(esp_ble_adv_data_t));
1283+
scan_rsp_data.set_scan_rsp = true;
1284+
// do not include the name or the tx power in the scan response
1285+
scan_rsp_data.include_name = false;
1286+
scan_rsp_data.include_txpower = false;
1287+
// do not include the service uuid or service data in the advertisement, only in the scan response
1288+
adv_data.manufacturer_len = 0;
1289+
adv_data.p_manufacturer_data = NULL;
1290+
adv_data.service_data_len = 0;
1291+
adv_data.p_service_data = NULL;
1292+
adv_data.service_uuid_len = 0;
1293+
adv_data.p_service_uuid = NULL;
12791294
esp_ble_gap_config_adv_data(&adv_data);
1295+
esp_ble_gap_config_adv_data(&scan_rsp_data);
12801296

12811297
// wait for the advertisement data to be configured
12821298
bt_gatts_event_result_t gatts_event;
@@ -1288,6 +1304,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bt_set_advertisement_obj, 1, bt_set_advertisem
12881304

12891305
STATIC mp_obj_t bt_advertise(mp_obj_t self_in, mp_obj_t enable) {
12901306
if (mp_obj_is_true(enable)) {
1307+
// some sensible time to wait for the advertisement configuration to complete
1308+
mp_hal_delay_ms(50);
12911309
esp_ble_gap_start_advertising(&bt_adv_params);
12921310
bt_obj.advertising = true;
12931311
} else {

0 commit comments

Comments
 (0)