我最近使用了 在 DEMO里的 “gatt_client”代码里 加入了 "ble_ibeacon" 的代码,目的是为了在“ESP_GAP_BLE_SCAN_RESULT_EVT” 事件里获取rssi 判断信号强度连接设备。代码里加入了深度随眠,按钮低电平唤醒。不知道哪里出了问题、麻烦帮我看看好吗?谢谢。
唤醒后出现的 ble 告警:
lld_pdu_get_tx_flush_nb HCI packet count mismatch (0, 1)
W (2324) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
lld_pdu_get_tx_flush_nb HCI packet count mismatch (0, 1)
W (2424) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
lld_pdu_get_tx_flush_nb HCI packet count mismatch (0, 1)
W (2524) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
lld_pdu_get_tx_flush_nb HCI packet count mismatch (0, 1)
W (2634) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x3e
W (2634) BT_APPL: gattc_conn_cb: if=3 st=0 id=3 rsn=0x3e
E (2644) GATTC_DEMO: ESP_GATTC_DISCONNECT_EVT, reason = 62
E (2644) GATTC_DEMO: open failed, status 133
[cid:5b229fdf$1$18dbf00e566$Coremail$13410038100$163.com]
事件回调代码:
case ESP_GAP_SEARCH_INQ_RES_EVT:
// ESP_LOGI(GATTC_TAG, "searched Adv Data Len %d, Scan Response Len %d", scan_result->scan_rst.adv_data_len, scan_result->scan_rst.scan_rsp_len);
// ESP_LOGE(GATTC_TAG, "===== MAC ==== %d,%d", has_remote_device_mac(remote_device_mac), memcmp(remote_device_mac, scan_result->scan_rst.bda, sizeof(esp_bd_addr_t)));
if (esp_ble_is_ibeacon_packet(scan_result->scan_rst.ble_adv, scan_result->scan_rst.adv_data_len))
{
esp_ble_ibeacon_t *ibeacon_data = (esp_ble_ibeacon_t *)(scan_result->scan_rst.ble_adv);
adv_name = esp_ble_resolve_adv_data(scan_result->scan_rst.ble_adv,
ESP_BLE_AD_TYPE_NAME_CMPL, &adv_name_len);
if (adv_name != NULL && (strncmp((char *)adv_name, "S", 1) == 0 || strncmp((char *)adv_name, "myBle", 5) == 0))
{
int device_rssi = scan_result->scan_rst.rssi;
ESP_LOGE(GATTC_TAG, "*** searched device adv_name *** %s", adv_name);
esp_log_buffer_hex("IBEACON_DEMO: Device address:", scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
ESP_LOGE(GATTC_TAG, "Measured power (RSSI at a 1m distance):%d dbm", ibeacon_data->ibeacon_vendor.measured_power);
ESP_LOGE(GATTC_TAG, "RSSI of packet:%d dbm\n", scan_result->scan_rst.rssi);
// remote_device_mac 是头一次连接后,存储到nvs里的;设备唤醒后从nvs里取出,有值的话,则匹配这个ble_mac发起连接
if (has_remote_device_mac(remote_device_mac))
{
if (memcmp(remote_device_mac, scan_result->scan_rst.bda, sizeof(esp_bd_addr_t)) == 0 && (device_ble_status == NOT_CONNECT || device_ble_status == SCANNING))
{
device_ble_status = CONNECTING;
esp_ble_gap_stop_scanning();
esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true);
}
}
// 获取信号最好的设备
else if (device_rssi > Base_Rssi && (max_rssi == 0 || device_rssi > max_rssi))
{
max_rssi = device_rssi;
ESP_LOGE(GATTC_TAG, "max_rssi:%d dbm\n", max_rssi);
// memcpy(remote_device_name, (char *)adv_name, adv_name_len);
memcpy(remote_device_mac, scan_result->scan_rst.bda, sizeof(esp_bd_addr_t));
// 在连接回调里会将 remote_device_mac 存到 nvs里面;设备唤醒后从nvs里取出
}
}
}
app_main 里的代码:
void app_main(void)
{
esp_err_t ret;
// 初始化 NVS.
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);
gpio_pad_select_gpio(5); // 选择要操作的GPIO
gpio_set_direction(5, GPIO_MODE_OUTPUT); // 设置GPIO为推挽输出模式
// 在初始化阶段创建互斥锁
xMutex = xSemaphoreCreateMutex();
// 创建GPIO检测任务
// 任务函数, 任务名字, 任务堆栈大小, 传递给任务函数的参数, 任务优先级, 任務句柄
xTaskCreatePinnedToCore(gpio_task, "gpio_task_example", 2048, NULL, 100, &gpio_task_handle, 1);
// 创建发送指令数据任务
xTaskCreatePinnedToCore(set_data_task, "set_data_task", 2048 * 2, NULL, 9, &set_data_handle, 0);
// 创建任务响应request_level
xTaskCreatePinnedToCore(response_task, "response_task", 2048 * 2, NULL, 8, &response_level_handle, 0);
// 创建led闪烁任务
// xTaskCreatePinnedToCore(blink_task, "blink_task", 1024, NULL, 7, &blink_task_handle, 0);
// esp_log_level_set(TAG, ESP_LOG_VERBOSE);
// esp_log_level_set(GPIO_LOG_TAG, ESP_LOG_VERBOSE);
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
if (cause != ESP_SLEEP_WAKEUP_ULP)
{
init_ulp_program();
}
else
{
update_pulse_count();
}
// 按键初始化
gpio_init();
// 按键中断初始化
gpio_intr_init();
init_data();
// 初始化蓝牙
ble_init();
ESP_ERROR_CHECK(esp_sleep_enable_ulp_wakeup());
while (1)
{
// 未加入白名单会在20s后翻转到TO_SLEEP状态
if (device_status == TO_SLEEP)
{
deep_sleep_start();
}
ESP_LOGE(MAIN_TAG, "running ... ");
vTaskDelay(3000 / portTICK_PERIOD_MS);
}
}
esp32 ble 连接告警
-
- Posts: 1
- Joined: Tue Feb 20, 2024 3:30 am
Jump to
- English Forum
- Explore
- News
- General Discussion
- FAQ
- Documentation
- Documentation
- Sample Code
- Discussion Forum
- Hardware
- ESP-IDF
- ESP-BOX
- ESP-ADF
- ESP-MDF
- ESP-WHO
- ESP-SkaiNet
- ESP32 Arduino
- IDEs for ESP-IDF
- ESP-AT
- ESP IoT Solution
- ESP RainMaker
- Rust
- ESP8266
- Report Bugs
- Showcase
- Chinese Forum 中文社区
- 活动区
- 乐鑫活动专区
- 讨论区
- 全国大学生物联网设计竞赛乐鑫答疑专区
- ESP-IDF 中文讨论版
- 《ESP32-C3 物联网工程开发实战》书籍讨论版
- 中文文档讨论版
- ESP-AT 中文讨论版
- ESP-BOX 中文讨论版
- ESP IoT Solution 中文讨论版
- ESP-ADF 中文讨论版
- ESP Mesh 中文讨论版
- ESP Cloud 中文讨论版
- ESP-WHO 中文讨论版
- ESP-SkaiNet 中文讨论版
- ESP 生产支持讨论版
- 硬件问题讨论
- 项目展示
Who is online
Users browsing this forum: No registered users and 203 guests
- All times are UTC
- Top
- Delete cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. ESP8266EX and ESP32 are some of our products.