Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About how to connect a Bluetooth device with a 16-bit UUID #9

Open
KevinLi-167 opened this issue May 16, 2023 · 1 comment
Open

About how to connect a Bluetooth device with a 16-bit UUID #9

KevinLi-167 opened this issue May 16, 2023 · 1 comment

Comments

@KevinLi-167
Copy link

Hello, I have encountered a problem when using the Bluetooth master project of SDK. Hopefully you can give me answers to my mistakes or provide me with the correct code.

(https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/blob/main/applications/bluetooth/ble_master/ble_master/ble_central_api.c)

A brief description of my problems,

  1. The core problem is that it cannot connect to the Bluetooth module DX-BT04-E whose uuid is TYPE_16. The code modification fails
  2. There is no example when the uuid is TYPE_16 and 32, the former is slightly different from the given TYPE_128, hope to make a tutorial or solution
  3. Do not understand the implementation of uuid conversion

It's about the file "ble_central_api.c" and the *bt_uuid_6/32/128 of"uuid.h"
MY_UUID1_USER_TXD is char[16] for 128byte with the uint8_t uuid128[16]; which used at func
ble_reverse_byte(); and memcmp().
My bluetooth device is DX-BT04-E"module. It's UUID identified as BT_UUID_TYPE_16.
So I follow the code format of char MY_UUID1_USER_TXD[16]

const uint16_t MY_UUID_2_USER_TXD = 0x42001;
const char MY_UUID_2_USER_TXD[4] = { 0x42, 0x01, 0x9a, 0xac }; //42019AAC
const char MY_UUID_2_USER_RXD[2] = { 0x66, 0x16 };

uuid16 = (uint16_t) (((struct bt_uuid_16*) (attr->uuid))->val);

debug: sprintf(buf1, "attr->uuid = uuid16_ori = %X\r\n", attr->uuid);bleuart_printf(buf1); output : 42019B40
debug: sprintf(buf1, "attr->uuid = uuid16_ori = %X\r\n", uuid16);bleuart_printf(buf1); output : 2800

Found in this val cannot be converted to uuid16 properly. Reading the source code for data type or casting type is also inavailable to find a solution.
I was wondering if the recognition is TYPE16, why is the value before the conversion 4-bit hexadecimal instead of 2-bit hexadecimal.
In the file gatt.h, const struct bt_uuid *uuid; how does the bt_uuid u8_t type convert to the bt_uuid_128

struct bt_uuid {
	u8_t type;
};

struct bt_uuid_16 {
	struct bt_uuid uuid;
	u16_t val;//
};


struct bt_uuid_128 {
	struct bt_uuid uuid;
	u8_t val[16];
};

The amount of data bytes is all different.It's not work when it come to the uuid16 and val use assign.
Finally I change if (memcmp((char*) uuid16, MY_UUID_2_USER_TXD, 2) == 0) to if (uuid16 == MY_UUID_2_USER_TXD) because its about u16_t and char,not the char[] and uint8.

What should I do to solve if (attr->uuid->type == BT_UUID_TYPE_16)?
I hope I will not disturb you. This is the first time I have raised an issue. Look forward to your reply. Thank you.

@KevinLi-167
Copy link
Author

有人尝试过连接其他蓝牙模块通讯么,用代码形式而不是原本固件AT指令

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant