2

I'm using java TinyB to connect to a TimeFlip device with Bluetooth LE.

When trying to write to the Descriptor of the Facet Characteristic to recieve notifications I always get the error:

Exception in thread "main" tinyb.BluetoothException: GDBus.Error:org.bluez.Error.NotPermitted: Write not permitted

But when I write to the same Descriptor using gatttool it works and i get the notifications.

        BluetoothGattService timeFlipService = device.find("f1196f50-71a4-11e6-bdf4-0800200c9a66", Duration.ofSeconds(5));
        BluetoothGattCharacteristic facets = timeFlipService.find("f1196f52-71a4-11e6-bdf4-0800200c9a66", Duration.ofSeconds(5));
        BluetoothGattDescriptor facetsConfig = facets.find("00002902-0000-1000-8000-00805f9b34fb", Duration.ofSeconds(5));  // like this ==> always null, custom method works???

        if(!login(timeFlipService)) {log.error("login to TimeFlip failed");}

        try{
            byte[] enableNotifications = {0x01, 0x00};
            facetsConfig.writeValue(enableNotifications);           //when facesConfig assigned with custom method throws write not permitted error
            facets.enableValueNotifications(new FacetNotification());
        }
        catch(NullPointerException e){
            log.error("NullPointerException in " + (facets == null ? "facet characteristic" : "facet descriptor"));
        }
        catch(BluetoothException b){
            log.error(b.getMessage());
        }
    }

The mentioned "custom method" just gets all Descriptor from a characteristic and returns the one matching a given uuid, as the find() method times out every time.

1 Answers1

4

In Bluez you are supposed to use StartNotify to turn on notifications or indications. Bluez will do the writing of the descriptor for you but if you try to do it yourself it indeed gives an error.

  • So you mean to only use enableValueNotifications()? Because doing so always results in a SIGSEV fatal error, that's why I started trying to write to the descriptor. – Moritz Perschke Apr 07 '21 at 16:45
  • Yes, it is a method of the characteristic. Looks like it is called enableValueNotifications() in Tinyb – Martijn van Welie Apr 07 '21 at 19:24
  • Yeah I found that in the bluez docs after your comment, enableValueNotifications() is definietly the right way. Doing it the correct way still produces SIGSEV for me, if you know why this could be that would great, otherwise I'll just use polling. – Moritz Perschke Apr 07 '21 at 20:45