GATT CLIENT接收乱码

某某ESP32友
Posts: 25
Joined: Fri May 07, 2021 4:10 pm

Re: GATT CLIENT接收乱码

Postby 某某ESP32友 » Thu Jun 03, 2021 8:46 am

MTU默认值500没改,APP的:
微信图片_20210601160737.jpg
微信图片_20210601160737.jpg (126.47 KiB) Viewed 6954 times
ESP32的:
I (3767) GATTC_DEMO: Write: atz
I (3787) GATTC_DEMO: update connection params status = 0, min_int = 8, max_int = 16,conn_int = 16,latency = 0, timeout = 300
I (3857) GATTC_DEMO: Receive:
I (3857) GATTC_DEMO: 61 74 7a 20 0d fc
I (4657) GATTC_DEMO: Receive:
I (4657) GATTC_DEMO: 0d 0d 45 4c 4d 33 32 37 20 76 31 2e 35 0d 0d 3e

I (6767) GATTC_DEMO: Write: at@1
I (6797) GATTC_DEMO: Receive:
I (6807) GATTC_DEMO: 61 74 40 31 20 0d 4f 42 44 49 49 20 74 6f 20 52
I (6807) GATTC_DEMO: 53 32 33 32
I (6807) GATTC_DEMO: Receive:
I (6807) GATTC_DEMO: 20 49 6e 74 65 72 70 72 65 74 65 72 0d 0d 3e 74
I (6817) GATTC_DEMO: Receive:
I (6817) GATTC_DEMO: 74 70 30 20 0d 3f 0d 0d 3e 30

I (9767) GATTC_DEMO: Write: ati
I (9797) GATTC_DEMO: Receive:
I (9807) GATTC_DEMO: 61 74 69 20 0d 45 4c 4d 33 32 37 20 76 31 2e 35
I (9807) GATTC_DEMO: 0d 0d 3e 30
I (9807) GATTC_DEMO: Receive:
I (9807) GATTC_DEMO: 31
I (9817) GATTC_DEMO: Receive:
I (9817) GATTC_DEMO: 30 30 20 0d 34 31 20 30 30 20 46 46 20 46 46 20
I (9827) GATTC_DEMO: 46 46 20 46
I (9827) GATTC_DEMO: Receive:
I (9827) GATTC_DEMO: 46 20 0d
I (9917) GATTC_DEMO: Receive:
I (9917) GATTC_DEMO: 0d 3e

I (12767) GATTC_DEMO: Write: attp0
I (12797) GATTC_DEMO: Receive:
I (12797) GATTC_DEMO: 61 74 74 70 30 20 0d 4f 4b 0d 0d 3e
I (12817) GATTC_DEMO: Receive:
I (12817) GATTC_DEMO: 30 35 20 0d 53 45 41 52 43 48 49 4e 47 2e 2e 2e
I (12817) GATTC_DEMO: 0d
I (13357) GATTC_DEMO: Receive:
I (13357) GATTC_DEMO: 34 31 20 30 30 20 46 46 20 46 46 20 46 46 20 46
I (13357) GATTC_DEMO: 46 20 0d
I (13457) GATTC_DEMO: Receive:
I (13457) GATTC_DEMO: 0d 3e

I (15767) GATTC_DEMO: Write: 0100
I (15797) GATTC_DEMO: Receive:
I (15807) GATTC_DEMO: 30 31 30 30 20 0d 34 31 20 30 30 20 46 46 20 46
I (15807) GATTC_DEMO: 46 20 46 46
I (15807) GATTC_DEMO: Receive:
I (15807) GATTC_DEMO: 20 46 46 20 0d
I (15897) GATTC_DEMO: Receive:
I (15897) GATTC_DEMO: 0d 3e

I (18767) GATTC_DEMO: Write: 0105
I (18797) GATTC_DEMO: Receive:
I (18797) GATTC_DEMO: 30 31 30 35 20 0d 34 31 20 30 35 20 36 43 20 0d
I (18897) GATTC_DEMO: Receive:
I (18897) GATTC_DEMO: 0d 3e

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

Re: GATT CLIENT接收乱码

Postby ESP_XuLZ » Thu Jun 03, 2021 9:39 am

看log中最大收包大小是默认值20,超过20会进行分包接收。 你应当是使用的esp_ble_gatt_set_local_mtu(500)设置的mtu吧?这个是表示你本地能接收单个包最大大小的能力, 你可以使用 esp_ble_gattc_send_mtu_req() 来使之生效,这个函数你可以搜下IDF 下 gattc_multi_connect 是怎样使用的

某某ESP32友
Posts: 25
Joined: Fri May 07, 2021 4:10 pm

Re: GATT CLIENT接收乱码

Postby 某某ESP32友 » Thu Jun 03, 2021 1:27 pm

大佬,例程里有esp_ble_gattc_send_mtu_req啊,但没有使MTU设置生效
case ESP_GATTC_CONNECT_EVT:
{
ESP_LOGI(GATTC_TAG, "ESP_GATTC_CONNECT_EVT conn_id %d, if %d", p_data->connect.conn_id, gattc_if);
gl_profile_tab[PROFILE_A_APP_ID].conn_id = p_data->connect.conn_id;
memcpy(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, p_data->connect.remote_bda, sizeof(esp_bd_addr_t));

gl_profile_tab[PROFILE_B_APP_ID].conn_id = p_data->connect.conn_id;
memcpy(gl_profile_tab[PROFILE_B_APP_ID].remote_bda, p_data->connect.remote_bda, sizeof(esp_bd_addr_t));

ESP_LOGI(GATTC_TAG, "REMOTE BDA:");
esp_log_buffer_hex(GATTC_TAG, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, sizeof(esp_bd_addr_t));
esp_err_t mtu_ret = esp_ble_gattc_send_mtu_req(gattc_if, p_data->connect.conn_id);
if (mtu_ret)
{
ESP_LOGE(GATTC_TAG, "config MTU error, error code = %x", mtu_ret);
}

break;
}

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

Re: GATT CLIENT接收乱码

Postby ESP_XuLZ » Fri Jun 04, 2021 2:48 am

1、如附件中图1、图2所示,gatt_server中notify 数据为25个字节,gatt_client 设置MTU为23,收到的数据为20个字节,gatt_client 设置MTU为50, 收到的数据为25个字节。esp_ble_gattc_send_mtu_req() 后会触发ESP_GATTC_CFG_MTU_EVT事件,你看下打印的status、mtu和conn_id 是多少
2、你们server端notify的行为及client 端代码我们不清楚,你可以使用gatt_client及gatt_server来验证结果
BBS12.png
BBS12.png (96.59 KiB) Viewed 6882 times
BBS22.png
BBS22.png (111.06 KiB) Viewed 6882 times

某某ESP32友
Posts: 25
Joined: Fri May 07, 2021 4:10 pm

Re: GATT CLIENT接收乱码

Postby 某某ESP32友 » Fri Jun 04, 2021 7:07 am

大佬,目前最棘手的问题就是MTU设置无效,无论设置多少,都是23,把默认值改了也是23。
源码完全是例程里的:
设置MTU大小:
QQ图片20210604145539.png
QQ图片20210604145539.png (44.35 KiB) Viewed 6860 times
设置生效:
QQ图片20210604145630.png
QQ图片20210604145630.png (82.86 KiB) Viewed 6860 times
运行结果:
QQ图片20210604145506.png
QQ图片20210604145506.png (64.96 KiB) Viewed 6860 times

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

Re: GATT CLIENT接收乱码

Postby ESP_XuLZ » Fri Jun 04, 2021 7:47 am

1、你应当是使用gatt_client 去连接你们的server 吧?这个是一个协商的过程,如果你们server设置23,返回值就是23,取两边本地设置的最小值
2、请在gatt_client和gatt_server上进行修改验证 mtu 问题,如果仍然有问题,请在附件中上传你所修改的代码及提供下所用IDF 分支和commit_id的信息

Who is online

Users browsing this forum: No registered users and 206 guests