完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
使用的例程路径: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=%dn", 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=%dn", 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 |
|
相关推荐
1个回答
|
|
在ESP32S3使用NimBLE库进行主动扫描时,如果扫描不到响应数据包,可能有以下几个原因:
1. 扫描参数设置不正确:请检查`ble_gap_disc_params`结构体中的参数设置是否正确。例如,扫描间隔(`itvl`)和扫描窗口(`window`)应该设置在合适的范围内。过小的扫描窗口可能导致扫描不到设备。 2. 被扫描设备未处于可发现状态:请确保被扫描的设备已经启动了广播,并设置为可发现模式。如果设备没有广播或未设置为可发现模式,扫描设备将无法发现它。 3. 扫描和广播信道不匹配:BLE使用3个广播信道(37、38、39),扫描设备和被扫描设备需要在相同的信道上才能互相发现。请检查您的扫描参数和被扫描设备的广播信道设置。 4. 信号强度问题:如果扫描设备和被扫描设备之间的距离过远,信号强度可能不足以建立连接。请尝试减小两者之间的距离,以提高信号强度。 5. 干扰问题:在某些情况下,其他无线设备可能会对BLE信号产生干扰,导致扫描失败。请确保扫描环境没有其他无线设备的干扰。 6. 代码问题:请检查您的代码逻辑是否正确,特别是在调用`ble_gap_disc`函数时,确保传入的参数正确无误。 为了解决这个问题,您可以尝试以下步骤: 1. 检查`ble_gap_disc_params`结构体中的参数设置,确保扫描间隔和扫描窗口设置在合适的范围内。 2. 确保被扫描设备已经启动了广播,并设置为可发现模式。 3. 检查扫描设备和被扫描设备的广播信道设置,确保它们在相同的信道上。 4. 尝试减小扫描设备和被扫描设备之间的距离,以提高信号强度。 5. 确保扫描环境没有其他无线设备的干扰。 6. 仔细检查您的代码逻辑,确保调用`ble_gap_disc`函数时传入的参数正确无误。 通过以上步骤,您应该能够找到导致扫描不到响应数据包的原因,并采取相应的措施解决问题。 |
|
|
|
只有小组成员才能发言,加入小组>>
1149 浏览 1 评论
582浏览 6评论
480浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
465浏览 5评论
466浏览 4评论
441浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 07:18 , Processed in 0.944965 second(s), Total 78, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号