在长达两年的售后中,收到华为手机连接ESP32蓝牙是最容易断开连接的,一开始小米手机、苹果手机都没问题,就只有华为,一连上就断开,所以我们认为是APP问题,于是我们去找APP的蓝牙底层,每一次的断开连接都是status =8.也看不懂,于是那我就来改ESP32呗。
把ESP32的BLE发射功率调整到最大,
esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_ADV, ESP_PWR_LVL_P9);
然后把超时时间配置大一点、
case ESP_GATTS_CONNECT_EVT:
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GATTS_CONNECT_EVT, conn_id = %d", param->connect.conn_id);
esp_log_buffer_hex(GATTS_TABLE_TAG, param->connect.remote_bda, 6);
esp_ble_conn_update_params_t conn_params = {0};
memcpy(conn_params.bda, param->connect.remote_bda, sizeof(esp_bd_addr_t));
/* For the iOS system, please refer to Apple official documents about the BLE connection parameters restrictions. */
conn_params.latency = 0;
conn_params.max_int = 0x40; // max_int = 0x20*1.25ms = 40ms
conn_params.min_int = 0x20; // min_int = 0x10*1.25ms = 20ms
conn_params.timeout = 1000; // timeout = 400*10ms = 4000ms
//start sent the update connection parameters to the peer device.
esp_ble_gap_update_conn_params(&conn_params);
然后就解决啦,华为P30 PRO P40 MATE40都不会断开连接了!!!!!