Search code examples
bluetooth-lowenergytizentizen-native-app

Tizen enable notifications for characteristic


Hi I'm trying to develop an app for the Gear S3 watch it's running Tizen 4.0.0.4 Shortly stated the problem is like that I don't know how to enable characteristic's notifications. When I try the usual approach, i.e. writing x01 x00 to 0x2902 descriptor I get -1 error and in the logs I get:

bt-gatt-client.c: __bluetooth_get_att_error_code(901) > Error : GDBus.Error:org.bluez.Error.NotPermitted: Write not permitted [/dev_4C_65_A8_DC_A1_F7/service002d/char002e/desc0030]

I have tried to look a bit in the blueZ to know what's wrong, but I just started.

The svc, char and desc look like that (They're custom chars from Xiaomi's Temp&Hum sensor):

SRVC:(1/7) uuid: [0000fe95-0000-1000-8000-00805f9b34fb]
CHAR:   (1/6) uuid: [00000001-0000-1000-8000-00805f9b34fb]
DESC:       (1/1) uuid: [00002902-0000-1000-8000-00805f9b34fb]

(the permission on the CHAR is write notify) I do the usual stuff (after connecting and so on, I didn't bond because it seems it is not necessary for the device, well unless Tizen's stack does some kind of magic with blueZ under the hood with bonding...). So I do more or less this: in connect callback, after creating a client I call the trio

bt_gatt_client_get_service()
bt_gatt_service_get_characteristic()
bt_gatt_characteristic_get_descriptor()

and then I set the value of 0x01 0x00 as an char array with

bt_gatt_set_value()

and then finally call

bt_gatt_client_write_value()

in bt_gatt_client_write_value() callback I get write fail with err code -1 and in the log the above mentioned error from bluez

I must admit I'm stuck... Is there any other way in Tizen to enable characteristic's notifications other than writing x01 x00 to CCCD descriptor? Perhaps I'm missing some precondition or something like that. Honestly I just followed the tutorial on the Sammys page and I thought it should work ... just like that... Just to mention using rpi0 and python it's working... thanks. UPDATE: I forgot to mention that, basically, I can write to other characteristics I haven't tried to set their notifications, but in general the only problem is the CCCD descriptor right now. The privileges are set.


Solution

  • Can you use "bt_gatt_client_set_characteristic_value_changed_cb" function? Even if you don't write value 0x01 in the descriptor, you can monitor the changed value for the charicteristics.

    https://developer.tizen.org/development/api-references/native-application?redirect=https://developer.tizen.org/dev-guide/5.0.0/org.tizen.native.mobile.apireference/group__CAPI__NETWORK__BLUETOOTH__GATT__CLIENT__MODULE.html#ga68dc116f5d5e32c505941072fb515871

    The example is

    bt_gatt_client_h client = NULL; // grobal variable (client handle)
    func
    {
        char *svc_uuid = NULL;
        char *chr_uuid = NULL;
        bt_gatt_h svc = NULL;
        bt_gatt_h chr = NULL;
    
        svc_uuid = g_test_param.params[0];
        chr_uuid = g_test_param.params[1];
    
        ret = bt_gatt_client_get_service(client, svc_uuid, &svc);
        if (ret != BT_ERROR_NONE) {
            TC_PRT("bt_gatt_client_get_service is failed : %d", ret);
            __bt_free_test_param(&g_test_param);
            break;
        }
    
        ret = bt_gatt_service_get_characteristic(svc,
                chr_uuid, &chr);
        if (ret != BT_ERROR_NONE) {
            TC_PRT("bt_gatt_service_get_characteristic is failed : %d", ret);
            __bt_free_test_param(&g_test_param);
            break;
        }
    
        ret = bt_gatt_client_set_characteristic_value_changed_cb(chr,
                        __bt_gatt_client_value_changed_cb, NULL);
        if (ret != BT_ERROR_NONE)
            TC_PRT("bt_gatt_client_set_characteristic_value_changed_cb is failed : %d", ret);
    }