@@ -209,6 +209,9 @@ static volatile bt_obj_t bt_obj;
209
209
static QueueHandle_t xScanQueue ;
210
210
static QueueHandle_t xGattsQueue ;
211
211
212
+ static esp_ble_adv_data_t adv_data ;
213
+ static esp_ble_adv_data_t scan_rsp_data ;
214
+
212
215
static const mp_obj_type_t mod_bt_connection_type ;
213
216
static const mp_obj_type_t mod_bt_service_type ;
214
217
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;
219
222
220
223
static esp_ble_adv_params_t bt_adv_params = {
221
224
.adv_int_min = 0x20 ,
222
- .adv_int_max = 0x20 ,
225
+ .adv_int_max = 0x40 ,
223
226
.adv_type = ADV_TYPE_IND ,
224
227
.own_addr_type = BLE_ADDR_TYPE_PUBLIC ,
225
228
.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) {
794
797
esp_ble_gattc_app_register (MOD_BT_CLIENT_APP_ID );
795
798
esp_ble_gatts_app_register (MOD_BT_SERVER_APP_ID );
796
799
797
- esp_ble_gatt_set_local_mtu (200 );
800
+ esp_ble_gatt_set_local_mtu (500 );
798
801
799
802
self -> init = true;
800
803
}
@@ -1209,7 +1212,6 @@ STATIC mp_obj_t bt_set_advertisement (mp_uint_t n_args, const mp_obj_t *pos_args
1209
1212
{ MP_QSTR_service_uuid , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } },
1210
1213
};
1211
1214
1212
- esp_ble_adv_data_t adv_data ;
1213
1215
mp_buffer_info_t manuf_bufinfo ;
1214
1216
mp_buffer_info_t srv_bufinfo ;
1215
1217
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
1276
1278
adv_data .appearance = 0x00 ;
1277
1279
adv_data .flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT );
1278
1280
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 ;
1279
1294
esp_ble_gap_config_adv_data (& adv_data );
1295
+ esp_ble_gap_config_adv_data (& scan_rsp_data );
1280
1296
1281
1297
// wait for the advertisement data to be configured
1282
1298
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
1288
1304
1289
1305
STATIC mp_obj_t bt_advertise (mp_obj_t self_in , mp_obj_t enable ) {
1290
1306
if (mp_obj_is_true (enable )) {
1307
+ // some sensible time to wait for the advertisement configuration to complete
1308
+ mp_hal_delay_ms (50 );
1291
1309
esp_ble_gap_start_advertising (& bt_adv_params );
1292
1310
bt_obj .advertising = true;
1293
1311
} else {
0 commit comments