From c13311dacb32d8d807dd72a74fd28122a0c584c4 Mon Sep 17 00:00:00 2001 From: zhanghaipeng Date: Mon, 1 Apr 2024 14:45:47 +0800 Subject: [PATCH] fix(ble/bluedroid): Optimized BLE SPP example for improved compatibility --- .../ble_spp_server/main/ble_spp_server_demo.c | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/examples/bluetooth/bluedroid/ble/ble_spp_server/main/ble_spp_server_demo.c b/examples/bluetooth/bluedroid/ble/ble_spp_server/main/ble_spp_server_demo.c index ab74b89667..5d3970ea0c 100644 --- a/examples/bluetooth/bluedroid/ble/ble_spp_server/main/ble_spp_server_demo.c +++ b/examples/bluetooth/bluedroid/ble/ble_spp_server/main/ble_spp_server_demo.c @@ -1,10 +1,8 @@ /* - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ #include "freertos/FreeRTOS.h" @@ -22,6 +20,7 @@ #include "esp_bt_defs.h" #include "esp_bt_main.h" #include "ble_spp_server_demo.h" +#include "esp_gatt_common_api.h" #define GATTS_TABLE_TAG "GATTS_SPP_DEMO" @@ -320,7 +319,7 @@ void uart_task(void *pvParameters) //Waiting for UART event. if (xQueueReceive(spp_uart_queue, (void * )&event, (portTickType)portMAX_DELAY)) { switch (event.type) { - //Event of UART receving data + //Event of UART receiving data case UART_DATA: if ((event.size)&&(is_connected)) { 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) { 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) { 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 break; case ESP_GATTS_DISCONNECT_EVT: + spp_mtu_size = 23; is_connected = false; enable_data_ntf = false; #ifdef SUPPORT_HEARTBEAT @@ -697,5 +697,10 @@ void app_main(void) 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; }