Tuesday 6 June 2017

Using noble (bluetooth low energy) with nw.js

I am struggling around to get noble working with nw.js aka node-webkit.

According to the wiki, 3rd-party node modules have to get compiled using nw-gyp. And noble uses the usb module - so I guess compiling the right way is important as well.

So what's the problem: If I use the noble module in a regular node environment like this

var noble = require('noble');

noble.on('stateChange', function (state) {
    log.info('State change: '+state);

    if (state === 'poweredOn') {
        log.info("Start scanning");
        noble.startScanning();

    } else {
        log.info("Stop scanning");
        noble.stopScanning();
    }
});

I can see the stateChange event right after I launch my (node) application and everything works fine. But if I use this within node-webkit, nothing happens and I can't use the module.

I also used the native usb module within nw.js and usb.getDeviceList() returns the list of devices as expected. So I guess everything is installed/compiled as it should be ... or is this expectation wrong?

And there is also another module - bluetooth-hci-socket - involved which seems to be a native one (there is a src folder with cpp/h sources). If I run "nw-gyp rebuild --target=0.22.3 --arch=x64" in the "node_modules/bluetooth-hci-socket" folder, everything compiles ok.

If I run the same nw-gyp in the "node_modules/usb" folder I do get an error (Error: gyp failed with exit code: 1 ...). But when running "node-pre-gyp rebuild --runtime=node-webkit --target=0.22.3" everything compiles in the usb folder as well - But I am not sure if both syntaxes are ok.

Anyway. Anyone else got noble running in nw.js and could help me out? Thanks very much!

I am using the actual nw.js (nw.js v0.22.3 / Node v7.10.0 / Chromium 58.0.3029.110), node.js v7.10.0, nw-gyp v3.4.0, node-pre-gyp v0.6.36 ... running on Linux (Mint 17.x)



via Markus M

No comments:

Post a Comment