@@ -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 ,
@@ -684,7 +687,7 @@ static mp_obj_t bt_init_helper(bt_obj_t *self, const mp_arg_val_t *args) {
684
687
esp_ble_gattc_app_register (MOD_BT_CLIENT_APP_ID );
685
688
esp_ble_gatts_app_register (MOD_BT_SERVER_APP_ID );
686
689
687
- esp_ble_gatt_set_local_mtu (200 );
690
+ esp_ble_gatt_set_local_mtu (500 );
688
691
689
692
self -> init = true;
690
693
}
@@ -989,7 +992,6 @@ STATIC mp_obj_t bt_set_advertisement (mp_uint_t n_args, const mp_obj_t *pos_args
989
992
{ MP_QSTR_service_uuid , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } },
990
993
};
991
994
992
- esp_ble_adv_data_t adv_data ;
993
995
mp_buffer_info_t manuf_bufinfo ;
994
996
mp_buffer_info_t srv_bufinfo ;
995
997
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
1056
1058
adv_data .appearance = 0x00 ;
1057
1059
adv_data .flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT );
1058
1060
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 ;
1059
1074
esp_ble_gap_config_adv_data (& adv_data );
1075
+ esp_ble_gap_config_adv_data (& scan_rsp_data );
1060
1076
1061
1077
// wait for the advertisement data to be configured
1062
1078
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
1068
1084
1069
1085
STATIC mp_obj_t bt_advertise (mp_obj_t self_in , mp_obj_t enable ) {
1070
1086
if (mp_obj_is_true (enable )) {
1087
+ // some sensible time to wait for the advertisement configuration to complete
1088
+ mp_hal_delay_ms (50 );
1071
1089
esp_ble_gap_start_advertising (& bt_adv_params );
1072
1090
bt_obj .advertising = true;
1073
1091
} else {
0 commit comments