espruino / winnus

Windows 8.1 and above BLE NUS support for Node.js
3 stars 5 forks source link

Connect to nrf52 #8

Open chipimix opened 4 years ago

chipimix commented 4 years ago

Hi! I'm trying to use this module to connect to a nrf52 with NUS service. However when I run this code: `var winnus = require("winnus");

var device = winnus.getDevices()[0]; console.log(device) winnus.connect(device, function(data) { console.log("Got data "+JSON.stringify(data)); });` It fails on connect: image Am I doing something wrong? does this module work exclusively for puck.js devices? Thanks!

gfwilliams commented 4 years ago

Hi - I'm afraid I don't know exactly what the issue is. How are you creating the NUS service on the device? Using the Nordic ble_nus library?

There is nothing specific in there that requires a Puck.js or other Espruino device, so it should work just fine

chipimix commented 4 years ago

Thanks for the answer! Yes we're using ble_nus library, is there something in particular I should be doing?

gfwilliams commented 4 years ago

No - I'm extremely surprised then. It should 'just work' :(

chipimix commented 4 years ago

I think I know what the issue is but I'm not entirely sure how to solve it. 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 the specifications of NUS, the CCCD UUID is 0x2902; however I think winnus will try to write it to 0x2901. I think this is what's happening and considering the BluetoothGATTSetDescriptorValue error, it would make sense. Any thoughts on how I can make this parameterizable or hardcode it? Thanks!

gfwilliams commented 4 years ago

Ahh, interesting - thanks for spotting that!

Well, I assume it's this check? https://github.com/espruino/winnus/blob/master/cpp/winnus.cpp#L494

There must be a better way to handle it...