Timeular / noble-winrt

Noble Windows 10 bindings using the official C++/WinRT API
MIT License
20 stars 26 forks source link

Issues subscribing and receiving data #17

Open chipimix opened 4 years ago

chipimix commented 4 years ago

Hi! It seems to me that BLE support on windows is somewhat limited and UWP-centric. This module allows development of electron apps. Thanks for all of your work!! :) Having said that, I'm having issues subscribing a service characteristic with the "notify" attribute: it doesn't seem to trigger the data event. Perhaps I'm doing something wrong:

uartCharacteristic.subscribe(function(error) {
     console.log('battery level notification on');
});
uartCharacteristic.on('data', function(data, isNotification){
    console.log(data);
});

Also, i read that

Writing/Reading to descriptor handles is not supported
Broadcast is not supported

Does this mean subscribing to a service characteristic with the "notify" attribute is not supported yet? Thanks again!

chipimix commented 4 years ago

I think I forgot a bolean parameter in the subscribe method; but now I encounter this error: image

geovie commented 4 years ago

@chipimix There is no need for a boolean parameter. You can check the example for a how to subscribe to a characteristic

chipimix commented 4 years ago

I thought it could be outdatted since the noble example features the boolean parameter. batteryLevelCharacteristic.subscribe(true, function(error) { console.log('battery level notification on'); }); Thanks for pointing the direction though. Still can't get on('data') events triggered by subscribe though, only with read() :(

geovie commented 4 years ago

Do you get any error in the subscribe callback?

chipimix commented 4 years ago

unfortunately no!

uartCharacteristic.subscribe(function(error) { console.log('notification on'); }); uartCharacteristic.on('data', function(data, isNotification){ console.log(data); });

results in: image

If I inspect the characteristic this is what I see: image

uartCharacteristic.read() does trigger the on('data') event though ...

geovie commented 4 years ago

Can you log the error: uartCharacteristic.subscribe(function(error) { console.log('subscribe:', error); });

chipimix commented 4 years ago

sure! but the issue is don't get any error in the subscribe callback

uartCharacteristic.subscribe(function(error) {
    console.log(error)
    console.log('notification on');
});

results in: image

chipimix commented 4 years ago

I think I found the issue! From what I understand, when we subscribe a characteristic with the notify attribute, we're basically writing something like [0x01,0x00] to the Client Characteristic Configuration Descriptor. In the case of my nRF52 board and Nordic UART Service Tx Characteristic, the CCCD UUID is 0x2902; however I think noble will try to write it to 0x2901. Is there some place where I can make this parameterizable or hardcode it? Thanks for all the help!