关于ESP32S3使用nimble库主动扫描,扫描不到响应数据包的问题

hongboyunquan
Posts: 1
Joined: Sat May 20, 2023 7:07 am

关于ESP32S3使用nimble库主动扫描,扫描不到响应数据包的问题

Postby hongboyunquan » Sat May 20, 2023 7:50 am

使用的例程路径:esp-idf-v4.4.4/esp-idf-v4.4.4/examples/bluetooth/nimble/blecent

将static void blecent_scan(void)做如下修改:
static void blecent_scan(void)
{
uint8_t own_addr_type;
struct ble_gap_disc_params disc_params;
int rc;

/* Figure out address to use while advertising (no privacy for now) */
rc = ble_hs_id_infer_auto(0, &own_addr_type);
if (rc != 0)
{
MODLOG_DFLT(ERROR, "error determining address type; rc=%d\n", rc);
return;
}

/* Tell the controller to filter duplicates; we don't want to process
* repeated advertisements from the same device.
*/
disc_params.filter_duplicates = 0;
/**
* Perform a passive scan. I.e., don't send follow-up scan requests to
* each advertiser.
*/
disc_params.passive = 0;

/* Use defaults for the rest of the parameters. */
disc_params.itvl = 0;
disc_params.window = 0;
disc_params.filter_policy = 0;
disc_params.limited = 0;


rc = ble_gap_disc(own_addr_type, BLE_HS_FOREVER, &disc_params, blecent_gap_event, NULL);
if (rc != 0)
{
MODLOG_DFLT(ERROR, "Error initiating GAP discovery procedure; rc=%d\n",
rc);
}

}


在static int blecent_should_connect(const struct ble_gap_disc_desc *disc)中进行广播包以及扫描响应数据包的打印输出:

static int blecent_should_connect(const struct ble_gap_disc_desc *disc)
{
struct ble_hs_adv_fields fields;
int rc;
int i;

/* The device has to be advertising connectability. */
if (disc->event_type != BLE_HCI_ADV_RPT_EVTYPE_ADV_IND &&
disc->event_type != BLE_HCI_ADV_RPT_EVTYPE_DIR_IND)
{

return 0;
}

rc = ble_hs_adv_parse_fields(&fields, disc->data, disc->length_data);
if (rc != 0)
{
return rc;
}
ESP_LOGI(tag, "length_data = %d", disc->length_data);
for (int i = 0; i < disc->length_data; i++)
{
printf("%02X ", disc->data);
}
printf("\n");


if (strlen(CONFIG_EXAMPLE_PEER_ADDR) && (strncmp(CONFIG_EXAMPLE_PEER_ADDR, "ADDR_ANY", strlen("ADDR_ANY")) != 0))
{
ESP_LOGI(tag, "Peer address from menuconfig: %s", CONFIG_EXAMPLE_PEER_ADDR);
/* Convert string to address */
sscanf(CONFIG_EXAMPLE_PEER_ADDR, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
&peer_addr[5], &peer_addr[4], &peer_addr[3],
&peer_addr[2], &peer_addr[1], &peer_addr[0]);
if (memcmp(peer_addr, disc->addr.val, sizeof(disc->addr.val)) != 0)
{
return 0;
}
}

/* The device has to advertise support for the Alert Notification
* service (0x1811).
*/
for (i = 0; i < fields.num_uuids16; i++)
{
if (ble_uuid_u16(&fields.uuids16.u) == BLECENT_SVC_ALERT_UUID)
{
return 1;
}
}

return 0;
}



期望的结果:能够扫描到广播包与扫描响应数据包;


上电后的log输出:
I (1282) NimBLE_BLE_CENT: length_data = 19
02 01 06 �I (22) boot: ESP-IDF v4.4.4-dirty 2nd stage bootloader
I (22) boot: compile time 14:26:44
I (23) boot: chip revision: v0.1
I (25) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (32) boot.esp32s3: Boot SPI Speed : 80MHz
I (37) boot.esp32s3: SPI Mode : DIO
I (41) boot.esp32s3: SPI Flash Size : 2MB
I (46) boot: Enabling RNG early entropy source...
I (52) boot: Partition Table:
I (55) boot: ## Label Usage Type ST Offset Length
I (62) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (70) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (77) boot: 2 factory factory app 00 00 00010000 00100000
I (85) boot: End of partition table
I (89) boot_comm: chip revision: 1, min. application chip revision: 0
I (96) esp_image: segment 0: paddr=00010020 vaddr=3c050020 size=0e770h ( 59248) map
I (115) esp_image: segment 1: paddr=0001e798 vaddr=3fc961f0 size=01880h ( 6272) load
I (117) esp_image: segment 2: paddr=00020020 vaddr=42000020 size=48de0h (298464) map
I (175) esp_image: segment 3: paddr=00068e08 vaddr=3fc97a70 size=023bch ( 9148) load
I (177) esp_image: segment 4: paddr=0006b1cc vaddr=40374000 size=121e8h ( 74216) load
I (204) boot: Loaded app from partition at offset 0x10000
I (204) boot: Disabling RNG early entropy source...
I (216) cpu_start: Pro cpu up.
I (216) cpu_start: Starting app cpu, entry point is 0x40375254
0x40375254: call_start_cpu1 at D:/workspace/vscode_esp/esp/esp-idf/components/esp_system/port/cpu_start.c:148

I (0) cpu_start: App cpu up.
I (230) cpu_start: Pro cpu start user code
I (230) cpu_start: cpu freq: 160000000
I (230) cpu_start: Application information:
I (233) cpu_start: Project name: blecent
I (238) cpu_start: App version: 90c7752d-dirty
I (243) cpu_start: Compile time: May 20 2023 14:27:33
I (249) cpu_start: ELF file SHA256: 580893b9577bc568...
I (255) cpu_start: ESP-IDF: v4.4.4-dirty
I (261) heap_init: Initializing. RAM available for dynamic allocation:
I (268) heap_init: At 3FC9C188 len 0004D588 (309 KiB): D/IRAM
I (274) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
I (281) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (287) heap_init: At 600FE000 len 00002000 (8 KiB): RTCRAM
I (294) spi_flash: detected chip: generic
I (298) spi_flash: flash io: dio
W (302) spi_flash: Detected size(8192k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (316) sleep: Configure to isolate all GPIO pins in sleep state
I (322) sleep: Enable automatic switching of GPIO sleep configuration
I (329) coexist: coexist rom version e7ae62f
I (334) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (422) BT_INIT: BT controller compile version [02bfb7f]
I (422) phy_init: phy_version 540,a5d905b,Oct 20 2022,19:36:11
I (462) system_api: Base MAC address is not set
I (462) system_api: read default base MAC address from EFUSE
I (462) BT_INIT: Bluetooth MAC: 7c:df:a1:e3:c5:f2

I (482) NimBLE_BLE_CENT: BLE Host Task Started
I (482) NimBLE: GAP procedure initiated: stop advertising.

I (482) NimBLE: GAP procedure initiated: discovery;
I (492) NimBLE: own_addr_type=0 filter_policy=0 passive=0 limited=0 filter_duplicates=0
I (502) NimBLE: duration=forever
I (502) NimBLE:

I (532) NimBLE_BLE_CENT: length_data = 19
02 01 06 0F FF 8F 03 0A 10 93 09 00 79 68 18 94 C2 7C 81
I (562) NimBLE_BLE_CENT: length_data = 19
02 01 06 0C 09 43 35 46 32 5F 44 45 56 49 43 45 02 0A 09
I (592) NimBLE_BLE_CENT: length_data = 30

Who is online

Users browsing this forum: Baidu [Spider] and 63 guests