Closed ericnts closed 1 year ago
@ericnts Please provide the esp32 and S3 sdkconfig files you used for testing and IDF commit
@Weijian-Espressif This is all the files https://github.com/ericnts/esp-gatt
@Weijian-Espressif IDF commit is 1b16ef6c
@ericnts thanks, If this issue is located, I will notify you as soon as possible
diff.patch.zip @ericnts Please use this patch file and retest
@ericnts Is there any update?
@ericnts were you able to test the patch?
@atwoz We have fixed this issue in 2022, and have not waited for your reply. please test the latest IDF, if you want get more adv rsp, please disable scanbackoff in controller menuconfig.
To be more specific, the fix commit on release/4.4 is https://github.com/espressif/esp-idf/commit/da943339adc84e131c90a87fde823c24ad4e6a69, feel free to reopen with more updates.
Answers checklist.
IDF version.
v4.4.2
Operating System used.
macOS
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
No response
Development Kit.
ESP32-S3-Korvo-2
Power Supply used.
Battery
What is the expected behavior?
esp32s3 and esp32 can have the same bluetooth broadcast scanning performance
What is the actual behavior?
Bluetooth broadcast scan of esp32s3 is poor
Steps to reproduce.
ESP32 on the left, ESP32S3 on the right
Debug Logs.
No response
More Information.
`/* 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. */
/**** *
****/
include
include
include
include
include "nvs.h"
include "nvs_flash.h"
include "esp_bt.h"
include "esp_gap_ble_api.h"
include "esp_gattc_api.h"
include "esp_gatt_defs.h"
include "esp_bt_main.h"
include "esp_gatt_common_api.h"
include "esp_log.h"
include "freertos/FreeRTOS.h"
include "freertos/task.h"
include "cJSON.h"
define GATTC_TAG "GATTC_TASK"
define REMOTE_SERVICE_UUID 0xFF00
define REMOTE_DEVID_CHAR_UUID 0xFF01
define REMOTE_DEV_STATE_CHAR_UUID 0xFF06
define REMOTE_AUTH_CHAR_UUID 0xFF0B
define PROFILE_NUM 1
define PROFILE_A_APP_ID 0
define INVALID_HANDLE 0
define SCAN_ALL_THE_TIME 0
//static const char remote_device_name[] = "gattc"; static bool connect = false; static bool get_server = false; static esp_gattc_char_elem_t char_elem_result = NULL; //static esp_gattc_descr_elem_t descr_elem_result = NULL; static esp_ble_gap_cb_param_t scan_rst; //static uint16_t alarm_conn_id = 0; //static uint16_t alarm_srv_start_handle = 0; //static uint16_t alarm_srv_end_handle = 0; //static uint16_t alarm_gattc_if = 0xff;
static const char target_adv_dat[] = {0x02, 0x01, 0x06, 0x1b, 0xff, 0xff, 0xff, 0x4e, 0x42}; / FreeRTOS event group to signal when we are connected & ready to make a request / //static EventGroupHandle_t gattc_event_group;
//const int ALARM_CONNECTED_BIT = BIT0; //const int ALARM_AUTH_BIT = BIT1; //const int ALARM_CLEAR_BIT = BIT2; //const int ALARM_CONNECTED_BIT = BIT3;
static uint32_t gatStatus = 0;
define FLAG_ALARM_CONNECTED (0x01 << 0)
define FLAG_ALARM_AUTH_REQ (0x01 << 1)
define FLAG_ALARM_AUTHED (0x01 << 2)
define FLAG_ALARM_CLEAN_REQ (0x01 << 3)
define FLAG_ALARM_CLEANED (0x01 << 4)
define FLAG_CMD_DISCONNECT_REQ (0x01 << 5)
define FLAG_CMD_CLEAN_REQ (0x01 << 6)
/ Declare static functions / static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t param); static void esp_gattc_cb(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t param); static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param);
static esp_bt_uuid_t remote_filter_service_uuid = { .len = ESP_UUID_LEN_16, .uuid = {.uuid16 = REMOTE_SERVICE_UUID,}, };
static esp_bt_uuid_t remote_filter_char_uuid = { .len = ESP_UUID_LEN_16, .uuid = {.uuid16 = REMOTE_AUTH_CHAR_UUID,}, };
//static esp_bt_uuid_t devid_filter_char_uuid = { // .len = ESP_UUID_LEN_16, // .uuid = {.uuid16 = REMOTE_DEVID_CHAR_UUID,}, //};
static esp_bt_uuid_t state_filter_char_uuid = { .len = ESP_UUID_LEN_16, .uuid = {.uuid16 = REMOTE_DEV_STATE_CHAR_UUID,}, };
//static esp_bt_uuid_t notify_descr_uuid = { // .len = ESP_UUID_LEN_16, // .uuid = {.uuid16 = ESP_GATT_UUID_CHAR_CLIENT_CONFIG,}, //};
static esp_ble_scan_params_t ble_scan_params = { .scan_type = BLE_SCAN_TYPE_ACTIVE, .own_addr_type = BLE_ADDR_TYPE_PUBLIC, .scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL, .scan_interval = 0x50, .scan_window = 0x30, .scan_duplicate = BLE_SCAN_DUPLICATE_DISABLE };
struct gattc_profile_inst { esp_gattc_cb_t gattc_cb; uint16_t gattc_if; uint16_t app_id; uint16_t conn_id; uint16_t service_start_handle; uint16_t service_end_handle; uint16_t char_handle; esp_bd_addr_t remote_bda; };
/ One gatt-based profile one app_id and one gattc_if, this array will store the gattc_if returned by ESP_GATTS_REG_EVT / static struct gattc_profile_inst gl_profile_tab[PROFILE_NUM] = { [PROFILE_A_APP_ID] = { .gattc_cb = gattc_profile_event_handler, .gattc_if = ESP_GATT_IF_NONE, / Not get the gatt_if, so initial is ESP_GATT_IF_NONE / }, };
void clear_warning(void){
}
static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t param) { esp_ble_gattc_cb_param_t p_data = (esp_ble_gattc_cb_param_t *)param;
}
static uint32_t gattc_ticks = 0, gattc_max = 0; static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t param) { uint8_t adv_name = NULL; uint8_t adv_name_len = 0; switch (event) { case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: { //the unit of the duration is second //uint32_t duration = 10; esp_ble_gap_start_scanning(SCAN_ALL_THE_TIME); break; } case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT: //scan start complete event to indicate scan start successfully or failed if (param->scan_start_cmpl.status != ESP_BT_STATUS_SUCCESS) { ESP_LOGE(GATTC_TAG, "scan start failed, error status = %x", param->scan_start_cmpl.status); break; } ESP_LOGI(GATTC_TAG, "scan start success"); gattc_ticks = xTaskGetTickCount(); break; case ESP_GAP_BLE_SCAN_RESULT_EVT: { esp_ble_gap_cb_param_t scan_result = (esp_ble_gap_cb_param_t )param; uint8_t i;
}
static void esp_gattc_cb(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t param) { / If event is register event, store the gattc_if for each profile */ if (event == ESP_GATTC_REG_EVT) { if (param->reg.status == ESP_GATT_OK) { gl_profile_tab[param->reg.app_id].gattc_if = gattc_if; } else { ESP_LOGI(GATTC_TAG, "reg app failed, app_id %04x, status %d", param->reg.app_id, param->reg.status); return; } }
}
void gattc_task(void *pvParameters) { while(1){ if((connect == true) && (gatStatus & FLAG_ALARM_AUTHED)){ if(gatStatus & FLAG_CMD_DISCONNECT_REQ){ gatStatus &= ~FLAG_CMD_DISCONNECT_REQ; esp_ble_gap_disconnect(gl_profile_tab[PROFILE_A_APP_ID].remote_bda); }
}
uint8_t gattc_app_main(void) { // Initialize NVS. esp_err_t ret = nvs_flash_init(); if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { ESP_ERROR_CHECK(nvs_flash_erase()); ret = nvs_flash_init(); } ESP_ERROR_CHECK( ret );
}
void app_main(void){ gattc_app_main();
}
`