ESP32C3 主机获取不到广播数据(已解决)

FengXinan
Posts: 14
Joined: Tue Mar 01, 2022 2:21 am

ESP32C3 主机获取不到广播数据(已解决)

Postby FengXinan » Thu Sep 15, 2022 7:37 am

adv_data = esp_ble_resolve_adv_data(scan_result->scan_rst.ble_adv,
adv_type, &adv_data_len);

主机扫描广播时可以获取ble_adv, 但打印ble_adv 时发现大多数时候没有除名称外的广播数据.
问题特征:只有第一次扫描可以扫到广播数据, 之后无法获取
解决方法:每次开始扫描前设置一遍广播参数
Last edited by FengXinan on Sat Sep 17, 2022 2:41 am, edited 4 times in total.

ESP_XuLZ
Posts: 173
Joined: Fri Mar 26, 2021 6:04 am

Re: ESP32C3 主机获取不到广播数据

Postby ESP_XuLZ » Thu Sep 15, 2022 9:40 am

scan_result->scan_rst.ble_adv 是由两个 包组成的,adv data 和 scan_rsp data , 但这两个包并不一定同时上来,所以在scan_result->scan_rst.ble_adv buffer 中会有三种情况:
1、adv data 和 scan_rsp data 同时上来(adv data 填充 buffer 前面)
2、仅 adv data 上来
3、仅 scan_rsp data 上来

所以你说的获取不到广播数据情况大致有以下:

1、广播者在 adv data 和 scan_rsp data 没有定义 除广播名称外的其他数据
2、包含其他数据的 packet 在本次扫描中没有捕获到(比如定义的广播数据在scan_rsp data 中,但是此次只扫描到 adv data),但后几次次扫描中总能获取到另外一个 packet 中的广播数据的

FengXinan
Posts: 14
Joined: Tue Mar 01, 2022 2:21 am

Re: ESP32C3 主机获取不到广播数据

Postby FengXinan » Fri Sep 16, 2022 4:58 am

ESP_XuLZ wrote:
Thu Sep 15, 2022 9:40 am
scan_result->scan_rst.ble_adv 是由两个 包组成的,adv data 和 scan_rsp data , 但这两个包并不一定同时上来,所以在scan_result->scan_rst.ble_adv buffer 中会有三种情况:
1、adv data 和 scan_rsp data 同时上来(adv data 填充 buffer 前面)
2、仅 adv data 上来
3、仅 scan_rsp data 上来

所以你说的获取不到广播数据情况大致有以下:

1、广播者在 adv data 和 scan_rsp data 没有定义 除广播名称外的其他数据
2、包含其他数据的 packet 在本次扫描中没有捕获到(比如定义的广播数据在scan_rsp data 中,但是此次只扫描到 adv data),但后几次次扫描中总能获取到另外一个 packet 中的广播数据的
我把scan_result->scan_rst.ble_adv 的62字节数据打印出来了, 绝大多数都 只有名称 xx09xxxxxx 的消息, 其他所有的数据都是0, 我尝试过增大扫描窗口, 并没有作用

ESP_XuLZ
Posts: 173
Joined: Fri Mar 26, 2021 6:04 am

Re: ESP32C3 主机获取不到广播数据

Postby ESP_XuLZ » Fri Sep 16, 2022 5:08 am

可能是你周围广播设置只有 设备名称的ADV 结构数据, 你可以使用一个能自定义设置广播的设备(比如 手机 APP, ESP32设备)做下测试, 将其他广播数据和 设备名称广播数据放在一个 packet 包中(31 字节的 adv data 或者 scan_rsp data), 来看下是否会只扫描到 设备名称广播数据
一般来说,并不会出现你说的情况,如果将 其他广播数据和 设备名称广播数据 放在不同的packet 包中(31 字节的 adv data 或者 scan_rsp data)中,可能会出现不同时上来的情况

FengXinan
Posts: 14
Joined: Tue Mar 01, 2022 2:21 am

Re: ESP32C3 主机获取不到广播数据

Postby FengXinan » Fri Sep 16, 2022 5:16 am

ESP_XuLZ wrote:
Fri Sep 16, 2022 5:08 am
可能是你周围广播设置只有 设备名称的ADV 结构数据, 你可以使用一个能自定义设置广播的设备(比如 手机 APP, ESP32设备)做下测试, 将其他广播数据和 设备名称广播数据放在一个 packet 包中(31 字节的 adv data 或者 scan_rsp data), 来看下是否会只扫描到 设备名称广播数据
一般来说,并不会出现你说的情况,如果将 其他广播数据和 设备名称广播数据 放在不同的packet 包中(31 字节的 adv data 或者 scan_rsp data)中,可能会出现不同时上来的情况
I (1619) name: PN771M Pen 0 12
I (1619) adv all: 0b 09 50 4e 37 37 31 4d 20 50 65 6e 00 00 00 00
I (1619) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (1629) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (1629) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (3179) name: REM1-10010027 22 15
I (3179) adv: 50 46 31 56 31 2e 31
I (3179) adv all: 02 01 06 09 03 58 69 ff f1 09 02 70 de 08 ff 50
I (3179) adv all: 46 31 56 31 2e 31 0e 09 52 45 4d 31 2d 31 30 30
I (3189) adv all: 31 30 30 32 37 00 00 00 00 00 00 00 00 00 00 00
I (3189) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (4609) name: box-mybox 0 11
I (4609) adv all: 0a 09 62 6f 78 2d 6d 79 62 6f 78 00 00 00 00 00
I (4619) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (4619) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (4629) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (4969) name: DL_0047 0 9
I (4969) adv all: 08 09 44 4c 5f 30 30 34 37 00 00 00 00 00 00 00
I (4969) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (4969) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (4979) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (7489) name: Forerunner 235 0 24
I (7489) adv all: 10 09 46 6f 72 65 72 75 6e 6e 65 72 20 32 33 35
I (7489) adv all: 00 06 16 10 3e 00 12 00 00 00 00 00 00 00 00 00
I (7489) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (7499) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (7949) name: box-7ea 0 9
I (7949) adv all: 08 09 62 6f 78 2d 37 65 61 00 00 00 00 00 00 00
I (7949) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (7959) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (7959) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (8609) name: box-mybox 0 11
I (8609) adv all: 0a 09 62 6f 78 2d 6d 79 62 6f 78 00 00 00 00 00
I (8609) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (8619) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (8629) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (9389) name: DL_0042 0 9
I (9389) adv all: 08 09 44 4c 5f 30 30 34 32 00 00 00 00 00 00 00
I (9389) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (9399) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (9399) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (10209) name: REM1-10010027 0 15
I (10209) adv all: 0e 09 52 45 4d 31 2d 31 30 30 31 30 30 32 37 00
I (10209) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (10209) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (10219) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (11969) name: DL_0047 0 9
I (11969) adv all: 08 09 44 4c 5f 30 30 34 37 00 00 00 00 00 00 00
I (11969) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (11969) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (11979) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (14509) name: Forerunner 235 0 24
I (14509) adv all: 10 09 46 6f 72 65 72 75 6e 6e 65 72 20 32 33 35
I (14509) adv all: 00 06 16 10 3e 00 12 00 00 00 00 00 00 00 00 00
I (14519) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (14519) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (15609) name: box-mybox 0 11
I (15609) adv all: 0a 09 62 6f 78 2d 6d 79 62 6f 78 00 00 00 00 00
I (15609) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (15619) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (15629) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (18949) name: box-7ea 0 9
I (18949) adv all: 08 09 62 6f 78 2d 37 65 61 00 00 00 00 00 00 00
I (18949) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (18959) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (18959) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (21459) name: Forerunner 235 0 24
I (21459) adv all: 10 09 46 6f 72 65 72 75 6e 6e 65 72 20 32 33 35
I (21459) adv all: 00 06 16 10 3e 00 12 00 00 00 00 00 00 00 00 00
I (21469) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (21479) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (22259) name: REM1-10010027 0 15
I (22259) adv all: 0e 09 52 45 4d 31 2d 31 30 30 31 30 30 32 37 00
I (22259) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (22269) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
I (22269) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00

扫描的部分log ,REM1-10010027 这个是我自己的设备, 在从机端0xFF 广播字段加了一段数据50 46 31 56 31 2e 31, 第一次扫描的时候大概率可以扫到这个字段, 随后基本就再也扫不到了.
name: REM1-10010027 0 15 第二个数字是adv_data_len 第三个数据是scan_rsp_len

ESP_XuLZ
Posts: 173
Joined: Fri Mar 26, 2021 6:04 am

Re: ESP32C3 主机获取不到广播数据

Postby ESP_XuLZ » Fri Sep 16, 2022 6:23 am

I (3179) name: REM1-10010027 22 15
I (3179) adv: 50 46 31 56 31 2e 31
I (3179) adv all: 02 01 06 09 03 58 69 ff f1 09 02 70 de 08 ff 50
I (3179) adv all: 46 31 56 31 2e 31 0e 09 52 45 4d 31 2d 31 30 30
I (3189) adv all: 31 30 30 32 37 00 00 00 00 00 00 00 00 00 00 00
I (3189) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
如上你的日志中 自定义的广播数据 50 46 31 56 31 2e 31 并没有显示在你所打印的 ble_adv 中,这点我不理解
如下是我做的测试:
gatt_server_service_table 中的广播修改如下:
2022-09-16_14-12.png
2022-09-16_14-12.png (58.14 KiB) Viewed 6300 times
使用 gatt_client 进行扫描, 将 CONFIG_EXAMPLE_DUMP_ADV_DATA_AND_SCAN_RESP 设为 1 来打印 ble_adv 中的数据,日志如附件所示,每次都能扫描到 0xff 的adv 数据
2022-09-16_14-15.png
2022-09-16_14-15.png (37.29 KiB) Viewed 6300 times
建议你使用 gatt_client 原示例进行扫描, 将 CONFIG_EXAMPLE_DUMP_ADV_DATA_AND_SCAN_RESP 设为 1 提供下 txt 格式日志
Attachments
gatt_client_scan_data.txt
(39.06 KiB) Downloaded 356 times

FengXinan
Posts: 14
Joined: Tue Mar 01, 2022 2:21 am

Re: ESP32C3 主机获取不到广播数据

Postby FengXinan » Fri Sep 16, 2022 7:19 am

ESP_XuLZ wrote:
Fri Sep 16, 2022 6:23 am
I (3179) name: REM1-10010027 22 15
I (3179) adv: 50 46 31 56 31 2e 31
I (3179) adv all: 02 01 06 09 03 58 69 ff f1 09 02 70 de 08 ff 50
I (3179) adv all: 46 31 56 31 2e 31 0e 09 52 45 4d 31 2d 31 30 30
I (3189) adv all: 31 30 30 32 37 00 00 00 00 00 00 00 00 00 00 00
I (3189) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
如上你的日志中 自定义的广播数据 50 46 31 56 31 2e 31 并没有显示在你所打印的 ble_adv 中,这点我不理解
如下是我做的测试:
gatt_server_service_table 中的广播修改如下:
2022-09-16_14-12.png
使用 gatt_client 进行扫描, 将 CONFIG_EXAMPLE_DUMP_ADV_DATA_AND_SCAN_RESP 设为 1 来打印 ble_adv 中的数据,日志如附件所示,每次都能扫描到 0xff 的adv 数据
2022-09-16_14-15.png

建议你使用 gatt_client 原示例进行扫描, 将 CONFIG_EXAMPLE_DUMP_ADV_DATA_AND_SCAN_RESP 设为 1 提供下 txt 格式日志
好的, 刚才试了, 使用示例程序是可以扫到信息的, 我再排查一下代码其他的问题

FengXinan
Posts: 14
Joined: Tue Mar 01, 2022 2:21 am

Re: ESP32C3 主机获取不到广播数据

Postby FengXinan » Fri Sep 16, 2022 7:43 am

ESP_XuLZ wrote:
Fri Sep 16, 2022 6:23 am
I (3179) name: REM1-10010027 22 15
I (3179) adv: 50 46 31 56 31 2e 31
I (3179) adv all: 02 01 06 09 03 58 69 ff f1 09 02 70 de 08 ff 50
I (3179) adv all: 46 31 56 31 2e 31 0e 09 52 45 4d 31 2d 31 30 30
I (3189) adv all: 31 30 30 32 37 00 00 00 00 00 00 00 00 00 00 00
I (3189) adv all: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
如上你的日志中 自定义的广播数据 50 46 31 56 31 2e 31 并没有显示在你所打印的 ble_adv 中,这点我不理解
如下是我做的测试:
gatt_server_service_table 中的广播修改如下:
2022-09-16_14-12.png
使用 gatt_client 进行扫描, 将 CONFIG_EXAMPLE_DUMP_ADV_DATA_AND_SCAN_RESP 设为 1 来打印 ble_adv 中的数据,日志如附件所示,每次都能扫描到 0xff 的adv 数据
2022-09-16_14-15.png

建议你使用 gatt_client 原示例进行扫描, 将 CONFIG_EXAMPLE_DUMP_ADV_DATA_AND_SCAN_RESP 设为 1 提供下 txt 格式日志
  1.        }
  2.             }
  3.             break;
  4.         case ESP_GAP_SEARCH_INQ_CMPL_EVT:
  5.             esp_ble_gap_start_scanning(5);
  6.             break;
  7.         default:
增加了这一段代码
使用 gatt_client 原示例进行扫描 , 第一次扫描可以扫到更多的广播数据, 第二次扫描就无法扫到广播数据了, 这个和我之前的表现是类似的.
Attachments
esp32c3_log.txt
(38.12 KiB) Downloaded 344 times

FengXinan
Posts: 14
Joined: Tue Mar 01, 2022 2:21 am

Re: ESP32C3 主机获取不到广播数据

Postby FengXinan » Sat Sep 17, 2022 2:39 am

基本已解决. 在第二次扫描的时候重新设置一遍扫描参数就可以扫到广播数据了,
  1. esp_ble_gap_set_scan_params(&ble_scan_params);
  2.             esp_ble_gap_start_scanning(5);

Who is online

Users browsing this forum: No registered users and 68 guests