Giter VIP home page Giter VIP logo

noble's People

Contributors

airdrummingfool avatar akx avatar apollon77 avatar atrovato avatar colemurray avatar debenben avatar dnicolson avatar domir avatar don avatar donavanbecker avatar ebaauw avatar enami avatar geovie avatar jacobrosenthal avatar joshua-smith4 avatar junkern avatar loghorn avatar mfgcode avatar millenniumbrain avatar mrose17 avatar mrstegeman avatar programmarchy avatar projectgus avatar pursual avatar rsmeral avatar rzr avatar sandeepmistry avatar symbitic avatar taktran avatar yackermann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

noble's Issues

Handling USB reconnects

We have an environment with lots of Wifi/BLE traffic that causes the Asus USB sticks to freeze every now and then. We work around this by reseting the stick (hciconfig hci0 down, up)

Unluckily, the hci.js does not recognize this but keeps the initial hci socket open. Besides complaining 'File descriptor in bad state', onSocketError does nothing useful.

As a test case (and preliminary fix), here is a minimal test case that scans for a second, forces the stick to power off, waits or it to appear again and re-initializes the hci layer with a new HciSocket object:

// survive restarts of usb dongles. initializes hciSocket again on error...
// tested with
// 0b05:17cb ASUSTek Computer, Inc. Broadcom BCM20702A0 Bluetooth

import { exec, execSync } from "child_process"

const noble = require('@abandonware/noble')

var BluetoothHciSocket = require('@abandonware/bluetooth-hci-socket');

noble._bindings._hci._socket.on('error', (error: any) => {
  console.log(error.message)
  // noble._bindings._hci._socket = new BluetoothHciSocket()
})

let timer: NodeJS.Timeout

function msleep (ms: number) {
  return new Promise(resolve => {
    setTimeout(resolve, ms)
  })
}

async function checkHciDevice () {
  let out = ''

  let up = execSync('hciconfig; hciconfig hci0 up; echo ""').toString()
  console.log('UP ' + up)
  if (up.indexOf('UP RUNNING')>0){
    msleep(200)
    console.log('hci found -- re-init hci!')
    noble._bindings._hci._socket = new BluetoothHciSocket()
    noble._bindings._hci.init()
    clearInterval(timer)
  } else {
    console.log('wait a little longer...')
  }
}

noble.on('stateChange', (state: string) => {
  console.log('noble--> stateChange ' + state)
  switch (state) {
    case 'poweredOn':
      noble.startScanning()
      // collect 1s of advertisments
      setTimeout(() => {
        execSync('hciconfig hci0 down; hciconfig')
      }, 1000)
      // after the timeout, the dongle disconnects and re-associates 
      break;
    case 'poweredOff':
      // wait for hci device to reconfigure and up it again. This needs a few seconds 
      // for the USB subsytem to reconfigure.
      setTimeout(()=>{
        timer = setInterval(checkHciDevice, 500)
      }, 5000)
      break;
    default:
      console.log('gaehn. ' + state)
  }
})

noble.on('discover', (peripheral: any) =>
  console.log(peripheral.address)
)

IMHO, onSocketError should at least emit an event for that case plus maybe a helper function to call hci.init() with a new socket object. Any suggestions?

Multiple processes using BLE

I have pi zero running raspbian stretch.

I have 2 node processes that are scanning and looking for different profiles. Running these processes one at a time is working perfectly.

As soon as I run them side by side. I am getting very strange behaviors almost like the two processes are using the same instance of noble.

I am getting errors like the below from process 1 when process 2 gets data on notify event ...
noble: unknown peripheral c7c3fb76b827 handle notify!

Please help :(

Data loss on Raspi 3 notifications

I experience major data loss on Raspi when subscribing to characteristic. My goal is to push through about 48000 bytes but I loose data at random places. The code I use is the following:

class A { 
     ...
     this.waitForData();
     setTimeout(async () => {
           await this.signUpForCharacteristic()
                 resolve()
     }, 250)

    waitForData() {
        let swinger = this
        var counter = 0
        this.characteristic.on('data', (data, isNotification) => {
            counter = counter + data.length
            let arr = [Buffer.from(swinger.downloadedData), data];
            swinger.downloadedData = Buffer.concat(arr);
            process.stdout.write(`Data received: [${counter}] [${isNotification}] [${swinger.downloadedData.length}] ${common.toHexString(data)}\x1B[0G`);
        });
    }

    async signUpForCharacteristic() {
        common.logger.info('Subscribing to notification')
        return new Promise((resolve, failure) => {
            this.characteristic.notify(true,error => {
                if (error == null) {
                    common.logger.info('Subscribed to notification')
                    resolve()
                }
                else {
                    common.logger.info(`Could not subscribe to notification: ${error.toString()}`)
                    failure(error)
                }
            })
        })
    }
}

Few bytes are missing. Using bluepy all data arrives perfectly 10 out 10 so it is not a hardware related issue. Also the peripheral works flawless with my mobile applications. Only Noble plays this to me.
Raspi 4 seems to be fine.
Do you have any suggestions?

Unintuitive method signatures

Signatures of some methods are not what they seem (and what the documentation seems to suggest).

E.g. in case of Service.discoverIncludedServices(serviceUuids, callback) – the docs suggest that serviceUuids is optional. But what's counterintuitive is, that you can either call as
discoverIncludedServices(serviceUuids, callback)
or
discoverIncludedServices().

But when you call
discoverIncludedServices(callback) (omitting just the "optional" serviceUuids)
unexpected behaviour ensues – it would try to pass the callback function as the serviceUUIDs to the lower layer.

I've noticed this with other methods as well.

I'll try to come up with a fix. Any ideas welcome.
So far, I was thinking of either:

  • fix README and index.d.ts to clarify this quirk
  • fix param handling in affected methods (e.g. first arg becomes serviceUuidsOrCallback, and then we check if (typeof serviceUuidsOrCallback === 'function') {...}

Subscription to Xiaomi Mi Kettle statusCharacteristic crashes with ERR_OUT_OF_RANGE

I'm trying to connect to my bluetooth enabled kettle using noble. Everything works fine up to the point I'm subscribing to the status update topic using .notify(true, err => {console.log(err)})

Editing gatt.js to ignore the out of bounds read results in a perfectly fine stream of status updates from the kettle.

Is this a Bug in Noble? Is this a non-standard Implementation by Xiaomi?

https://github.com/abandonware/noble/blob/master/lib/hci-socket/gatt.js#L625
data looks like this: <Buffer 09 03 3e 00 00>

internal/buffer.js:55
  throw new ERR_OUT_OF_RANGE(type || 'offset',
  ^

RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 3. Received 4
    at boundsError (internal/buffer.js:55:9)
    at Buffer.readUInt16LE (internal/buffer.js:134:5)
    at Gatt.<anonymous> (/home/hypfer/WebstormProjects/ble_things/node_modules/@abandonware/noble/lib/hci-socket/gatt.js:625:24)
    at Gatt.onAclStreamData (/home/hypfer/WebstormProjects/ble_things/node_modules/@abandonware/noble/lib/hci-socket/gatt.js:132:26)
    at AclStream.emit (events.js:187:15)
    at AclStream.push (/home/hypfer/WebstormProjects/ble_things/node_modules/@abandonware/noble/lib/hci-socket/acl-stream.js:35:10)
    at NobleBindings.onAclDataPkt (/home/hypfer/WebstormProjects/ble_things/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:286:15)
    at Hci.emit (events.js:182:13)
    at Hci.onSocketData (/home/hypfer/WebstormProjects/ble_things/node_modules/@abandonware/noble/lib/hci-socket/hci.js:497:14)
    at BluetoothHciSocket.emit (events.js:182:13)

MTU gets set but not Used

Hi,

I have an issue subscribing to characteristics. The notification only contains 20bytes.

My MTU gets set after I Requested the Services. It is not set after the Connect.
When I then console.log() the peripheral, I get the correct MTU value.
But as soon as I receive a notification I receive only 20 Bytes.

My Bluetooth Devices works fine. I tested everything using gatttool.
In Gatttool I had to first connect to the device. Then set the MTU. Then I could subscribe. Without setting the MTU manualy I got only 20bytes.

Is It possible to set the MTU manually using Noble?

I tested everything using a Raspberry Pi 4 and 3b+.

Br.

Thank you for this fix

Just came here to say thank you so much for this fix of noble! It works perfectly!

Why always complain? Why not compliment in a GitHub issue!

Cheers ✌️

Connection Issues

So, great stuff. I'm building an app using noble on osx and a raspberry pi zero w. they are both using nodejs 13.13.x and trying to connect to an iphone x, xs and iphone 7. the three phones have already been paired to the osx machine but have been removed. the devices have never been paired with any of the raspberry pi boards.

the issue is noble won't connect to any of the mobile devices. i've had them on standby mode, had settings open with bluetooth on and scanning, i've set the discoverable to on on the raspberry pi boards as well as pairable to on. i have also forced initiate a connection in and out of noble and can confirm that bluetooth works on every device and machine. when i use bluetoothctl, i can pair any of the iphone devices with any of the raspberry pi boards.

i guess my question is, what am i doing wrong and how to i make them connect with noble.

i've started a new project and copied the cache-gatt-discovery example as well as the other examples and regardless, nothing seems to get the connect to work. it will output that it's getting ready to connect, stops the scan and tries to connect. it never fails and never connects though.

any idea why?

install failing on Mojave (osx 10.14.6)

Hi!

First saw this compile error on mainline noble, and saw a comment there that suggested this fork. I am seeing the same compile failure:

$ npm install @abandonware/noble

> [email protected] install /Users/jake/code/node_modules/xpc-connection
> node-gyp rebuild

CXX(target) Release/obj.target/binding/src/XpcConnection.o
 ../src/XpcConnection.cpp:26:77: error: too few arguments to function call, single argument 'context' was not
  specified
target->Set(Nan::New("XpcConnection").ToLocalChecked(), tmpl->GetFunction());
                                                      ~~~~~~~~~~~~~~~~~ ^
/Users/jake/Library/Caches/node-gyp/13.6.0/include/node/v8.h:6283:3: note: 'GetFunction' declared here
V8_WARN_UNUSED_RESULT MaybeLocal<Function> GetFunction(
^

Node v13.6.0
npm v6.13.4

Both freshly installed.

index.d.ts error

node_modules/@abandonware/noble/index.d.ts:48:2 - error TS1036: Statements are not allowed in ambient contexts.
48 };

I can fix it by manually patching the file file to remove the semicolon at line 48. I don't think its an error per-se but my linter sure doesn't like it.

1800 missing on mac?

is it not possible to get the generic access on mac?
read somewhere upstream that it's only possible on linux?

Discovering of bleno peripheral does not work in multi-role scenarios

I start a bleno peripheral and can connect and discover the services and characteristics. Once I use noble to connect to another peripheral I cannot discover the services and characteristics of my peripheral any more.

In noble mutli role scenarios are explicitly supported:
60fa47e

Bleno explicitly ignores connects by wrong roles:
https://github.com/abandonware/bleno/blob/master/lib/hci-socket/bindings.js#L135
but noble doesn't:
https://github.com/abandonware/noble/blob/master/lib/hci-socket/bindings.js#L173

It seems its up to noble which accepts connections from from another central. Once I added the same check for noble, discovering of the bleno peripheral works again. I will create a pull request for this.

Hard node crash on MacOS Mojave

Crashes with the following traceback:

FATAL ERROR:  Cannot read property 'find' of undefined
 1: 0x1000660f9 node::Abort() [/usr/local/bin/node]
 2: 0x100066785 node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
 3: 0x10006666c node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
 4: 0x100049c79 napi_fatal_error [/usr/local/bin/node]
 5: 0x104a9b641 Napi::Error::Fatal(char const*, char const*) [/tmp/test/node_modules/@abandonware/noble/lib/mac/native/binding.node]
 6: 0x104aa6c45 ThreadSafeCallback::Impl::static_async_callback(uv_async_s*) [/tmp/test/node_modules/@abandonware/noble/lib/mac/native/binding.node]
 7: 0x100768676 uv__async_io [/usr/local/bin/node]
 8: 0x100777d41 uv__io_poll [/usr/local/bin/node]
 9: 0x100768b0b uv_run [/usr/local/bin/node]
10: 0x1000486a7 node::StartNodeWithIsolate(v8::Isolate*, node::IsolateData*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) [/usr/local/bin/node]
11: 0x100048271 node::StartNodeWithLoopAndArgs(uv_loop_s*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) [/usr/local/bin/node]
12: 0x100047f0b node::Start(int, char**) [/usr/local/bin/node]
13: 0x7fff6f6973d5 start [/usr/lib/system/libdyld.dylib]
14: 0x1
Abort trap: 6
$ node -v
v11.13.0

Running @abandonware/noble at version 1.9.2-2.

Can be reproduced with the following:

const noble = require("@abandonware/noble");
class Scanner {
  constructor() {
    noble.on("discover", this.onDiscover.bind(this));
    noble.on("scanStart", this.onScanStart.bind(this));
    noble.on("stateChange", () => {
      noble.startScanning([], true);
    });
  }

  onScanStart() {
    this.log.debug("Started scanning.");
  }

  onDiscover(peripheral) {
    console.log(peripheral);
  }
}
const scanner = new Scanner();

It does not crash when the scanStart event callback is bound to an anonymous function like this:

noble.on("scanStart", () => this.log.debug("Started scanning."));

Maybe @geovie has some insight in this?

Using noble and bleno at the same time

Hi,

I want to build a proxy for a proprietary BLE gadget (health) providing a non-proprietary BLE service. At the moment a I can start advertising using bleno and scan for the gadget using noble. On connecting to the peripheral by noble the callback (https://github.com/abandonware/noble#connect) is never called and there is no error.

I use Windows 10 and WinUSB as a driver for an Intel Bluetooth 5.0 chip. I would like to use a Raspberry Pi Zero W for production (which I didn't buy yet).

  1. There is a hint at https://github.com/abandonware/noble#bleno-compatibility about this, but this flag did not change anything. Might this be up to the WinUSB? Should WinUSB provide Bluetooth 4.1 functionality?
  2. Should this work using the Raspberry Pi and Linux?
  3. Should it work to connect to a peripheral as a central using noble and be connected to another centrals as a peripheral using bleno? Or is this something which won't work anyway?
  4. Should this work using two processes? On windows it doesn't seem so, but what about Linux?
  5. Is the only way to get this work by using two BLE adapters (e.g. Raspberry's onboard and another USB dongle)?

I appreciate for any hint

Cheers,
Stephan

node 12.8 - dependency @abandonware/bluetooth-hci-socket build fail

I believe the reason this fork was made was to fix this problem in node 10. Yet, I still seem to have this trouble with both the original noble and this @abondonware version.

gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:196:23)
gyp ERR! stack     at ChildProcess.emit (events.js:203:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Linux 4.19.57-v7+
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/home/pi/Public/scanner/node_modules/@abandonware/bluetooth-hci-socket/lib/binding/binding.node" "--module_name=binding" "--module_path=/home/pi/Public/scanner/node_modules/@abandonware/bluetooth-hci-socket/lib/binding" "--napi_version=4" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v72"
gyp ERR! cwd /home/pi/Public/scanner/node_modules/@abandonware/bluetooth-hci-socket
gyp ERR! node -v v12.8.0
gyp ERR! node-gyp -v v5.0.3
gyp ERR! not ok 
node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/home/pi/Public/scanner/node_modules/@abandonware/bluetooth-hci-socket/lib/binding/binding.node --module_name=binding --module_path=/home/pi/Public/scanner/node_modules/@abandonware/bluetooth-hci-socket/lib/binding --napi_version=4 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v72' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/home/pi/Public/scanner/node_modules/@abandonware/bluetooth-hci-socket/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:203:13)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
node-pre-gyp ERR! System Linux 4.19.57-v7+
node-pre-gyp ERR! command "/usr/local/bin/node" "/home/pi/Public/scanner/node_modules/@abandonware/bluetooth-hci-socket/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /home/pi/Public/scanner/node_modules/@abandonware/bluetooth-hci-socket
node-pre-gyp ERR! node -v v12.8.0
node-pre-gyp ERR! node-pre-gyp -v v0.12.0
node-pre-gyp ERR! not ok 
Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/home/pi/Public/scanner/node_modules/@abandonware/bluetooth-hci-socket/lib/binding/binding.node --module_name=binding --module_path=/home/pi/Public/scanner/node_modules/@abandonware/bluetooth-hci-socket/lib/binding --napi_version=4 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v72' (1)
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @abandonware/[email protected] install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @abandonware/[email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Co maintenance

As I said, elsewhere as creator of @abandonware org, I am open to co maintainership,
but it's hard to trust everyone, specially when taking over orphan packages. So I don't want to put users under any risk.

In short term, I propose this rule:

Any developer can apply but he should already has committed to an opensource organisation that he will behave nicely (to not intentionally commit malicious code), An explicit proof of commitment should be provided too.

Related links:

I am open to suggestions.

Tracking changes is also welcome, ask me how if unsure:

Implement Bluetooth 5.0 Devices to Noble Library

Hi,

i am trying to receive data from an Intel NUC AC-9462 Wireless/Bluetooth device, which implements BLE 5.1 I am able to interface with this device from Ubuntu directly.

With bluetoothctl: scan on, no other devices where found. I think it can not be detected from noble library.

My device:
hci0: Type: Primary Bus: USB
BD Address: 20:16:B9:36:65:C2 ACL MTU: 1021:4 SCO MTU: 96:6
UP RUNNING
RX bytes:17130 acl:0 sco:0 events:2776 errors:0
TX bytes:678668 acl:0 sco:0 commands:2773 errors:0
Features: 0xbf 0xfe 0x0f 0xfe 0xdb 0xff 0x7b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH SNIFF
Link mode: SLAVE ACCEPT
Name: 'ubuntu20-iobroker'
Class: 0x0c0104
Service Classes: Rendering, Capturing
Device Class: Computer, Desktop workstation
HCI Version: 5.1 (0xa) Revision: 0x100
LMP Version: 5.1 (0xa) Subversion: 0x100
Manufacturer: Intel Corp. (2)

Whats nessesary to implememt this device or any other bluetooth 5.1 device on the noble library?

Fails to rebuild on electron 1.8.8!

✖ Rebuild Failed

An unhandled error occurred inside electron-rebuild
  CC(target) Release/obj.target/nothing/../node-addon-api/src/nothing.o
  LIBTOOL-STATIC Release/nothing.a
  CXX(target) Release/obj.target/binding/lib/mac/src/noble_mac.o
In file included from ../lib/mac/src/noble_mac.mm:7:
In file included from ../lib/mac/src/noble_mac.h:3:
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:987:24: error: unknown type name 'napi_async_context'
                       napi_async_context context = nullptr) const;
                       ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:990:24: error: unknown type name 'napi_async_context'
                       napi_async_context context = nullptr) const;
                       ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:994:24: error: unknown type name 'napi_async_context'
                       napi_async_context context = nullptr) const;
                       ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:987:43: error: cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'
                       napi_async_context context = nullptr) const;
                                          ^         ~~~~~~~
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:987:43: note: passing argument to parameter 'context' here
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:990:43: error: cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'
                       napi_async_context context = nullptr) const;
                                          ^         ~~~~~~~
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:990:43: note: passing argument to parameter 'context' here
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:994:43: error: cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'
                       napi_async_context context = nullptr) const;
                                          ^         ~~~~~~~
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:994:43: note: passing argument to parameter 'context' here
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1016:7: error: unknown type name 'napi_deferred'
      napi_deferred _deferred;
      ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1168:30: error: unknown type name 'napi_async_context'
                             napi_async_context context = nullptr) const;
                             ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1171:30: error: unknown type name 'napi_async_context'
                             napi_async_context context = nullptr) const;
                             ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1175:30: error: unknown type name 'napi_async_context'
                             napi_async_context context = nullptr) const;
                             ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1168:49: error: cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'
                             napi_async_context context = nullptr) const;
                                                ^         ~~~~~~~
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1168:49: note: passing argument to parameter 'context' here
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1171:49: error: cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'
                             napi_async_context context = nullptr) const;
                                                ^         ~~~~~~~
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1171:49: note: passing argument to parameter 'context' here
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1175:49: error: cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'
                             napi_async_context context = nullptr) const;
                                                ^         ~~~~~~~
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1175:49: note: passing argument to parameter 'context' here
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1759:14: error: unknown type name 'napi_async_context'
    operator napi_async_context() const;
             ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1763:5: error: unknown type name 'napi_async_context'
    napi_async_context _context;
    ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:2045:20: error: unknown type name 'napi_node_version'
      static const napi_node_version* GetNodeVersion(Env env);
                   ^
In file included from ../lib/mac/src/noble_mac.mm:7:
In file included from ../lib/mac/src/noble_mac.h:3:
In file included from /Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:2051:
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi-inl.h:437:24: error: use of undeclared identifier 'napi_is_promise'
  napi_status status = napi_is_promise(_env, _value, &result);
                       ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi-inl.h:448:24: error: use of undeclared identifier 'napi_is_dataview'
  napi_status status = napi_is_dataview(_env, _value, &result);
                       ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi-inl.h:535:24: error: use of undeclared identifier 'napi_create_double'
  napi_status status = napi_create_double(env, val, &value);
                       ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Release/obj.target/binding/lib/mac/src/noble_mac.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/herrjemand/testElectronAPP/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Darwin 18.7.0
gyp ERR! command "/Users/herrjemand/.nvm/versions/node/v8.16.1/bin/node" "/Users/herrjemand/testElectronAPP/node_modules/.bin/node-gyp" "rebuild" "--target=1.8.8" "--arch=x64" "--dist-url=https://electronjs.org/headers" "--build-from-source"
gyp ERR! cwd /Users/herrjemand/testElectronAPP/node_modules/noble
gyp ERR! node -v v8.16.1
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok

Failed with exit code: 1

Error:   CC(target) Release/obj.target/nothing/../node-addon-api/src/nothing.o
  LIBTOOL-STATIC Release/nothing.a
  CXX(target) Release/obj.target/binding/lib/mac/src/noble_mac.o
In file included from ../lib/mac/src/noble_mac.mm:7:
In file included from ../lib/mac/src/noble_mac.h:3:
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:987:24: error: unknown type name 'napi_async_context'
                       napi_async_context context = nullptr) const;
                       ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:990:24: error: unknown type name 'napi_async_context'
                       napi_async_context context = nullptr) const;
                       ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:994:24: error: unknown type name 'napi_async_context'
                       napi_async_context context = nullptr) const;
                       ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:987:43: error: cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'
                       napi_async_context context = nullptr) const;
                                          ^         ~~~~~~~
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:987:43: note: passing argument to parameter 'context' here
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:990:43: error: cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'
                       napi_async_context context = nullptr) const;
                                          ^         ~~~~~~~
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:990:43: note: passing argument to parameter 'context' here
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:994:43: error: cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'
                       napi_async_context context = nullptr) const;
                                          ^         ~~~~~~~
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:994:43: note: passing argument to parameter 'context' here
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1016:7: error: unknown type name 'napi_deferred'
      napi_deferred _deferred;
      ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1168:30: error: unknown type name 'napi_async_context'
                             napi_async_context context = nullptr) const;
                             ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1171:30: error: unknown type name 'napi_async_context'
                             napi_async_context context = nullptr) const;
                             ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1175:30: error: unknown type name 'napi_async_context'
                             napi_async_context context = nullptr) const;
                             ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1168:49: error: cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'
                             napi_async_context context = nullptr) const;
                                                ^         ~~~~~~~
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1168:49: note: passing argument to parameter 'context' here
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1171:49: error: cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'
                             napi_async_context context = nullptr) const;
                                                ^         ~~~~~~~
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1171:49: note: passing argument to parameter 'context' here
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1175:49: error: cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'
                             napi_async_context context = nullptr) const;
                                                ^         ~~~~~~~
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1175:49: note: passing argument to parameter 'context' here
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1759:14: error: unknown type name 'napi_async_context'
    operator napi_async_context() const;
             ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:1763:5: error: unknown type name 'napi_async_context'
    napi_async_context _context;
    ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:2045:20: error: unknown type name 'napi_node_version'
      static const napi_node_version* GetNodeVersion(Env env);
                   ^
In file included from ../lib/mac/src/noble_mac.mm:7:
In file included from ../lib/mac/src/noble_mac.h:3:
In file included from /Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi.h:2051:
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi-inl.h:437:24: error: use of undeclared identifier 'napi_is_promise'
  napi_status status = napi_is_promise(_env, _value, &result);
                       ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi-inl.h:448:24: error: use of undeclared identifier 'napi_is_dataview'
  napi_status status = napi_is_dataview(_env, _value, &result);
                       ^
/Users/herrjemand/testElectronAPP/node_modules/node-addon-api/napi-inl.h:535:24: error: use of undeclared identifier 'napi_create_double'
  napi_status status = napi_create_double(env, val, &value);
                       ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Release/obj.target/binding/lib/mac/src/noble_mac.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/herrjemand/testElectronAPP/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Darwin 18.7.0
gyp ERR! command "/Users/herrjemand/.nvm/versions/node/v8.16.1/bin/node" "/Users/herrjemand/testElectronAPP/node_modules/.bin/node-gyp" "rebuild" "--target=1.8.8" "--arch=x64" "--dist-url=https://electronjs.org/headers" "--build-from-source"
gyp ERR! cwd /Users/herrjemand/testElectronAPP/node_modules/noble
gyp ERR! node -v v8.16.1
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok

Failed with exit code: 1
    at SafeSubscriber._error (/Users/herrjemand/testElectronAPP/node_modules/spawn-rx/lib/src/index.js:267:84)
    at SafeSubscriber.__tryOrUnsub (/Users/herrjemand/testElectronAPP/node_modules/rxjs/internal/Subscriber.js:205:16)
    at SafeSubscriber.error (/Users/herrjemand/testElectronAPP/node_modules/rxjs/internal/Subscriber.js:156:26)
    at Subscriber._error (/Users/herrjemand/testElectronAPP/node_modules/rxjs/internal/Subscriber.js:92:26)
    at Subscriber.error (/Users/herrjemand/testElectronAPP/node_modules/rxjs/internal/Subscriber.js:72:18)
    at MapSubscriber.Subscriber._error (/Users/herrjemand/testElectronAPP/node_modules/rxjs/internal/Subscriber.js:92:26)
    at MapSubscriber.Subscriber.error (/Users/herrjemand/testElectronAPP/node_modules/rxjs/internal/Subscriber.js:72:18)
    at SafeSubscriber._next (/Users/herrjemand/testElectronAPP/node_modules/spawn-rx/lib/src/index.js:242:65)
    at SafeSubscriber.__tryOrUnsub (/Users/herrjemand/testElectronAPP/node_modules/rxjs/internal/Subscriber.js:205:16)
    at SafeSubscriber.next (/Users/herrjemand/testElectronAPP/node_modules/rxjs/internal/Subscriber.js:143:22)
Connecting process...
Error connecting to Noble API. The error is:  Error: The module '/Users/herrjemand/testElectronAPP/node_modules/noble/lib/mac/native/binding.node'
was compiled against the ABI-stable Node.js API (N-API).
This feature is experimental and must be enabled on the
command-line by adding --napi-modules.
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:172:20)
    at Object.Module._extensions..node (module.js:598:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:172:20)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/herrjemand/testElectronAPP/node_modules/noble/lib/mac/bindings.js:4:16)
    at Object.<anonymous> (/Users/herrjemand/testElectronAPP/node_modules/noble/lib/mac/bindings.js:10:3)
ELECTRON VERSION: 1.8.8
NODE VERSION: 8.2.1

Caught illegal packet

Noble started to spit out hell of a lot of debug messages. I do not know where it comes from tbo but it is quite annoying.

processLeAdvertisingReport: Caught illegal packet (buffer overflow): TypeError: device.isIdentifiedByAdvertisement is not a function

unable to write

version = 1.9.2-8

I am unable to write a byte (buffer) value to my device using the code below, there are no errors and it appears to complete successfully, however the value is never written to the device registry.

If I use nrfConnect on my phone, then I can update this register successfully, however using noble the value is never updated and no errors are generated.

What am I doing wrong ?

const cl = console.log;
function go(per){
  per.connect(function(error) {
  	cl(1,per.state)
  	per.discoverServices(['aa20'], function(error, services) {
  		cl(2,per.state)
  		var devsvc = services[0];
  		devsvc.discoverCharacteristics(['aa23'], function(error, characteristics) {
  		  cl(3,per.state)
  		  var cdata = characteristics[0];
  			var buf = Buffer.allocUnsafe(1);
  			buf.writeUInt8(0xFF);
  			characteristics[0].write(buf,true,function(err){
  			  cl(4,per.state)
  			  per.disconnect(cl);
  			});
  		})
  	})
  })
}

MacOS, Raspberry Pi: Peripheral.mtu is not set

Affects MacOS Catalina 10.15.3 (MacBook Pro Retina, 15", Late 2013) and Raspbian Buster February 2020 (Raspberry Pi 3 B) - I have no other devices to check this.

Peripheral.mtu seems to never get set for me. Looking at the MacOS PacketLogger I can see a Exchange MTU Request and Exchange MTU Response.

Workaround

My workaround currently is to use a default value that is working for the devices I have for testing and to make the mtu configureable.

Documentation structure

Hello everyone ! :)

I was on a big problem with noble since i found this one and make noble working (only the stateChange event) and thank you for that... It was a good start.

I was on the impossibility to get my devices with the discover event... Don't tell me why, no errors, just nothing appear on the terminal...

Just because i didn't read the entire doc...

Someone teach me than, it's useless to continue reading if something doesn't work or something you don't understand... It's true.

Well, then, do you know how i solve my problem ?

I solve my problem with this command line ... Who is at the bottom of this documentation...
sudo setcap cap_net_raw+eip $(eval readlink -f which node)

Now when i execute my code, he's going on my discover event and i finally get my devices...

Why the hell Running on Linux section is at the bottom of the documentation ?

I hope i'm not alone to do something like that. :) And i hope so, but please, can you put the Running on Linux section at the top inside Prerequisites or Notes maybe ?

Maybe that will help others...

Characteristics do not update until connection is reestablished on a Raspberry Pi

On macOS, the following code polls for the state of a Switchbot device successfully. On a Raspberry Pi, the advertisement data does not update until a new connection is made.

For comparison, Python code using the bluetooth or the bluepy modules work but seize control of the device rendering the official app unable to make a connection with the device.

Is this perhaps due to differences between CoreBluetooth and BlueZ?

const noble = require('@abandonware/noble');

const address = 'FF:FF:FF:FF:FF:FF';

const uuidPrimary = 'cba20d00224d11e69fb80002a5d5c51b';
const uuidWrite = 'cba20002224d11e69fb80002a5d5c51b';

const getState = peripheral => {
  const advertisement = peripheral.advertisement;
  const serviceData = advertisement.serviceData;
  const buf = serviceData[0].data;
  const byte1 = buf.readUInt8(1);
  return byte1 & 0b01000000 ? true : false;
};

noble.on('stateChange', state => {
  if (state === 'poweredOn') {
    noble.startScanning([uuidPrimary], false);
  } else {
    noble.stopScanning();
  }
});

noble.on('discover', peripheral => {
  if (peripheral.address.match(new RegExp(address.replace(/:/g, '.'), 'i'))) {
    peripheral.connect(error => {
      peripheral.discoverServices([uuidPrimary], (error, services) => {
        services[0].discoverCharacteristics([uuidWrite], (error, characteristics) => {
          setInterval(() => console.log('State:', getState(peripheral)), 1000);
        });
      });
    });
  }
});

MacOS: discoverAllServicesAndCharacteristics causes write-callback not being called

First of all: Thanks so much for you hard work maintaining this library - I am very grateful for being able to use a node lib for communicating with bluetooth le devices!!! :)

Here is the problem I'd like to report:

When using a characteristic retrieved with discoverAllServicesAndCharacteristics for writes then the write callback is never called. (But the write is performed - the data arrives on the target device)

Operating System: MacOS Catalina 10.15.3

On a raspberry pi 3B I cannot reproduce the problem - everything seems to work as expected.

Example - Retrieving characteristics

[...]
peripheral.discoverAllServicesAndCharacteristics((error, services, characteristics) => {
    if (error)
    {
        reject(`Error discovering characteristics: ${error}`);
        return;
    }
    if (characteristics)
    {
        resolve(characteristics);
    }
});
[...]

Example - Write

[...]
const writeListener = (err: string): void => {
    if (err) {
        reject(`Error writing: ${err}`);
    }
    resolve();
};

characteristic.write(data, true, (err) => {
    writeListener(err); // this is never called, same with `characteristic.once('write', writeListener)`
});
[...]

Workaround

My workaround currently is to use discoverSomeServicesAndCharacteristics with a list of all characteristics (UUIDs) that I need. (Calling this method more than once results in the same problem)

Disconnection event received immediately after Connection on Raspberry Pi 3 B+

I'm currently trying to connect to one of my peripherals using @abandonware/noble,
As soon as a connection is established, i call discoverServices() and most of the time the connection falls immediately.
I use event-based transitions using Statecharts, so I'm sure there's no overlapping of commands during the connection.
It's totally related to:
noble#465
Where some people think it's because BLE and WiFi are on the same chipset on RPi 3B+ and RPi Zero. Although these boards work well on bluepy according to someone on the thread. So I think the problem it's related to hci.
Any ideas on how to solve this?

Using noble within a docker container

I am trying to use noble in a node (v13.8.0) app running in a local docker container.

When I run my application I receive the below error. It seems like there is an issue with hci-socket.

`/app/node_modules/@abandonware/noble/lib/hci-socket/hci.js:75
this._socket = new BluetoothHciSocket();
^

Error: EAFNOSUPPORT, Address family not supported by protocol
at new Hci (/app/node_modules/@abandonware/noble/lib/hci-socket/hci.js:75:18)
at new NobleBindings (/app/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:28:15)
at Object. (/app/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:511:18)
at Module._compile (internal/modules/cjs/loader.js:1151:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1040:19)
at require (internal/modules/cjs/helpers.js:72:18)
at module.exports (/app/node_modules/@abandonware/noble/lib/resolve-bindings.js:13:12) {
errno: 97,
code: 'EAFNOSUPPORT',
syscall: 'socket'
}
`

I found this on noble noble#805

Does anyone have a workaround?

Thanks!

Impossible to get services when connect to a device

Hello everyone,

I'm depress right now, i hope someone can help me a little bit, i will really appreciate this... lol

My goal is simple :
1 - On my first laptop, i'm using bleno
2 - On my second laptop, i'm using nativescript-bluetooth v2.0.0-beta.23
3 - When my second laptop read the service from my second laptop -> get a string

How can i do that ? So, time to explain a bit what i did so far ! :)

First laptop: I created a project with bleno

On my second laptop (i'm using VMWare with Ubuntu) i try to get the service from my first laptop. Big problem : The services are empty...

Here the full source code :
https://gist.github.com/Ravaniss/3f4cf62e27acb9594204321052cc0b39

{ UUID: '74:29:AF:80:17:BA', JS: name: 'echo', JS: state: 'connected', JS: services: [ [length]: 0 ], JS: advertismentData: undefined } JS: 'Peripheral connected with UUID: 74:29:AF:80:17:BA' JS: 'Disconnected successfully'

You are going to say, why don't you use noble ? Because noble or bleno doesn't work on my second laptop using Ubuntu on VMware... Tried this a lot... But works perfectly fine on my first laptop using a SSD... (Should i buy a SSD only with Ubuntu and do a dual boot... ?)

I don't think than the problem comes to nativescript-bluetooth plugin, the problem is from bleno, how can i set a service and when i'm scanning, i get a services with a length of 1 ? x)

"noble.stopScanning();" isn't working

(From: eschava/node-red-contrib-xiaomi-ble#20)

I'm using one of the supported Intel-based adapters on Windows 10.
Possibly because there's a long distance between the PC and the sensors, I sometimes don't get a result. I would be willing to try again and retrigger the node, but that's not possible. I realized that when I get to a timeout, the code gets stuck in line 162 (stopScanning). I tried to put another node.status after this line and it doesn't get there. And so it doesn't let me call the node again (probably node.scanningActive is still true). Is there a way to forcibly stop the scan somehow?

Subscribe and Notify are not working on Linux

Hi I really appreciate your work to get noble working again on the Raspberry Pi. The code seems to compile alright, and my BLE device (an ESP32) can connect, but none of the methods of the characteristic objects seem to work.

characteristic.on('data', function(data) {
   // no events
});
characteristic.subscribe(function(err) {
   // never gets called
});
otherCharacteristic.read(function(error, data) {
   // never gets called 
});
otherCharacteristic.write(buffer, false, function(error) {
   // never gets called and nothing received on device
});

My code works on MacOSX using the "noble-mac" fork but is not working with yours on a Pi3 (respbian), so perhaps there is something still missing for this to work on the Pi3 ?

Display warning/error if running with insufficient permissions

I just tried a minimalistic script for scanning the nearby peripherals, but somehow nothing happened at all. As it turned out, noble's state was and stayed "unknown" and would not switch to "poweredOn", even though my bluetooth dongle was attached.

With debug output turned on, I saw some messages suggesting there was a problem with insufficient permissions. After running the command shown in the "Running without root/sudo" section, everything worked fine.

If I remember correctly, the original noble displayed a helpful warning message if there was a problem with insufficient permissions.

MacOS Mojave support

Hi!

Thank you very much for taking the initiative to create a maintainable fork. I understand that this fork mainly was created for getting support for Node >=10 but another big issue that noble has is missing support for MacOS Mojave. This PR noble#840 fixes this and because of noble being unmaintained the PR author created a new package noble-mac - https://github.com/Timeular/noble-mac.

It would be preferable to only have one fork. Maybe noble#840 could be merged into this repository and start a discussion with the noble-mac author about making contributions to this repository instead?

Trying to list available ports with Espruino fails.

I have tried to get some help in the espruino forums but we got stuck.

Im running OSX Mojave 10.14, Node 12.7.0 (also tried 10.10.0 and 8.6.0).

I modify the espruino source code to require @abandonware/noble instead of noble, i installed @abandonware/noble v1.9.2-3

When I run espruino --list it dumps:

FATAL ERROR:  Cannot read property 'indexOf' of undefined
 1: 0x100077a0b node::Abort() [/Users/manuelabergcobo/.nvm/versions/node/v12.7.0/bin/node]
 2: 0x100077b8f node::OnFatalError(char const*, char const*) [/Users/manuelabergcobo/.nvm/versions/node/v12.7.0/bin/node]
 3: 0x100077a21 node::OnFatalError(char const*, char const*) [/Users/manuelabergcobo/.nvm/versions/node/v12.7.0/bin/node]
 4: 0x10005839a napi_open_callback_scope [/Users/manuelabergcobo/.nvm/versions/node/v12.7.0/bin/node]
 5: 0x105c8eb1d Napi::Error::Fatal(char const*, char const*) [/Users/manuelabergcobo/.nvm/versions/node/v12.7.0/lib/node_modules/espruino/node_modules/@abandonware/noble/lib/mac/native/binding.node]
 6: 0x105c9d801 ThreadSafeCallback::Impl::static_async_callback(uv_async_s*) [/Users/manuelabergcobo/.nvm/versions/node/v12.7.0/lib/node_modules/espruino/node_modules/@abandonware/noble/lib/mac/native/binding.node]
 7: 0x10086a81c uv__async_io [/Users/manuelabergcobo/.nvm/versions/node/v12.7.0/bin/node]
 8: 0x10087ad7d uv__io_poll [/Users/manuelabergcobo/.nvm/versions/node/v12.7.0/bin/node]
 9: 0x10086aca6 uv_run [/Users/manuelabergcobo/.nvm/versions/node/v12.7.0/bin/node]
10: 0x1000ad491 node::NodeMainInstance::Run() [/Users/manuelabergcobo/.nvm/versions/node/v12.7.0/bin/node]
11: 0x100057abf node::Start(int, char**) [/Users/manuelabergcobo/.nvm/versions/node/v12.7.0/bin/node]
12: 0x7fff6eecb085 start [/usr/lib/system/libdyld.dylib]
Abort trap: 6

seems like something goes awry in step 5 or 6 of the stack trace, any clues?

its important to note that if i run some script to discover peripherals using @abandonware/noble I can actually see my pucks in the listing. so I can discover peripherals but I cannot connect to them because I cant even get the ports to list with espruino --list

I know that it looks like an espruino problem, but I have been trying 2010912093093 things with noble, noble-mac and @abandonware-noble but this package seems the most popular and maintained one, would love some help :(

Issue with noble.on state change

I am trying to get this plugin working on a raspberry pi. I have an external BLE dongle attached to the pi. I have used the hcitool to verify that I can scan and connect to a BLE device.

I created a very simple node express application (node version - 10.19.0) and installed the plugin.

My package.json is as follows:

{
  "name": "angular-node-express-api",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "@abandonware/noble": "^1.9.2-7",
    "body-parser": "~1.13.2",
    "cookie-parser": "~1.3.5",
    "express": "~4.13.1"
  }
}

I copied the example code into my application as follows:

var noble = require('@abandonware/noble');

console.log('Noble ' + noble);

noble.on('stateChange', function(state) {
  console.log('Current Noble state ' + state);
  if (state === 'poweredOn') {
    noble.startScanning();
  } else {
    noble.stopScanning();
  }
});

noble.on('discover', function(peripheral) {
  console.log('peripheral discovered (' + peripheral.id +
              ' with address <' + peripheral.address +  ', ' + peripheral.addressType + '>,' +
              ' connectable ' + peripheral.connectable + ',' +
              ' RSSI ' + peripheral.rssi + ':');
  console.log('\thello my local name is:');
  console.log('\t\t' + peripheral.advertisement.localName);
  console.log('\tcan I interest you in any of the following advertised services:');
  console.log('\t\t' + JSON.stringify(peripheral.advertisement.serviceUuids));

  var serviceData = peripheral.advertisement.serviceData;
  if (serviceData && serviceData.length) {
    console.log('\there is my service data:');
    for (var i in serviceData) {
      console.log('\t\t' + JSON.stringify(serviceData[i].uuid) + ': ' + JSON.stringify(serviceData[i].data.toString('hex')));
    }
  }
  if (peripheral.advertisement.manufacturerData) {
    console.log('\there is my manufacturer data:');
    console.log('\t\t' + JSON.stringify(peripheral.advertisement.manufacturerData.toString('hex')));
  }
  if (peripheral.advertisement.txPowerLevel !== undefined) {
    console.log('\tmy TX power level is:');
    console.log('\t\t' + peripheral.advertisement.txPowerLevel);
  }

  console.log();
});

I can see an object is created from the first console.log, but the stateChange callback is never called (i.e. the state remains in an unknown state).

Is scanning/ discovery filtered somehow ?

Hi;

I am having difficulty with discovering peripherals using this module, and suspect that there is some kind of filter being applied.

When I scan using bluetoothctl, obviously I get a lot of devices, but included in that is my Temperature/Humidity device:

# devices
Device CB:D0:C5:0C:27:BD Jinou_Sensor_HumiTemp

But when I enable scanning, all that is reported is:

noble.on('stateChange', (state) => {
  console.log('Noble adapter is %s', state);

  if (state === 'poweredOn') {
    console.log('Start scanning for devices');
    noble.startScanning([], true);
  }
});

noble.on('discover', (peripheral) => {
    // Device CB:D0:C5:0C:27:BD Jinou_Sensor_HumiTemp
    console.log(peripheral.id,peripheral.advertisement.serviceUuids);
}
7990a4322454 [ 'fe9f' ]
7990a4322454 [ 'fe9f' ]
7990a4322454 [ 'fe9f' ]
7990a4322454 [ 'fe9f' ]
7990a4322454 [ 'fe9f' ]
7990a4322454 [ 'fe9f' ]
7990a4322454 [ 'fe9f' ]
7990a4322454 [ 'fe9f' ]

What am I doing wrong ?

Doesn't build with node 12.8.1 (electron 7.0.0)

If I try to use electron-rebuild with electron 7, it causes the build to fail.

I'm not sure if this is due to the changes in v8 for electron but it does seem to build on the "normal" (non electron) version of 12.8.1.

It doesn't seem to be the same problem as #21 but a problem with maybe node-usb.

$ node_modules/.bin/electron-rebuild
- Searching dependency tree
✖ Rebuild Failed

An unhandled error occurred inside electron-rebuild
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp info find Python using Python version 2.7.15 found at "/usr/bin/python"
gyp info spawn /usr/bin/python
gyp info spawn args [
gyp info spawn args   '/app/electron/node_modules/electron-rebuild/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/app/electron/node_modules/usb/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/app/electron/node_modules/electron-rebuild/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/root/.electron-gyp/7.0.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/root/.electron-gyp/7.0.0',
gyp info spawn args   '-Dnode_gyp_dir=/app/electron/node_modules/electron-rebuild/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/root/.electron-gyp/7.0.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/app/electron/node_modules/usb',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/app/electron/node_modules/usb/build'
  CC(target) Release/obj.target/libusb/libusb/libusb/core.o
  CC(target) Release/obj.target/libusb/libusb/libusb/descriptor.o
  CC(target) Release/obj.target/libusb/libusb/libusb/hotplug.o
  CC(target) Release/obj.target/libusb/libusb/libusb/io.o
  CC(target) Release/obj.target/libusb/libusb/libusb/strerror.o
  CC(target) Release/obj.target/libusb/libusb/libusb/sync.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/poll_posix.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/threads_posix.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/linux_usbfs.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/linux_udev.o
  AR(target) Release/obj.target/usb.a
  COPY Release/usb.a
  CXX(target) Release/obj.target/usb_bindings/src/node_usb.o
In file included from /root/.electron-gyp/7.0.0/include/node/v8-internal.h:14:0,
                 from /root/.electron-gyp/7.0.0/include/node/v8.h:27,
                 from ../src/node_usb.h:12,
                 from ../src/node_usb.cc:1:
/root/.electron-gyp/7.0.0/include/node/v8config.h:343:49: warning: 'MicrotasksCompletedCallback' is deprecated [-Wdeprecated-declarations]
   declarator __attribute__((deprecated(message)))
                                                 ^
/root/.electron-gyp/7.0.0/include/node/v8.h:8513:3: note: in expansion of macro 'V8_DEPRECATE_SOON'
   V8_DEPRECATE_SOON("Use *WithData version.",
   ^~~~~~~~~~~~~~~~~
/root/.electron-gyp/7.0.0/include/node/v8config.h:343:49: warning: 'MicrotasksCompletedCallback' is deprecated [-Wdeprecated-declarations]
   declarator __attribute__((deprecated(message)))
                                                 ^
/root/.electron-gyp/7.0.0/include/node/v8.h:8522:3: note: in expansion of macro 'V8_DEPRECATE_SOON'
   V8_DEPRECATE_SOON("Use *WithData version.",
   ^~~~~~~~~~~~~~~~~
../src/node_usb.cc: In function 'void Initialize(v8::Local<v8::Object>)':
../src/node_usb.cc:66:84: error: no matching function for call to 'v8::Object::Set(v8::Local<v8::String>, Nan::imp::FactoryBase<v8::Number>::return_t)'
  target->Set(Nan::New<String>("INIT_ERROR").ToLocalChecked(), Nan::New<Number>(res));
                                                                                    ^
In file included from ../src/node_usb.h:12:0,
                 from ../src/node_usb.cc:1:
/root/.electron-gyp/7.0.0/include/node/v8.h:3455:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, v8::Local<v8::Value>, v8::Local<v8::Value>)
   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
                                     ^~~
/root/.electron-gyp/7.0.0/include/node/v8.h:3455:37: note:   candidate expects 3 arguments, 2 provided
/root/.electron-gyp/7.0.0/include/node/v8.h:3458:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, uint32_t, v8::Local<v8::Value>)
   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
                                     ^~~
/root/.electron-gyp/7.0.0/include/node/v8.h:3458:37: note:   candidate expects 3 arguments, 2 provided
../src/node_usb.cc: In function 'Nan::NAN_METHOD_RETURN_TYPE GetDeviceList(Nan::NAN_METHOD_ARGS_TYPE)':
../src/node_usb.cc:116:35: error: no matching function for call to 'v8::Array::Set(int&, v8::Local<v8::Object>)'
   arr->Set(i, Device::get(devs[i]));
                                   ^
In file included from ../src/node_usb.h:12:0,
                 from ../src/node_usb.cc:1:
/root/.electron-gyp/7.0.0/include/node/v8.h:3455:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, v8::Local<v8::Value>, v8::Local<v8::Value>)
   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
                                     ^~~
/root/.electron-gyp/7.0.0/include/node/v8.h:3455:37: note:   candidate expects 3 arguments, 2 provided
/root/.electron-gyp/7.0.0/include/node/v8.h:3458:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, uint32_t, v8::Local<v8::Value>)
   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
                                     ^~~
/root/.electron-gyp/7.0.0/include/node/v8.h:3458:37: note:   candidate expects 3 arguments, 2 provided
../src/node_usb.cc: In function 'void handleHotplug(std::pair<libusb_device*, libusb_hotplug_event>)':
../src/node_usb.cc:151:58: warning: 'v8::Local<v8::Value> Nan::MakeCallback(v8::Local<v8::Object>, const char*, int, v8::Local<v8::Value>*)' is deprecated [-Wdeprecated-declarations]
  Nan::MakeCallback(Nan::New(hotplugThis), "emit", 2, argv);
                                                          ^
In file included from ../src/helpers.h:3:0,
                 from ../src/node_usb.h:21,
                 from ../src/node_usb.cc:1:
../node_modules/nan/nan.h:1001:46: note: declared here
   NAN_DEPRECATED inline v8::Local<v8::Value> MakeCallback(
                                              ^~~~~~~~~~~~
../src/node_usb.cc: In function 'v8::Local<v8::Value> libusbException(int)':
../src/node_usb.cc:301:96: error: no matching function for call to 'v8::Object::Set(v8::Local<v8::String>, Nan::imp::IntegerFactory<v8::Integer>::return_t)'
  e.As<v8::Object>()->Set(Nan::New<String>("errno").ToLocalChecked(), Nan::New<Integer>(errorno));
                                                                                                ^
In file included from ../src/node_usb.h:12:0,
                 from ../src/node_usb.cc:1:
/root/.electron-gyp/7.0.0/include/node/v8.h:3455:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, v8::Local<v8::Value>, v8::Local<v8::Value>)
   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
                                     ^~~
/root/.electron-gyp/7.0.0/include/node/v8.h:3455:37: note:   candidate expects 3 arguments, 2 provided
/root/.electron-gyp/7.0.0/include/node/v8.h:3458:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, uint32_t, v8::Local<v8::Value>)
   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
                                     ^~~
/root/.electron-gyp/7.0.0/include/node/v8.h:3458:37: note:   candidate expects 3 arguments, 2 provided
usb_bindings.target.mk:120: recipe for target 'Release/obj.target/usb_bindings/src/node_usb.o' failed
make: Leaving directory '/app/electron/node_modules/usb/build'
make: *** [Release/obj.target/usb_bindings/src/node_usb.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/app/electron/node_modules/electron-rebuild/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:203:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Linux 4.15.0-1043-aws
gyp ERR! command "/root/.nvm/versions/node/v12.8.1/bin/node" "/app/electron/node_modules/electron-rebuild/node_modules/.bin/node-gyp" "rebuild" "--target=7.0.0" "--arch=x64" "--dist-url=https://electronjs.org/headers" "--build-from-source"
gyp ERR! cwd /app/electron/node_modules/usb
gyp ERR! node -v v12.8.1
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok

Failed with exit code: 1

Error: gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp info find Python using Python version 2.7.15 found at "/usr/bin/python"
gyp info spawn /usr/bin/python
gyp info spawn args [
gyp info spawn args   '/app/electron/node_modules/electron-rebuild/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/app/electron/node_modules/usb/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/app/electron/node_modules/electron-rebuild/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/root/.electron-gyp/7.0.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/root/.electron-gyp/7.0.0',
gyp info spawn args   '-Dnode_gyp_dir=/app/electron/node_modules/electron-rebuild/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/root/.electron-gyp/7.0.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/app/electron/node_modules/usb',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/app/electron/node_modules/usb/build'
  CC(target) Release/obj.target/libusb/libusb/libusb/core.o
  CC(target) Release/obj.target/libusb/libusb/libusb/descriptor.o
  CC(target) Release/obj.target/libusb/libusb/libusb/hotplug.o
  CC(target) Release/obj.target/libusb/libusb/libusb/io.o
  CC(target) Release/obj.target/libusb/libusb/libusb/strerror.o
  CC(target) Release/obj.target/libusb/libusb/libusb/sync.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/poll_posix.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/threads_posix.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/linux_usbfs.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/linux_udev.o
  AR(target) Release/obj.target/usb.a
  COPY Release/usb.a
  CXX(target) Release/obj.target/usb_bindings/src/node_usb.o
In file included from /root/.electron-gyp/7.0.0/include/node/v8-internal.h:14:0,
                 from /root/.electron-gyp/7.0.0/include/node/v8.h:27,
                 from ../src/node_usb.h:12,
                 from ../src/node_usb.cc:1:
/root/.electron-gyp/7.0.0/include/node/v8config.h:343:49: warning: 'MicrotasksCompletedCallback' is deprecated [-Wdeprecated-declarations]
   declarator __attribute__((deprecated(message)))
                                                 ^
/root/.electron-gyp/7.0.0/include/node/v8.h:8513:3: note: in expansion of macro 'V8_DEPRECATE_SOON'
   V8_DEPRECATE_SOON("Use *WithData version.",
   ^~~~~~~~~~~~~~~~~
/root/.electron-gyp/7.0.0/include/node/v8config.h:343:49: warning: 'MicrotasksCompletedCallback' is deprecated [-Wdeprecated-declarations]
   declarator __attribute__((deprecated(message)))
                                                 ^
/root/.electron-gyp/7.0.0/include/node/v8.h:8522:3: note: in expansion of macro 'V8_DEPRECATE_SOON'
   V8_DEPRECATE_SOON("Use *WithData version.",
   ^~~~~~~~~~~~~~~~~
../src/node_usb.cc: In function 'void Initialize(v8::Local<v8::Object>)':
../src/node_usb.cc:66:84: error: no matching function for call to 'v8::Object::Set(v8::Local<v8::String>, Nan::imp::FactoryBase<v8::Number>::return_t)'
  target->Set(Nan::New<String>("INIT_ERROR").ToLocalChecked(), Nan::New<Number>(res));
                                                                                    ^
In file included from ../src/node_usb.h:12:0,
                 from ../src/node_usb.cc:1:
/root/.electron-gyp/7.0.0/include/node/v8.h:3455:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, v8::Local<v8::Value>, v8::Local<v8::Value>)
   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
                                     ^~~
/root/.electron-gyp/7.0.0/include/node/v8.h:3455:37: note:   candidate expects 3 arguments, 2 provided
/root/.electron-gyp/7.0.0/include/node/v8.h:3458:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, uint32_t, v8::Local<v8::Value>)
   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
                                     ^~~
/root/.electron-gyp/7.0.0/include/node/v8.h:3458:37: note:   candidate expects 3 arguments, 2 provided
../src/node_usb.cc: In function 'Nan::NAN_METHOD_RETURN_TYPE GetDeviceList(Nan::NAN_METHOD_ARGS_TYPE)':
../src/node_usb.cc:116:35: error: no matching function for call to 'v8::Array::Set(int&, v8::Local<v8::Object>)'
   arr->Set(i, Device::get(devs[i]));
                                   ^
In file included from ../src/node_usb.h:12:0,
                 from ../src/node_usb.cc:1:
/root/.electron-gyp/7.0.0/include/node/v8.h:3455:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, v8::Local<v8::Value>, v8::Local<v8::Value>)
   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
                                     ^~~
/root/.electron-gyp/7.0.0/include/node/v8.h:3455:37: note:   candidate expects 3 arguments, 2 provided
/root/.electron-gyp/7.0.0/include/node/v8.h:3458:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, uint32_t, v8::Local<v8::Value>)
   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
                                     ^~~
/root/.electron-gyp/7.0.0/include/node/v8.h:3458:37: note:   candidate expects 3 arguments, 2 provided
../src/node_usb.cc: In function 'void handleHotplug(std::pair<libusb_device*, libusb_hotplug_event>)':
../src/node_usb.cc:151:58: warning: 'v8::Local<v8::Value> Nan::MakeCallback(v8::Local<v8::Object>, const char*, int, v8::Local<v8::Value>*)' is deprecated [-Wdeprecated-declarations]
  Nan::MakeCallback(Nan::New(hotplugThis), "emit", 2, argv);
                                                          ^
In file included from ../src/helpers.h:3:0,
                 from ../src/node_usb.h:21,
                 from ../src/node_usb.cc:1:
../node_modules/nan/nan.h:1001:46: note: declared here
   NAN_DEPRECATED inline v8::Local<v8::Value> MakeCallback(
                                              ^~~~~~~~~~~~
../src/node_usb.cc: In function 'v8::Local<v8::Value> libusbException(int)':
../src/node_usb.cc:301:96: error: no matching function for call to 'v8::Object::Set(v8::Local<v8::String>, Nan::imp::IntegerFactory<v8::Integer>::return_t)'
  e.As<v8::Object>()->Set(Nan::New<String>("errno").ToLocalChecked(), Nan::New<Integer>(errorno));
                                                                                                ^
In file included from ../src/node_usb.h:12:0,
                 from ../src/node_usb.cc:1:
/root/.electron-gyp/7.0.0/include/node/v8.h:3455:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, v8::Local<v8::Value>, v8::Local<v8::Value>)
   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
                                     ^~~
/root/.electron-gyp/7.0.0/include/node/v8.h:3455:37: note:   candidate expects 3 arguments, 2 provided
/root/.electron-gyp/7.0.0/include/node/v8.h:3458:37: note: candidate: v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, uint32_t, v8::Local<v8::Value>)
   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
                                     ^~~
/root/.electron-gyp/7.0.0/include/node/v8.h:3458:37: note:   candidate expects 3 arguments, 2 provided
usb_bindings.target.mk:120: recipe for target 'Release/obj.target/usb_bindings/src/node_usb.o' failed
make: Leaving directory '/app/electron/node_modules/usb/build'
make: *** [Release/obj.target/usb_bindings/src/node_usb.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/app/electron/node_modules/electron-rebuild/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:203:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Linux 4.15.0-1043-aws
gyp ERR! command "/root/.nvm/versions/node/v12.8.1/bin/node" "/app/electron/node_modules/electron-rebuild/node_modules/.bin/node-gyp" "rebuild" "--target=7.0.0" "--arch=x64" "--dist-url=https://electronjs.org/headers" "--build-from-source"
gyp ERR! cwd /app/electron/node_modules/usb
gyp ERR! node -v v12.8.1
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok

Failed with exit code: 1
    at SafeSubscriber._error (/app/electron/node_modules/spawn-rx/lib/src/index.js:267:84)
    at SafeSubscriber.__tryOrUnsub (/app/electron/node_modules/rxjs/internal/Subscriber.js:205:16)
    at SafeSubscriber.error (/app/electron/node_modules/rxjs/internal/Subscriber.js:156:26)
    at Subscriber._error (/app/electron/node_modules/rxjs/internal/Subscriber.js:92:26)
    at Subscriber.error (/app/electron/node_modules/rxjs/internal/Subscriber.js:72:18)
    at MapSubscriber.Subscriber._error (/app/electron/node_modules/rxjs/internal/Subscriber.js:92:26)
    at MapSubscriber.Subscriber.error (/app/electron/node_modules/rxjs/internal/Subscriber.js:72:18)
    at SafeSubscriber._next (/app/electron/node_modules/spawn-rx/lib/src/index.js:242:65)
    at SafeSubscriber.__tryOrUnsub (/app/electron/node_modules/rxjs/internal/Subscriber.js:205:16)
    at SafeSubscriber.next (/app/electron/node_modules/rxjs/internal/Subscriber.js:143:22)
error Command failed with exit code 255.

Trouble Installing

Hi,

I'm trying to install noble, but running into an issue that I can't decipher. I'm rather ignorant about any kind of coding (trying to install noble to be able to install a homebridge plugin that requires it), so apologies if my question has an obvious answer.
I'm trying to install on a Raspberry Pi4 with Node.js version 13.9.0 and npm version 6.13.7.
Here's what I see when I run the install command

sudo npm install @abandonware/noble

[email protected] install /home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket
node-gyp rebuild

gyp WARN EACCES current user ("pi") does not have permission to access the dev dir "/root/.cache/node-gyp/13.9.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp"
make: Entering directory '/home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/build'
CXX(target) Release/obj.target/binding/src/BluetoothHciSocket.o
In file included from ../src/BluetoothHciSocket.cpp:8:
../../../../nan/nan.h: In function ‘void Nan::AsyncQueueWorker(Nan::AsyncWorker*)’:
../../../../nan/nan.h:2298:62: warning: cast between incompatible function types from ‘void ()(uv_work_t)’ {aka ‘void ()(uv_work_s)’} to ‘uv_after_work_cb’ {aka ‘void ()(uv_work_s, int)’} [-Wcast-function-type]
, reinterpret_cast<uv_after_work_cb>(AsyncExecuteComplete)
^
../src/BluetoothHciSocket.cpp: In static member function ‘static void BluetoothHciSocket::Init(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE)’:
../src/BluetoothHciSocket.cpp:128:82: error: no matching function for call to ‘v8::FunctionTemplate::GetFunction()’
get->Set(Nan::New("BluetoothHciSocket").ToLocalChecked(), tmpl->GetFunction());
^

In file included from /home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/node.h:67,
from /home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/node_buffer.h:25,
from ../src/BluetoothHciSocket.cpp:7:
/home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/v8.h:6283:46: note: candidate: ‘v8::MaybeLocalv8::Function v8::FunctionTemplate::GetFunction(v8::Localv8::Context)’
V8_WARN_UNUSED_RESULT MaybeLocal GetFunction(
^~~~~~~~~~~
/home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/v8.h:6283:46: note: candidate expects 1 argument, 0 provided
../src/BluetoothHciSocket.cpp: In member function ‘void BluetoothHciSocket::poll()’:
../src/BluetoothHciSocket.cpp:251:95: warning: ‘v8::Localv8::Value Nan::MakeCallback(v8::Localv8::Object, v8::Localv8::String, int, v8::Localv8::Value*’ is deprecated [-Wdeprecated-declarations]
back(Nan::New(this->This), Nan::New("emit").ToLocalChecked(), 2, argv);
^

In file included from ../src/BluetoothHciSocket.cpp:8:
../../../../nan/nan.h:1045:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value MakeCallback(
^~~~~~~~~~~~
../src/BluetoothHciSocket.cpp:251:95: warning: ‘v8::Localv8::Value Nan::MakeCallback(v8::Localv8::Object, v8::Localv8::String, int, v8::Localv8::Value*’ is deprecated [-Wdeprecated-declarations]
back(Nan::New(this->This), Nan::New("emit").ToLocalChecked(), 2, argv);
^

In file included from ../src/BluetoothHciSocket.cpp:8:
../../../../nan/nan.h:1045:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value MakeCallback(
^~~~~~~~~~~~
../src/BluetoothHciSocket.cpp: In member function ‘void BluetoothHciSocket::emitErrnoError()’:
../src/BluetoothHciSocket.cpp:269:109: error: no matching function for call to v8::Object::Get(v8::Localv8::String)’
or = Local::Cast(globalObj->Get(Nan::New("Error").ToLocalChecked()));
^

In file included from /home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/node.h:67,
from /home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/node_buffer.h:25,
from ../src/BluetoothHciSocket.cpp:7:
/home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/v8.h:3594:43: note: candidate: ‘v8::MaybeLocalv8::Value v8::Object::Get(v8::Localv8::Context, v8::Localv8::Value)’
V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context,
^~~
/home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/v8.h:3594:43: note: candidate expects 2 arguments, 1 provided
/home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/v8.h:3597:43: note: candidate: ‘v8::MaybeLocalv8::Value v8::Object::Get(v8::Localv8::Context, uint32_t)’
V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context,
^~~
/home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/v8.h:3597:43: note: candidate expects 2 arguments, 1 provided
../src/BluetoothHciSocket.cpp:275:72: error: no matching function for call to ‘v8::Function::NewInstance(int, v8::Localv8::Value [1])’
Local error = errorConstructor->NewInstance(1, constructorArgs);
^
In file included from /home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/node.h:67,
from /home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/node_buffer.h:25,
from ../src/BluetoothHciSocket.cpp:7:
/home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/v8.h:4318:44: note: candidate: ‘v8::MaybeLocalv8::Object v8::Function::NewInstance(v8::Localv8::Context, int, v8::Localv8::Value) const’
V8_WARN_UNUSED_RESULT MaybeLocal NewInstance(
^~~~~~~~~~~
/home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/v8.h:4318:44: note: candidate expects 3 arguments, 2 provided
/home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/v8.h:4321:44: note: candidate: ‘v8::MaybeLocalv8::Object v8::Function::NewInstance(v8::Localv8::Context) const’
V8_WARN_UNUSED_RESULT MaybeLocal NewInstance(
^~~~~~~~~~~
/home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/v8.h:4321:44: note: candidate expects 1 argument, 2 provided
../src/BluetoothHciSocket.cpp:282:93: warning: ‘v8::Localv8::Value Nan::MakeCallback(v8::Localv8::Object, v8::Localv8::String, int, v8::Localv8::Value’ is deprecated [-Wdeprecated-declarations]
back(Nan::New(this->This), Nan::New("emit").ToLocalChecked(), 2, argv);
^

In file included from ../src/BluetoothHciSocket.cpp:8:
../../../../nan/nan.h:1045:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value MakeCallback(
^~~~~~~~~~~~
../src/BluetoothHciSocket.cpp:282:93: warning: ‘v8::Localv8::Value Nan::MakeCallback(v8::Localv8::Object, v8::Localv8::String, int, v8::Localv8::Value*’ is deprecated [-Wdeprecated-declarations]
back(Nan::New(this->This), Nan::New("emit").ToLocalChecked(), 2, argv);
^

In file included from ../src/BluetoothHciSocket.cpp:8:
../../../../nan/nan.h:1045:46: note: declared here
NAN_DEPRECATED inline v8::Localv8::Value MakeCallback(
^~~~~~~~~~~~
../src/BluetoothHciSocket.cpp: In static member function ‘static Nan::NAN_METHOD_RETURN_TYPE BluetoothHciSocket::BindRaw(Nan::NAN_METHOD_ARGS_TYPE)’:
../src/BluetoothHciSocket.cpp:395:34: error: no matching function for call to ‘v8::Value::IntegerValue()’
devId = arg0->IntegerValue();
^
In file included from /home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/node.h:67,
from /home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/node_buffer.h:25,
from ../src/BluetoothHciSocket.cpp:7:
/home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/v8.h:2774:40: note: candidate: ‘v8::Maybe v8::Value::IntegerValue(v8::Localv8::Context) const’
V8_WARN_UNUSED_RESULT Maybe<int64_t> IntegerValue(
^~~~~~~~~~~~
/home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/v8.h:2774:40: note: candidate expects 1 argument, 0 provided
../src/BluetoothHciSocket.cpp: In static member function ‘static Nan::NAN_METHOD_RETURN_TYPE BluetoothHciSocket::BindUser(Nan::NAN_METHOD_ARGS_TYPE)’:
../src/BluetoothHciSocket.cpp:417:34: error: no matching function for call to ‘v8::Value::IntegerValue()’
devId = arg0->IntegerValue();
^
In file included from /home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/node.h:67,
from /home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/node_buffer.h:25,
from ../src/BluetoothHciSocket.cpp:7:
/home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/v8.h:2774:40: note: candidate: ‘v8::Maybe v8::Value::IntegerValue(v8::Localv8::Context) const’
V8_WARN_UNUSED_RESULT Maybe<int64_t> IntegerValue(
^~~~~~~~~~~~
/home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/v8.h:2774:40: note: candidate expects 1 argument, 0 provided
In file included from /home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/node_buffer.h:25,
from ../src/BluetoothHciSocket.cpp:7:
../src/BluetoothHciSocket.cpp: At global scope:
/home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/node.h:618:43: warning: cast between incompatible function types from ‘void ()(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE)’ {aka ‘void ()(v8::Localv8::Object)’} to ‘node::addon_register_func’ {aka ‘void ()(v8::Localv8::Object, v8::Localv8::Value, void)’} [-Wcast-function-type]
(node::addon_register_func) (regfunc),
^
/home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/.node-gyp/13.9.0/include/node/node.h:652:3: note: in expansion of macro ‘NODE_MODULE_X’
NODE_MODULE_X(modname, regfunc, NULL, 0) // NOLINT (readability/null_usage)
^~~~~~~~~~~~~
../src/BluetoothHciSocket.cpp:499:1: note: in expansion of macro ‘NODE_MODULE’
NODE_MODULE(binding, BluetoothHciSocket::Init);
^~~~~~~~~~~
make: *** [binding.target.mk:109: Release/obj.target/binding/src/BluetoothHciSocket.o] Error 1
make: Leaving directory '/home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack at ChildProcess.emit (events.js:321:20)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Linux 4.19.97-v7l+
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/pi/node_modules/noble-device/node_modules/bluetooth-hci-socket
gyp ERR! node -v v13.9.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok

@abandonware/[email protected] install /home/pi/node_modules/@abandonware/noble
node-gyp rebuild

gyp WARN EACCES current user ("pi") does not have permission to access the dev dir "/root/.cache/node-gyp/13.9.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/pi/node_modules/@abandonware/noble/.node-gyp"
make: Entering directory '/home/pi/node_modules/@abandonware/noble/build'
SOLINK_MODULE(target) Release/obj.target/noble.node
COPY Release/noble.node
make: Leaving directory '/home/pi/node_modules/@abandonware/noble/build'
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/xpc-connection):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"arm"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/noble-device/node_modules/bluetooth-hci-socket):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: node-gyp rebuild
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

2 packages are looking for funding
run npm fund for details

found 2 low severity vulnerabilities
run npm audit fix to fix them, or npm audit for details

Any help would be appreciated.

BLE IDs differ between OSX and Linux (Linux is correct)

Hi,
I'm a bit of a node.js newbie, so this bug report isn't directly on noble (but with a bit of guidance, I can get a more clear log). I'm using https://github.com/mKeRix/room-assistant on a raspberry pi and on my MacBook (running Mojave), and I get different IDs for my devices (Mi Band 4s and an Amazfit watch). On Linux, I get the proper IDs, however, on Mac, I get:

[Nest] 19083   - 03/07/2020, 12:17:48 PM   [BluetoothLowEnergyService] Discovered new BLE peripheral 5015698a79934f2299c1089292f58244 with ID 5015698a79934f2299c1089292f58244 and RSSI -71
[Nest] 19083   - 03/07/2020, 12:17:52 PM   [BluetoothLowEnergyService] Discovered new BLE peripheral 5deeee38f55d4b6ea55f2fa18950651c with ID 5deeee38f55d4b6ea55f2fa18950651c and RSSI -53
[Nest] 19083   - 03/07/2020, 12:17:53 PM   [BluetoothLowEnergyService] Discovered new BLE peripheral dc2c15ea9978499d87cc9e18b27f6cd4 with ID dc2c15ea9978499d87cc9e18b27f6cd4 and RSSI -82
[Nest] 19083   - 03/07/2020, 12:18:02 PM   [BluetoothLowEnergyService] Discovered new BLE peripheral 0e6c3f100ea940aaa3ee0cedcc4531bb with ID 0e6c3f100ea940aaa3ee0cedcc4531bb and RSSI -80
[Nest] 19083   - 03/07/2020, 12:18:22 PM   [BluetoothLowEnergyService] Discovered new BLE peripheral a70d4e932254439093ba5298a73ede4b with ID a70d4e932254439093ba5298a73ede4b and RSSI -54

(These are the names if found and the values of Peripheral.name and Peripheral.id. I'm not sure what the convention is here, but it's clearly too long to be a MAC address.

Under Linux, these 5 devices are correctly identified as

Mar 01 16:03:01 raspberrypi room-assistant[25952]: [Nest] 25952   - 03/01/2020, 4:03:01 PM   [BluetoothLowEnergyService] Discovered new BLE peripheral Mi Smart Band 4 with ID f66233931936 and RSSI -88
Mar 01 17:26:53 raspberrypi room-assistant[25952]: [Nest] 25952   - 03/01/2020, 5:26:53 PM   [BluetoothLowEnergyService] Discovered new BLE peripheral Mi Smart Band 4 with ID e9b8fb1b6f63 and RSSI -87
Mar 01 17:48:11 raspberrypi room-assistant[25952]: [Nest] 25952   - 03/01/2020, 5:48:11 PM   [BluetoothLowEnergyService] Discovered new BLE peripheral Mi Smart Band 4 with ID d11b4424249b and RSSI -85
Mar 01 19:59:47 raspberrypi room-assistant[25952]: [Nest] 25952   - 03/01/2020, 7:59:47 PM   [BluetoothLowEnergyService] Discovered new BLE peripheral Mi Smart Band 4 with ID dd10a5420752 and RSSI -89
Mar 05 16:49:22 raspberrypi room-assistant[21185]: [Nest] 21185   - 03/05/2020, 4:49:22 PM   [BluetoothLowEnergyService] Discovered new BLE peripheral Amazfit Bip Watch with ID dce807d7d0e6 and RSSI -81

I'm not 100% sure which map to which.

Any ideas? I'd be happy to reproduce this with just noble if someone can give me a snippet that I an just to just do a scan and print the IDs and Names found.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.