sidorares / dbus-native

D-bus protocol client and server for node.js written in native javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BlueZ GATT server read characteristic does not return an error org.bluez.Error.InProgress

JohnRucker opened this issue · comments

I have a Bluetooth LE server based on dbus-native and BlueZ 5.50. When my client (iPhone in this case) reads a characteristic from my LE server (Raspberry Pi zero W) I need to return a dBus error of "org.bluez.Error.InProgress". I'm returning the error according to your example here.

Everything appears to work just fine but the error is not sent by my server over dBus. dbus-monitor --system shows the method call return is an empty array (no data).

capture

Here is my interface description and here is the class method that is called when the characteristic read is requested. I have it hard-coded to return an error to help with troubleshooting.

I'm sure I'm missing the correct syntax for returning a dBus error to a method call. Is your example correct? I noticed you have a sendError function. Do I need to somehow call that in response to the method call? If so I'm struggling with how to get assess to the "msg" object and return this function? Can you point me in the right direction? Thanks!!

PS your work is absolutely fantastic and I'm soo close to having a working BT Smart device all based on native-dbus!!

Figured it out! I have to throw the error and set thisError.dbusName = 'org.bluez.Error.InProgress';

Here is what the log looks like now:
capture
Here is the method that returns the above error:

    _readKey(options){
        console.log('_readKey method called.');
        console.log('node = ' + this.DataKey)
        console.log('UUID = ' + this.UUID)
        if (options){
            console.log('options follow:');
            if(Array.isArray(options)){
                options.forEach(function(val, index){
                    var detailsObj = val[1][0][0]
                    console.log('\t' + val[0] + ' : ' + val[1][1] + ', of type -> ' + detailsObj.type + ' <-.');
                })
            } else {
                console.log(options);
            }
        }
        //Do something to generate return data and place it in arryBuffer as an arry of bytes
        //var arryBuffer = Buffer.from([0x62, 0x01, 0x02, 0x03]);
        //console.log('Return buffer ->'+ arryBuffer +'<-');
        //this.Value = arryBuffer;


        var thisError = new Error('please wait...');
        thisError.dbusName = 'org.bluez.Error.InProgress';
        console.log(thisError)

        throw thisError;
        //return thisError;
    };

So I think your example should be changed from:

        // Return a DBus error to indicate a problem (shows how to send DBus errors)
        return new Error(
          'Incorrect number of elements supplied (0 < n < 256)!'
);

To:

        // Return a DBus error to indicate a problem (shows how to send DBus errors)
        throw new Error(
          'Incorrect number of elements supplied (0 < n < 256)!'
);