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

Bluetooth LE Gatt server characteristic value is always NULL on Tizen 3.0.0.2

我目前正在做一个项目,使用三星 Galaxy Gear S3 作为低功耗蓝牙服务器来构建客户服务。问题是在我构建特征和描述符、将它们添加到另一个和服务、将服务注册到服务器并启动服务器之后,iPhone 上的 BlueScanner 应用程序只显示我的特征和描述符没有价值,但有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" 函数。我猜客户端每次都读取该值并且由于未定义该函数,它不会 return 任何东西,所以服务器的值被设置为 NULL.