gpt4 book ai didi

bluetooth-lowenergy - Tizen 3.0.0.2 上的蓝牙 LE Gatt 服务器特征值始终为 NULL

转载 作者:行者123 更新时间:2023-12-05 06:34:08 26 4
gpt4 key购买 nike

我目前正在做一个项目,使用 Samsung Galaxy Gear S3 作为低功耗蓝牙服务器来构建客户服务。问题是在我构建特征和描述符、将它们添加到另一个和服务、将服务注册到服务器并启动服务器之后,我 iPhone 上的 BlueScanner 应用程序只显示我的特征和描述符没有值(value),但是有uuid。这是我的代码:

const char *service_uuid = "ADE3D529-C784-4F63-A987-EB69F70EE816";
bt_gatt_service_type_e type = BT_GATT_SERVICE_TYPE_PRIMARY;
//server handle
static bt_gatt_server_h gattServer = NULL;

//service handle
static bt_gatt_h gattSvc = NULL;

//Characteristic handle
bt_gatt_h gattChara = NULL;
const char *charaUuid = "AD7B334F-4637-4B86-90B6-9D787F03D218";
//const char *charaValue = "myCharacteristic";

//descriptor handle
static bt_gatt_h gattDescriptor = NULL;
const char *DescUuid = "0x1002";
const char *DescValue = "50";

void createService() {
dlog_print(DLOG_INFO, LOG_TAG, "Create Service");
int ret = bt_gatt_server_initialize();
if (ret != BT_ERROR_NONE) {
char* err;
err = get_error_message(ret);
dlog_print(DLOG_ERROR, LOG_TAG, "Init GATT server failed. err = %s",
err);
}

if (!gattServer) {
// gattServer not exist, create server
ret = bt_gatt_server_create(&gattServer);
if (ret != BT_ERROR_NONE) {
char* err;
err = get_error_message(ret);
dlog_print(DLOG_ERROR, LOG_TAG,
"Create GATT server failed. err = %s", err);
} else {
dlog_print(DLOG_INFO, LOG_TAG, "Create GATT server Succeed");
}
}

ret = bt_gatt_service_create(service_uuid, type, &gattSvc);
if (ret != BT_ERROR_NONE) {
char* err;
err = get_error_message(ret);
dlog_print(DLOG_ERROR, LOG_TAG, "Create GATT service failed. err = %s",
err);
} else {
dlog_print(DLOG_INFO, LOG_TAG, "Create GATT service Succeed");
}

ret = bt_gatt_characteristic_create(charaUuid,
BT_GATT_PERMISSION_READ | BT_GATT_PERMISSION_WRITE,
BT_GATT_PROPERTY_INDICATE | BT_GATT_PROPERTY_READ, charaValue,
LE_INITIAL_BUF_SIZE, &gattChara);
if (ret != BT_ERROR_NONE) {
char* err;
err = get_error_message(ret);
dlog_print(DLOG_ERROR, LOG_TAG,
"create characteristic failed. err = %s", err);
} else {
dlog_print(DLOG_INFO, LOG_TAG, "create characteristic Succeed");
}

ret = bt_gatt_server_set_read_value_requested_cb(gattChara,
__bt_gatt_server_read_value_requested_cb, NULL);
if (ret != BT_ERROR_NONE) {
char* err;
err = get_error_message(ret);
dlog_print(DLOG_ERROR, LOG_TAG, "create read request failed. err = %s",
err);
} else {
dlog_print(DLOG_INFO, LOG_TAG, "create read request Succeed");
}

ret = bt_gatt_descriptor_create(DescUuid,
BT_GATT_PERMISSION_READ | BT_GATT_PERMISSION_WRITE, DescValue,
LE_INITIAL_BUF_SIZE, &gattDescriptor);
if (ret != BT_ERROR_NONE) {
char* err;
err = get_error_message(ret);
dlog_print(DLOG_ERROR, LOG_TAG, "create descriptor failed. err = %s",
err);
} else {
dlog_print(DLOG_INFO, LOG_TAG, "create descriptor server Succeed");
}

ret = bt_gatt_characteristic_add_descriptor(gattChara, gattDescriptor);
if (ret != BT_ERROR_NONE) {
char* err;
err = get_error_message(ret);
dlog_print(DLOG_ERROR, LOG_TAG,
"add descriptor to characteristic failed. err = %s", err);
} else {
dlog_print(DLOG_INFO, LOG_TAG,
"add descriptor to characteristic Succeed");
}
ret = bt_gatt_service_add_characteristic(gattSvc, gattChara);
if (ret != BT_ERROR_NONE) {
char* err;
err = get_error_message(ret);
dlog_print(DLOG_ERROR, LOG_TAG,
"add characteristic to service failed. err = %s", err);
} else {
dlog_print(DLOG_INFO, LOG_TAG, "add characteristic to service Succeed");
}

ret = bt_gatt_server_register_service(gattServer, gattSvc);
if (ret != BT_ERROR_NONE) {
char* err;
err = get_error_message(ret);
dlog_print(DLOG_ERROR, LOG_TAG,
"register GATT service failed. err = %s", err);
} else {
dlog_print(DLOG_INFO, LOG_TAG, "register GATT service Succeed");
}

ret = bt_gatt_server_start();
if (ret != BT_ERROR_NONE) {
char* err;
err = get_error_message(ret);
dlog_print(DLOG_ERROR, LOG_TAG, "start GATT server failed. err = %s",
err);
} else {
dlog_print(DLOG_INFO, LOG_TAG, "start GATT server Succeed");
}
}

提前致谢!

最佳答案

我最终解决了这个问题。原来必须在“__bt_gatt_server_read_value_requested_cb”中调用“bt_gatt_server_send_response”函数。我猜客户端每次都读取该值,并且由于未定义该函数,它不会返回任何内容,所以服务器的值被设置为 NULL。

关于bluetooth-lowenergy - Tizen 3.0.0.2 上的蓝牙 LE Gatt 服务器特征值始终为 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50409765/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com