fix(ble/bluedroid): Optimized BLE SPP example for improved compatibility

This commit is contained in:
zhanghaipeng
2024-04-01 14:45:47 +08:00
parent b4d51f2202
commit c13311dacb

View File

@ -1,10 +1,8 @@
/* /*
This example code is in the Public Domain (or CC0 licensed, at your option.) * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
Unless required by applicable law or agreed to in writing, this * SPDX-License-Identifier: Unlicense OR CC0-1.0
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR */
CONDITIONS OF ANY KIND, either express or implied.
*/
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
@ -22,6 +20,7 @@
#include "esp_bt_defs.h" #include "esp_bt_defs.h"
#include "esp_bt_main.h" #include "esp_bt_main.h"
#include "ble_spp_server_demo.h" #include "ble_spp_server_demo.h"
#include "esp_gatt_common_api.h"
#define GATTS_TABLE_TAG "GATTS_SPP_DEMO" #define GATTS_TABLE_TAG "GATTS_SPP_DEMO"
@ -320,7 +319,7 @@ void uart_task(void *pvParameters)
//Waiting for UART event. //Waiting for UART event.
if (xQueueReceive(spp_uart_queue, (void * )&event, (portTickType)portMAX_DELAY)) { if (xQueueReceive(spp_uart_queue, (void * )&event, (portTickType)portMAX_DELAY)) {
switch (event.type) { switch (event.type) {
//Event of UART receving data //Event of UART receiving data
case UART_DATA: case UART_DATA:
if ((event.size)&&(is_connected)) { if ((event.size)&&(is_connected)) {
uint8_t * temp = NULL; uint8_t * temp = NULL;
@ -466,7 +465,7 @@ static void spp_task_init(void)
static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
{ {
esp_err_t err; esp_err_t err;
ESP_LOGE(GATTS_TABLE_TAG, "GAP_EVT, event %d\n", event); ESP_LOGI(GATTS_TABLE_TAG, "GAP_EVT, event %d", event);
switch (event) { switch (event) {
case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT: case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT:
@ -587,6 +586,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_
#endif #endif
break; break;
case ESP_GATTS_DISCONNECT_EVT: case ESP_GATTS_DISCONNECT_EVT:
spp_mtu_size = 23;
is_connected = false; is_connected = false;
enable_data_ntf = false; enable_data_ntf = false;
#ifdef SUPPORT_HEARTBEAT #ifdef SUPPORT_HEARTBEAT
@ -697,5 +697,10 @@ void app_main(void)
spp_task_init(); spp_task_init();
esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(500);
if (local_mtu_ret){
ESP_LOGE(GATTS_TABLE_TAG, "set local MTU failed, error code = %x", local_mtu_ret);
}
return; return;
} }