Languages

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

I am currently doing a project that uses Samsung Galaxy Gear S3 as Bluetooth Low Energy server to build custom services. The problem is after I built the characteristic and descriptor, added them to another and to the service, registered the service to the server, and started the server, the BlueScanner app on my iPhone just shows that my characteristic and descriptor do not have value, but have uuid. Here is my code:

 

 

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");
}
}

 

Thanks in advance!

Responses

1 Replies
K Johnson

I guess you've find the solution and posted an answer in this link. Hope it'll help other developers to find solution facing similar problem.