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.)
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;
}