你看下我得操作步骤:
1、用示例工程生成一个ble4.2的server工程
2、在main_app函数中加上show_bonded_devices();
- 1.png (40.01 KiB) Viewed 5013 times
3、设置ble地址为固定地址,防止每次都产生一个新的蓝牙记录。
- 2.png (21.36 KiB) Viewed 5013 times
- 3.png (39.5 KiB) Viewed 5013 times
4、然后编译烧写后,第一次打开用手机系统的蓝牙设置连接一下。
5、重启设备,先不用手机连接,观察show_bonded_devices() 函数的打印信息。
-------------------------------------------------一下是日志----------------------------------------------------
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x18 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
Octal Flash Mode Enabled
For OPI Flash, Use Default Flash Boot Mode
mode:SLOW_RD, clock div:1
load:0x3fce3808,len:0x1654
load:0x403c9700,len:0xbb8
load:0x403cc700,len:0x2f88
SHA-256 comparison failed:
Calculated: b7ce2f7693df2d6f0d0090eeaf59e9d7f3dc2aa28824f5729293528e3c41f764
Expected: 1d9205207d8d1080d6f0cfe002218a5b76dfac59ac50890fc374c07311e16718
Attempting to boot anyway...
entry 0x403c9954
I (50) boot: ESP-IDF v4.4.2-dirty 2nd stage bootloader
I (51) boot: compile time 18:00:25
I (51) boot: chip revision: 0
I (53) boot.esp32s3: Boot SPI Speed : 80MHz
I (58) boot.esp32s3: SPI Mode : SLOW READ
I (63) boot.esp32s3: SPI Flash Size : 4MB
I (67) boot: Enabling RNG early entropy source...
I (73) boot: Partition Table:
I (76) boot: ## Label Usage Type ST Offset Length
I (84) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (91) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (99) boot: 2 factory factory app 00 00 00010000 00100000
I (106) boot: End of partition table
I (110) esp_image: segment 0: paddr=00010020 vaddr=3c080020 size=1c7ach (116652) map
I (146) esp_image: segment 1: paddr=0002c7d4 vaddr=3fc945b0 size=03844h ( 14404) load
I (150) esp_image: segment 2: paddr=00030020 vaddr=42000020 size=713b0h (463792) map
I (261) esp_image: segment 3: paddr=000a13d8 vaddr=3fc97df4 size=000d8h ( 216) load
I (262) esp_image: segment 4: paddr=000a14b8 vaddr=40374000 size=105b0h ( 66992) load
I (285) esp_image: segment 5: paddr=000b1a70 vaddr=50000000 size=00010h ( 16) load
I (292) boot: Loaded app from partition at offset 0x10000
I (292) boot: Disabling RNG early entropy source...
I (306) cpu_start: Pro cpu up.
I (306) cpu_start: Starting app cpu, entry point is 0x40375194
0x40375194: call_start_cpu1 at D:/software/Espressif/frameworks/esp-idf-v4.4.2/components/esp_system/port/cpu_start.c:160
I (0) cpu_start: App cpu up.
I (320) cpu_start: Pro cpu start user code
I (320) cpu_start: cpu freq: 160000000
I (320) cpu_start: Application information:
I (322) cpu_start: Project name: sec_gatts_demo
I (328) cpu_start: App version: 1
I (332) cpu_start: Compile time: Sep 1 2022 18:00:04
I (339) cpu_start: ELF file SHA256: 0bb7ff711e029e97...
I (345) cpu_start: ESP-IDF: v4.4.2-dirty
I (350) heap_init: Initializing. RAM available for dynamic allocation:
I (357) heap_init: At 3FC9BD40 len 000442C0 (272 KiB): D/IRAM
I (364) heap_init: At 3FCE0000 len 0000EE34 (59 KiB): STACK/DRAM
I (370) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (377) spi_flash: detected chip: mxic
W (381) spi_flash: Detected flash size > 16 MB, but access beyond 16 MB is not supported for this flash model yet.
I (392) spi_flash: flash io: dio
W (396) spi_flash: Detected size(32768k) larger than the size in the binary image header(4096k). Using the size in the binary image header.
I (410) sleep: Configure to isolate all GPIO pins in sleep state
I (416) sleep: Enable automatic switching of GPIO sleep configuration
I (423) coexist: coexist rom version e7ae62f
I (428) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
W (469) BT_INIT: esp_bt_controller_mem_release not implemented, return OK
I (469) BT_INIT: BT controller compile version [05195c9]
I (469) phy_init: phy_version 503,13653eb,Jun 1 2022,17:47:08
W (479) phy_init: failed to load RF calibration data (0x1102), falling back to full calibration
I (529) system_api: Base MAC address is not set
I (529) system_api: read default base MAC address from EFUSE
I (529) BT_INIT: Bluetooth MAC: 7c:df:a1:e1:10:c6
I (539) SEC_GATTS_DEMO: app_main init bluetooth
I (579) SEC_GATTS_DEMO: The number handle = 8
I (589) SEC_GATTS_DEMO: advertising start success
I (589) SEC_GATTS_DEMO: Bonded devices number : 0
I (589) SEC_GATTS_DEMO: Bonded devices list : 0
I (4129) SEC_GATTS_DEMO: ESP_GATTS_CONNECT_EVT
W (5619) BT_SMP: FOR LE SC LTK IS USED INSTEAD OF STK
I (5749) SEC_GATTS_DEMO: key type = ESP_LE_KEY_LENC
I (5749) SEC_GATTS_DEMO: key type = ESP_LE_KEY_PENC
I (5749) SEC_GATTS_DEMO: key type = ESP_LE_KEY_LID
I (5849) SEC_GATTS_DEMO: key type = ESP_LE_KEY_PID
I (5879) SEC_GATTS_DEMO: remote BD_ADDR: 579159b80052
I (5879) SEC_GATTS_DEMO: address type = 1
I (5879) SEC_GATTS_DEMO: pair status = success
I (5879) SEC_GATTS_DEMO: auth mode = ESP_LE_AUTH_REQ_SC_BOND
I (5889) SEC_GATTS_DEMO: Bonded devices number : 1
I (5889) SEC_GATTS_DEMO: Bonded devices list : 1
I (5899) SEC_GATTS_DEMO: 57 91 59 b8 00 52
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x18 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
Octal Flash Mode Enabled
For OPI Flash, Use Default Flash Boot Mode
mode:SLOW_RD, clock div:1
load:0x3fce3808,len:0x1654
load:0x403c9700,len:0xbb8
load:0x403cc700,len:0x2f88
SHA-256 comparison failed:
Calculated: b7ce2f7693df2d6f0d0090eeaf59e9d7f3dc2aa28824f5729293528e3c41f764
Expected: 1d9205207d8d1080d6f0cfe002218a5b76dfac59ac50890fc374c07311e16718
Attempting to boot anyway...
entry 0x403c9954
I (50) boot: ESP-IDF v4.4.2-dirty 2nd stage bootloader
I (51) boot: compile time 18:00:25
I (51) boot: chip revision: 0
I (53) boot.esp32s3: Boot SPI Speed : 80MHz
I (58) boot.esp32s3: SPI Mode : SLOW READ
I (63) boot.esp32s3: SPI Flash Size : 4MB
I (67) boot: Enabling RNG early entropy source...
I (73) boot: Partition Table:
I (76) boot: ## Label Usage Type ST Offset Length
I (84) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (91) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (99) boot: 2 factory factory app 00 00 00010000 00100000
I (106) boot: End of partition table
I (110) esp_image: segment 0: paddr=00010020 vaddr=3c080020 size=1c7ach (116652) map
I (146) esp_image: segment 1: paddr=0002c7d4 vaddr=3fc945b0 size=03844h ( 14404) load
I (150) esp_image: segment 2: paddr=00030020 vaddr=42000020 size=713b0h (463792) map
I (261) esp_image: segment 3: paddr=000a13d8 vaddr=3fc97df4 size=000d8h ( 216) load
I (262) esp_image: segment 4: paddr=000a14b8 vaddr=40374000 size=105b0h ( 66992) load
I (285) esp_image: segment 5: paddr=000b1a70 vaddr=50000000 size=00010h ( 16) load
I (292) boot: Loaded app from partition at offset 0x10000
I (292) boot: Disabling RNG early entropy source...
I (306) cpu_start: Pro cpu up.
I (306) cpu_start: Starting app cpu, entry point is 0x40375194
0x40375194: call_start_cpu1 at D:/software/Espressif/frameworks/esp-idf-v4.4.2/components/esp_system/port/cpu_start.c:160
I (0) cpu_start: App cpu up.
I (320) cpu_start: Pro cpu start user code
I (320) cpu_start: cpu freq: 160000000
I (320) cpu_start: Application information:
I (322) cpu_start: Project name: sec_gatts_demo
I (328) cpu_start: App version: 1
I (332) cpu_start: Compile time: Sep 1 2022 18:00:04
I (339) cpu_start: ELF file SHA256: 0bb7ff711e029e97...
I (345) cpu_start: ESP-IDF: v4.4.2-dirty
I (350) heap_init: Initializing. RAM available for dynamic allocation:
I (357) heap_init: At 3FC9BD40 len 000442C0 (272 KiB): D/IRAM
I (364) heap_init: At 3FCE0000 len 0000EE34 (59 KiB): STACK/DRAM
I (370) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (377) spi_flash: detected chip: mxic
W (381) spi_flash: Detected flash size > 16 MB, but access beyond 16 MB is not supported for this flash model yet.
I (392) spi_flash: flash io: dio
W (396) spi_flash: Detected size(32768k) larger than the size in the binary image header(4096k). Using the size in the binary image header.
I (410) sleep: Configure to isolate all GPIO pins in sleep state
I (416) sleep: Enable automatic switching of GPIO sleep configuration
I (423) coexist: coexist rom version e7ae62f
I (428) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
W (469) BT_INIT: esp_bt_controller_mem_release not implemented, return OK
I (469) BT_INIT: BT controller compile version [05195c9]
I (469) phy_init: phy_version 503,13653eb,Jun 1 2022,17:47:08
W (479) phy_init: failed to load RF calibration data (0x1102), falling back to full calibration
I (529) system_api: Base MAC address is not set
I (529) system_api: read default base MAC address from EFUSE
I (529) BT_INIT: Bluetooth MAC: 7c:df:a1:e1:10:c6
I (529) SEC_GATTS_DEMO: app_main init bluetooth
I (579) SEC_GATTS_DEMO: The number handle = 8
I (589) SEC_GATTS_DEMO: advertising start success
I (589) SEC_GATTS_DEMO: Bonded devices number : 0
I (589) SEC_GATTS_DEMO: Bonded devices list : 0
--------------------------------------以上是日志------------------------------------------------
ESP_XuLZ wrote: ↑Wed Aug 31, 2022 3:28 am
xinhaojie wrote: ↑Tue Aug 30, 2022 8:20 am
开发环境:ESP IDF 4.4.2 开发板:ESP32-S3-DevKitC-1 v1.1 PC:win11 在编译测试gatt_security_server这个工程的时候,使用BLE4.2.在测试手机连接后,重启ESP32S3,板子上的绑定信息就丢失了。还有我添加到白名单的地址也会随着重启消失。白名单我可以通过NVS记录,但是绑定的密钥信息我无法存储。我查阅了BLE的接口文档,没有看到保存绑定信息的接口。请教一下我应该怎么搞。
我这边使用 esp32s3 开发板测试ESP IDF 4.4.2下的 gatt_security_server 示例没有遇到这个问题; 重启esp32s3, 手机再次与之相连,绑定地址是之前配对手机的,绑定设备数目也是 1 个
企业微信截图_20220831111453.png
企业微信截图_20220831111721.png
在 gatt_security_server 中这个 remove_all_bonded_devices()
https://github.com/espressif/esp-idf/bl ... emo.c#L581 API 是可以删除绑定设备信息的,但是这部分代码是默认屏蔽的