Giter Site home page Giter Site logo

abandonware / bleno Goto Github PK

View Code? Open in Web Editor NEW

This project forked from noble/bleno

146.0 146.0 50.0 653 KB

A Node.js module for implementing BLE (Bluetooth Low Energy) peripherals

Home Page: https://mastodon.social/@rzr/106068437787315146#bleno

License: MIT License

JavaScript 65.96% Python 0.73% Objective-C 5.10% Objective-C++ 26.57% C++ 1.64%
bluetooth

bleno's People

Contributors

apollon77 avatar beaufortfrancois avatar bradfol avatar ceckerle avatar cheesebaron avatar derhuerst avatar don avatar dragom avatar gfwilliams avatar guimier avatar hashok avatar jacobrosenthal avatar jason-cooke avatar jonathanwiesel avatar leahjessie avatar malikolivier avatar mnkhouri avatar mploch-sonavation avatar petersaints avatar pfafman avatar programmarchy avatar ptx2 avatar raspelikan avatar robertchiras avatar rzr avatar sandeepmistry avatar spinogrizz avatar suppsandrob avatar valpackett avatar vdharmon 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

bleno's Issues

TypeError: Cannot read property 'length' of undefined in smp.js

Hello,

I'm running the latest version of the bleno package and when I'm trying to swtich from a paried phone to another phone i get this error:

/home/pi/NodeBLETest/node_modules/@abandonware/bleno/lib/hci-socket/crypto.js:60
var output = new Buffer(input.length);
^

TypeError: Cannot read property 'length' of undefined
at swap (/home/pi/NodeBLETest/node_modules/@abandonware/bleno/lib/hci-socket/crypto.js:60:33)
at e (/home/pi/NodeBLETest/node_modules/@abandonware/bleno/lib/hci-socket/crypto.js:37:9)
at Object.c1 (/home/pi/NodeBLETest/node_modules/@abandonware/bleno/lib/hci-socket/crypto.js:22:9)
at Smp.handlePairingRandom (/home/pi/NodeBLETest/node_modules/@abandonware/bleno/lib/hci-socket/smp.js:130:12)
at Smp.onAclStreamData (/home/pi/NodeBLETest/node_modules/@abandonware/bleno/lib/hci-socket/smp.js:58:10)
at AclStream.emit (events.js:327:22)
at AclStream.push (/home/pi/NodeBLETest/node_modules/@abandonware/bleno/lib/hci-socket/acl-stream.js:26:10)
at BlenoBindings.onAclDataPkt (/home/pi/NodeBLETest/node_modules/@abandonware/bleno/lib/hci-socket/bindings.js:194:21)
at Hci.emit (events.js:315:20)
at Hci.onSocketData (/home/pi/NodeBLETest/node_modules/@abandonware/bleno/lib/hci-socket/hci.js:588:14)

Is there a way to bypass the pairing itself or the code that causes this issue?

The code runs on an RPi 4

Thanks!

Bluetooth seems not to work

Hello I get in log the error

Nov 13 23:39:45 moonbike systemd[1]: Stopped kettler.service.
Nov 13 23:39:45 moonbike systemd[1]: Started kettler.service.
Nov 13 23:39:49 moonbike Kettler[17785]: module.js:549
Nov 13 23:39:49 moonbike Kettler[17785]: throw err;
Nov 13 23:39:49 moonbike Kettler[17785]: ^
Nov 13 23:39:49 moonbike Kettler[17785]: Error: Cannot find module '@abandonware/bleno'
Nov 13 23:39:49 moonbike Kettler[17785]: at Function.Module._resolveFilename (module.js:547:15)
Nov 13 23:39:49 moonbike Kettler[17785]: at Function.Module._load (module.js:474:25)
Nov 13 23:39:49 moonbike Kettler[17785]: at Module.require (module.js:596:17)
Nov 13 23:39:49 moonbike Kettler[17785]: at require (internal/module.js:11:18)
Nov 13 23:39:49 moonbike Kettler[17785]: at Object. (/home/pi/KettlerUSB/BLE/kettlerBLE.js:1:77)
Nov 13 23:39:49 moonbike Kettler[17785]: at Module._compile (module.js:652:30)
Nov 13 23:39:49 moonbike Kettler[17785]: at Object.Module._extensions..js (module.js:663:10)
Nov 13 23:39:49 moonbike Kettler[17785]: at Module.load (module.js:565:32)
Nov 13 23:39:49 moonbike Kettler[17785]: at tryModuleLoad (module.js:505:12)
Nov 13 23:39:49 moonbike Kettler[17785]: at Function.Module._load (module.js:497:3)
Nov 13 23:39:49 moonbike systemd[1]: kettler.service: Main process exited, code=exited, status=1/FAILURE
Nov 13 23:39:49 moonbike systemd[1]: kettler.service: Failed with result 'exit-code'.
Nov 13 23:39:49 moonbike systemd[1]: kettler.service: Service RestartSec=100ms expired, scheduling restart.
Nov 13 23:39:49 moonbike systemd[1]: kettler.service: Scheduled restart job, restart counter is at 104.
Nov 13 23:39:49 moonbike systemd[1]: Stopped kettler.service.
Nov 13 23:39:49 moonbike systemd[1]: Started kettler.service.

Disconnecting a peripheral in a multi-role scenario also disconnects bleno from central

I start a bleno peripheral and connect to it. I use noble to connect to another peripheral. Once I disconnect the other peripheral, the disconnect event is also processed by bleno and the central connection is lost.

In noble mutli role scenarios are explicitly supported:
abandonware/noble@60fa47e

Bleno does not check whether the disconnect event is sent by the connected central:
https://github.com/abandonware/bleno/blob/master/lib/hci-socket/hci.js#L493

I will create a pull request for this.

[email protected] is broken

Hello,

Over the last few days we experienced an issue causing bleno to only show advertisement data
with no access to services when deployed on a RPI3.
It would even make remote apps like Lightblue randomly crash on connection.

in this capture there are supposed to be two services with many characteristics available
screenshot

After a few (okay, a lot) investigations, we found out that bluetooth-hci-socket's version in the dependencies is not pinned to a specific revision causing it to be updated when the dependency is updated.

It appears that @abandonware/[email protected] is broken (see: abandonware/node-bluetooth-hci-socket#31 ) and forcing @abandonware/[email protected] solved the issue.

Would it be possible put a warning in the README and to either lock the optional dependency's version in the package.json or move it to a peerDependency so that people can choose the revision they install ? (I can take care of the PR if needed).

Thanks !

[question] Is it possible to set the mac address?

I am trying to emulate my nRF52, being connected to my iPhone.
The iPhone remembers the HEX mac-address that was connected, and is able to connect when the screen is off.
However, with this, each time I restart the application, I get a new/random MAC address.

So, is there anyway to specify a specific MAC address for bleno?

[Question] How to send more than 1 response to a single write request?

I'm trying to implement a simulator that mimics a physical device that uses BLE to transmit messages. Whenever it receives a write request, it'll send an initial response (0xFFFF...), then the actual response (0x7F1002...). However, I'm only able to send 1 response with my Bleno implementation currently. How can I implement it to send both?

Further, if I need to send a response with more than 20 bytes, how can I do so with Bleno? I've gone through the examples, but not quite sure what I should be looking for.

Disconnecting instantly after sucessful connection

Currently running dietpi.

Everything works, except when I try to connect; It works for ~3s and disconnects.
Btmon shows this as a Remote User Terminated Connection

Any idea how I can find out what is giving this disconnect request?

Logs are running the echo example.

Bleno Debug=* enviroment dump
https://pastebin.com/PiMkBNH8

btmon dump
https://pastebin.com/EUnikR9E

Any help would be greatly appreciated, been at a loss for a very long time now, and it seems google does not contain any solutions.

pairing failed: lib/hci-socket/crypto.js:60 TypeError: Cannot read property 'length' of undefined

I am trying to run the echo example with the latest version of bleno, but when I attempt to pair it crashes:

node echo/main.js
bleno - echo
on -> stateChange: poweredOn
on -> advertisingStart: success
(node:3716) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
/home/dev/ble-light-js/node_modules/bleno/lib/hci-socket/crypto.js:60
  var output = new Buffer(input.length);
                                ^

TypeError: Cannot read property 'length' of undefined
    at swap (/home/dev/ble-light-js/node_modules/bleno/lib/hci-socket/crypto.js:60:33)
    at e (/home/dev/ble-light-js/node_modules/bleno/lib/hci-socket/crypto.js:37:9)
    at Object.c1 (/home/dev/ble-light-js/node_modules/bleno/lib/hci-socket/crypto.js:22:9)
    at Smp.handlePairingRandom (/home/dev/ble-light-js/node_modules/bleno/lib/hci-socket/smp.js:130:12)
    at Smp.onAclStreamData (/home/dev/ble-light-js/node_modules/bleno/lib/hci-socket/smp.js:58:10)
    at AclStream.emit (events.js:327:22)
    at AclStream.push (/home/dev/ble-light-js/node_modules/bleno/lib/hci-socket/acl-stream.js:26:10)
    at BlenoBindings.onAclDataPkt (/home/dev/ble-light-js/node_modules/bleno/lib/hci-socket/bindings.js:194:21)
    at Hci.emit (events.js:315:20)
    at Hci.onSocketData (/home/dev/ble-light-js/node_modules/bleno/lib/hci-socket/hci.js:595:14)

Requesting access to contact list

Hi all,

My car usually asks if it can access my contact list.
Can I implement something simimlar using this library?

Kind regards,

Lesley

Can't bond to bleno on Raspberry Pi

Is it possible to do pairing/bonding with this bleno fork? I found that there are "secure" properties for characteristics. But whenever my android phone tries to bond with bleno running on my raspis (I tried the RPi 3B+, as well as RPi 4) nothing happens and the connection ends after a few seconds.

I have checked using a BLE Fitness Tracker that the phone is able to bond to BLE devices in principle.

Using the current stable Raspian with bluetooth bluez libbluetooth-dev libudev-dev installed as per the readme.
Bluetoothd is disables, though I did test with enabled, too, but didn't find any difference regarding the issue.

Using non-secure writes/reads on characteristics works fine with bleno.

cat yarn.lock | grep bleno
"@abandonware/bleno@^0.5.1-2":
  resolved "https://registry.yarnpkg.com/@abandonware/bleno/-/bleno-0.5.1-2.tgz#b381c33bc1e4c5eb5d945f413db8a98e5818f3b9"
apt list | grep blue
bluealsa-dbgsym/testing 0.13 armhf
bluealsa/testing 0.13 armhf
bluebird-gtk-theme/stable 1.3-1 all
bluedevil/stable 4:5.14.5-1 armhf
bluefish-data/stable 2.2.10-1 all
bluefish-plugins/stable 2.2.10-1+b11 armhf
bluefish/stable 2.2.10-1+b11 armhf
bluej/testing 4.2.1 all
blueman/stable 2.0.8-1+b2 armhf
bluemindo/stable 0.3-4.1 all
bluemon/stable 1.4-7+b4 armhf
blueproximity/stable 1.2.5-6 all
bluetooth/testing,now 5.50-1.2~deb10u1+rpt2 all  [installiert]
bluewho/stable 0.1-2 all
bluez-cups-dbgsym/testing 5.50-1.2~deb10u1+rpt2 armhf
bluez-cups/testing 5.50-1.2~deb10u1+rpt2 armhf
bluez-dbgsym/testing 5.50-1.2~deb10u1+rpt2 armhf
bluez-firmware/testing 1.2-4+rpt5 all [aktualisierbar von: 1.2-4+rpt4]
bluez-hcidump-dbgsym/testing 5.50-1.2~deb10u1+rpt2 armhf
bluez-hcidump/testing 5.50-1.2~deb10u1+rpt2 armhf
bluez-obexd-dbgsym/testing 5.50-1.2~deb10u1+rpt2 armhf
bluez-obexd/testing 5.50-1.2~deb10u1+rpt2 armhf
bluez-test-scripts/testing 5.50-1.2~deb10u1+rpt2 all
bluez-test-tools-dbgsym/testing 5.50-1.2~deb10u1+rpt2 armhf
bluez-test-tools/testing 5.50-1.2~deb10u1+rpt2 armhf
bluez-tools/stable 2.0~20170911.0.7cb788c-2 armhf
bluez/testing,now 5.50-1.2~deb10u1+rpt2 armhf  [installiert]
compass-blueprint-plugin/stable 1.0.0-3 all
gir1.2-gnomebluetooth-1.0/stable 3.28.2-4~deb10u1 armhf
gnome-bluetooth/stable 3.28.2-4~deb10u1 armhf
golang-github-bluebreezecf-opentsdb-goclient-dev/stable 0.0~git20160515.0.539764b-1 all
golang-github-microcosm-cc-bluemonday-dev/stable 0.0~git20161202.0.e797637-1.1 all
jquery-jplayer-bluemonday/stable 2.7.0-1 all
libbluedevil-dev/stable 2.0~rc1-6-g7bb223c-3 armhf
libbluedevil2/stable 2.0~rc1-6-g7bb223c-3 armhf
libbluetooth-dev/testing,now 5.50-1.2~deb10u1+rpt2 armhf  [installiert]
libbluetooth3-dbgsym/testing 5.50-1.2~deb10u1+rpt2 armhf
libbluetooth3/testing,now 5.50-1.2~deb10u1+rpt2 armhf  [Installiert,automatisch]
libgnome-bluetooth-dev/stable 3.28.2-4~deb10u1 armhf
libgnome-bluetooth13/stable 3.28.2-4~deb10u1 armhf
libkf5bluezqt-data/stable 5.54.0-1 all
libkf5bluezqt-dev/stable 5.54.0-1 armhf
libkf5bluezqt-doc/stable 5.54.0-1 all
libkf5bluezqt6/stable 5.54.0-1 armhf
libnet-bluetooth-perl/stable 0.41-2+b2 armhf
libpam-blue/stable 0.9.0-3+b4 armhf
libqt5bluetooth5-bin/stable 5.11.3-2 armhf
libqt5bluetooth5/stable 5.11.3-2 armhf
libspa-bluetooth/stable 0.2.5-1 armhf
lxplug-bluetooth-dbgsym/testing 0.16 armhf
lxplug-bluetooth/testing 0.16 armhf
mplayer-skin-blue/stable 1.11-2 all
node-babel-plugin-transform-async-to-bluebird/stable 1.1.1-2 all
node-bluebird/stable 3.5.1+dfsg2-2 all
pi-bluetooth/testing,now 0.1.15 all  [installiert]
pulseaudio-module-bluetooth/stable 12.2-4+deb10u1 armhf
python-bluez/stable 0.22+really0.22-1 armhf
python-lightblue/stable 0.3.2-5 armhf
python3-bluez/stable 0.22+really0.22-1 armhf
qml-module-org-kde-bluezqt/stable 5.54.0-1 armhf
qml-module-qtbluetooth/stable 5.11.3-2 armhf
ruby-bluefeather/stable 0.41-5 all
ruby-rails-assets-blueimp-gallery/stable 2.33.0-1 all

support bluetooth 5

hi, did this library support bluetooth 5 with laptop ?
if so, how?
tnxxxx

App crash when force quit app on macOS for subscribing on 'stateChange' event

I have used abandonware/bleno in my electron app. Every time I right click on the app and click quit option, app is crashing.
ble-crash.txt

To investigate this, I have removed stateChange event subscription and app is no more crashing.

My code to subscribe on stateChange event is bleno.on('stateChange', (state) => { console.log('ble state changed to:', state); });

When I removed this portion, the app is no more crashing. But then another issue occurs: ble state never changes from unknown, the state remains unknown always. That's why I can't do anything with ble.

macOS: Disable NSLog to avoid flooding console

Hi,

Thank you for maintaining this library,

When running a bleno-powered application on macOS, the console currently gets flooded with a large amount of output from the native library, like so:

2023-05-10 09:22:38.983 Electron[15846:644204] BlenoMac::SetServices
2023-05-10 09:22:38.983 Electron[15846:644204] napiArrayToCBMutableServices
2023-05-10 09:22:38.983 Electron[15846:644204] napiToCBMutableService
2023-05-10 09:22:38.983 Electron[15846:644204] napiArrayToCBMutableService: uuid:13333333-3333-3333-3333-333333333337
2023-05-10 09:22:38.983 Electron[15846:644204] napiArrayToCBMutableCharacteristics
2023-05-10 09:22:38.983 Electron[15846:644204] napiToCBMutableCharacteristic
2023-05-10 09:22:38.983 Electron[15846:644204] napiToCBMutableCharacteristic: cUUID:13333333-3333-3333-3333-333333333338
2023-05-10 09:22:38.983 Electron[15846:644204] napiToCBMutableCharacteristic: value:(null)
2023-05-10 09:22:38.983 Electron[15846:644204] napiToCBCharacteristicProperties
2023-05-10 09:22:38.983 Electron[15846:644204] napiToCBAttributePermissions
2023-05-10 09:22:38.983 Electron[15846:644204] napiArrayToCBDescriptors
2023-05-10 09:22:38.983 Electron[15846:644204] napiToCBMutableCharacteristic
2023-05-10 09:22:38.983 Electron[15846:644204] napiToCBMutableCharacteristic: cUUID:13333333-3333-3333-3333-333333333339
2023-05-10 09:22:38.983 Electron[15846:644204] napiToCBMutableCharacteristic: value:(null)
2023-05-10 09:22:38.983 Electron[15846:644204] napiToCBCharacteristicProperties
2023-05-10 09:22:38.983 Electron[15846:644204] napiToCBAttributePermissions
2023-05-10 09:22:38.983 Electron[15846:644204] napiArrayToCBDescriptors
2023-05-10 09:22:38.983 Electron[15846:644204] napiArrayToUUIDEmitters

The amount of output is so large and so frequent that it essentially renders the console unusable for anything else. How can I disable this output?

Sincerely,

a different Node.js version using

my node v18.18.0
when run the node code , there is a error below in console:

Error: The module '/home/pi/raspi/bleno-starter/node_modules/@abandonware/bluetooth-hci-socket/build/Release/bluetooth_hci_socket.node'
was compiled against a different Node.js version using

Hidden build dependency on Python 2

A dependency of this project (xpc-connect) seems to be dependent on Python 2 to build, which is a problem on macOS now that Python isn't bundled with the OS anymore. This is in no way bleno's problem, but it would be helpful to add it to the Mac installation instructions.

It works for me when Python 2 is installed with pyenv and either python or python2 points to it. Also possible that upgrading the xpc-connect dependency might solve the problem, as it has a recent commit related to Mac versions (though not obviously having anything to do with Python).

With only Python 3 installed, npm install produces the following.

Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: ...
Output:
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | darwin | x64
gyp ERR! configure error
gyp ERR! stack Error: Command failed: /Users/xxx/.pyenv/shims/python -c import sys; print \"%s.%s.%s\" % sys.version_info[:3];
gyp ERR! stack   File \"<string>\", line 1
gyp ERR! stack     import sys; print \"%s.%s.%s\" % sys.version_info[:3];
gyp ERR! stack                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gyp ERR! stack SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
gyp ERR! stack
gyp ERR! stack     at ChildProcess.exithandler (node:child_process:389:12)
gyp ERR! stack     at ChildProcess.emit (node:events:537:28)
gyp ERR! stack     at maybeClose (node:internal/child_process:1091:16)
gyp ERR! stack     at Socket.<anonymous> (node:internal/child_process:449:11)
gyp ERR! stack     at Socket.emit (node:events:537:28)
gyp ERR! stack     at Pipe.<anonymous> (node:net:747:14)
gyp ERR! System Darwin 21.5.0

Documentation Update

Not sure if you really want me to create a pull request, but on the Events for Disconnect you have.

Disconnect
bleno.on('disconnect', callback(clientAddress)); // Linux only

However disconnect did fire for me just fine on Windows.

Pairing error: crypto.js:60: TypeError: Cannot read property 'length' of undefined

I am trying to run the echo example with the latest version of bleno, but when I attempt to pair it crashes:

node echo/main.js
bleno - echo
on -> stateChange: poweredOn
on -> advertisingStart: success
(node:3716) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
/home/dev/ble-light-js/node_modules/bleno/lib/hci-socket/crypto.js:60
  var output = new Buffer(input.length);
                                ^

TypeError: Cannot read property 'length' of undefined
    at swap (/home/dev/ble-light-js/node_modules/bleno/lib/hci-socket/crypto.js:60:33)
    at e (/home/dev/ble-light-js/node_modules/bleno/lib/hci-socket/crypto.js:37:9)
    at Object.c1 (/home/dev/ble-light-js/node_modules/bleno/lib/hci-socket/crypto.js:22:9)
    at Smp.handlePairingRandom (/home/dev/ble-light-js/node_modules/bleno/lib/hci-socket/smp.js:130:12)
    at Smp.onAclStreamData (/home/dev/ble-light-js/node_modules/bleno/lib/hci-socket/smp.js:58:10)
    at AclStream.emit (events.js:327:22)
    at AclStream.push (/home/dev/ble-light-js/node_modules/bleno/lib/hci-socket/acl-stream.js:26:10)
    at BlenoBindings.onAclDataPkt (/home/dev/ble-light-js/node_modules/bleno/lib/hci-socket/bindings.js:194:21)
    at Hci.emit (events.js:315:20)
    at Hci.onSocketData (/home/dev/ble-light-js/node_modules/bleno/lib/hci-socket/hci.js:595:14)

bleno 0.5.1-3
nodejs v14.15.0
Linux 5.4.72 armv7l

Data loss on 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 with me.
Do you have any suggestions?

startAdvertising fails with "Command Disallowed"

I am trying to test bleno on my laptop running Ubuntu 20.04, but bleno.startAdvertising is failing with the following error:

Error: Command Disallowed
    at Gap.onHciLeAdvertiseEnableSet (/home/brendan/standardbots/botman/node_modules/@abandonware/bleno/lib/hci-socket/gap.js:201:15)
    at Hci.emit (events.js:198:13)
    at Hci.processCmdCompleteEvent (/home/brendan/standardbots/botman/node_modules/@abandonware/bleno/lib/hci-socket/hci.js:669:10)
    at Hci.onSocketData (/home/brendan/standardbots/botman/node_modules/@abandonware/bleno/lib/hci-socket/hci.js:540:12)
    at BluetoothHciSocket.emit (events.js:198:13)

I have disabled bluetoothd and enabled hci0 per the README instructions, and I've also run the setcap command as well.

The code is the following:

async function establishConnection(): Promise<void> {
  console.log('Establishing connection');

  await new Promise<void>((resolve, reject) => {
    const serviceUuid = '...';  // Omitted.
    bleno.on('advertisingStart', (err) => {
      if (err) {
        reject(err);  // <-- "Command Disallowed" error throwing here.
        return;
      }

      console.log('Advertising Bluetooth service');
      bleno.setServices(...);  // Omitted.
    });

    bleno.on('accept', (clientAddress: string) => {
      console.log(`Accepted connection from ${clientAddress}`);
      bleno.stopAdvertising();
    });

    bleno.on('stateChange', (state) => {
      if (state === 'poweredOn') {
        bleno.startAdvertising('service', [serviceUuid]);                                                                                                                         
      }
    });
  });
}

hcidump shows the following output:

$ sudo hcidump -t -x                                                                                                                                                                   
HCI sniffer - Bluetooth packet analyzer ver 5.53                                                                                                                                       
device: hci0 snap_len: 1500 filter: 0xffffffffffffffff                                                                                                                                 
2020-10-18 18:46:35.024528 < HCI Command: Set Event Mask (0x03|0x0001) plen 8                                                                                                          
    Mask: 0xfffffbff07f8bf3d                                                                                                                                                           
2020-10-18 18:46:35.140118 > HCI Event: Command Complete (0x0e) plen 4                                                                                                                 
    Set Event Mask (0x03|0x0001) ncmd 1                                                                                                                                                
    status 0x00                                                                                                                                                                        
2020-10-18 18:46:35.140217 < HCI Command: LE Set Event Mask (0x08|0x0001) plen 8                                                                                                       
    mask 0x1f00000000000000 (Reserved)                                                                                                                                                 
2020-10-18 18:46:35.141102 > HCI Event: Command Complete (0x0e) plen 4                                                                                                                 
    LE Set Event Mask (0x08|0x0001) ncmd 1                                                                                                                                             
    status 0x00                                                                                                                                                                        
2020-10-18 18:46:35.141187 < HCI Command: Read Local Version Information (0x04|0x0001) plen 0                                                                                          
2020-10-18 18:46:35.142105 > HCI Event: Command Complete (0x0e) plen 12                                                                                                                
    Read Local Version Information (0x04|0x0001) ncmd 1                                                                                                                                
    status 0x00                                                                                                                                                                        
    HCI Version: 5.1 (0xa) HCI Revision: 0x100                                                                                                                                         
    LMP Version: 5.1 (0xa) LMP Subversion: 0x100                                                                                                                                       
    Manufacturer: Intel Corp. (2)                                                                                                                                                      
2020-10-18 18:46:35.142186 < HCI Command: Write LE Host Supported (0x03|0x006d) plen 2                                                                                                 
  01 00                                                                                                                                                                                
2020-10-18 18:46:35.143100 > HCI Event: Command Complete (0x0e) plen 4                                                                                                                 
    Write LE Host Supported (0x03|0x006d) ncmd 1                                                                                                                                       
    00                                                                                                                                                                                 
2020-10-18 18:46:35.143181 < HCI Command: Read LE Host Supported (0x03|0x006c) plen 0                                                                                                  
2020-10-18 18:46:35.144102 > HCI Event: Command Complete (0x0e) plen 6                                                                                                                 
    Read LE Host Supported (0x03|0x006c) ncmd 1                                                                                                                                        
    00 01 00                                                                                                                                                                           
2020-10-18 18:46:35.144182 < HCI Command: Read BD ADDR (0x04|0x0009) plen 0                                                                                                            
2020-10-18 18:46:35.145104 > HCI Event: Command Complete (0x0e) plen 10                                                                                                                
    Read BD ADDR (0x04|0x0009) ncmd 1                                                                                                                                                  
    status 0x00 bdaddr 40:EC:99:BB:5E:94                                                                                                                                               
2020-10-18 18:46:35.145192 < HCI Command: LE Read Buffer Size (0x08|0x0002) plen 0                                                                                                     
2020-10-18 18:46:35.146101 > HCI Event: Command Complete (0x0e) plen 7                                                                                                                 
    LE Read Buffer Size (0x08|0x0002) ncmd 1                                                                                                                                           
    status 0x00 pktlen 0x00fb maxpkt 0x03                                                                                                                                              
2020-10-18 18:46:35.146181 < HCI Command: LE Set Advertise Enable (0x08|0x000a) plen 1                                                                                                 
  00                                                                                                                                                                                   
2020-10-18 18:46:35.147117 > HCI Event: Command Complete (0x0e) plen 4                                                                                                                 
    LE Set Advertise Enable (0x08|0x000a) ncmd 1                                                                                                                                       
    status 0x0c                                                                                                                                                                        
    Error: Command Disallowed                                                                                                                                                          
2020-10-18 18:46:35.147200 < HCI Command: LE Set Advertising Parameters (0x08|0x0006) plen 15                                                                                          
    min 100.000ms, max 100.000ms                                                                                                                                                       
    type 0x00 (ADV_IND - Connectable undirected advertising) ownbdaddr 0x00 (Public)                                                                                                   
    directbdaddr 0x00 (Public) 00:00:00:00:00:00                                                                                                                                       
    channelmap 0x07 filterpolicy 0x00 (Allow scan from any, connection from any)                                                                                                       
2020-10-18 18:46:35.148119 > HCI Event: Command Complete (0x0e) plen 4                                                                                                                 
    LE Set Advertising Parameters (0x08|0x0006) ncmd 1
    status 0x0c
    Error: Command Disallowed
2020-10-18 18:46:35.150862 < HCI Command: LE Set Scan Response Data (0x08|0x0009) plen 32
  08 07 08 62 6F 74 6D 61 6E 00 00 00 00 00 00 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 
2020-10-18 18:46:35.152224 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Response Data (0x08|0x0009) ncmd 1
    status 0x0c
    Error: Command Disallowed
2020-10-18 18:46:35.152327 < HCI Command: LE Set Advertising Data (0x08|0x0008) plen 32
  15 02 01 06 11 06 A6 7B 45 BE 57 04 FB A3 CE 4C BD 31 14 69 
  0D D7 00 00 00 00 00 00 00 00 00 00 
2020-10-18 18:46:35.153178 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Advertising Data (0x08|0x0008) ncmd 1
    status 0x0c
    Error: Command Disallowed
2020-10-18 18:46:35.153274 < HCI Command: LE Set Advertise Enable (0x08|0x000a) plen 1
  01 
2020-10-18 18:46:35.154178 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Advertise Enable (0x08|0x000a) ncmd 1
    status 0x0c
    Error: Command Disallowed
2020-10-18 18:46:35.154277 < HCI Command: LE Set Scan Response Data (0x08|0x0009) plen 32
  08 07 08 62 6F 74 6D 61 6E 00 00 00 00 00 00 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 
2020-10-18 18:46:35.155102 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Response Data (0x08|0x0009) ncmd 1
    status 0x0c
    Error: Command Disallowed
2020-10-18 18:46:35.155183 < HCI Command: LE Set Advertising Data (0x08|0x0008) plen 32
  15 02 01 06 11 06 A6 7B 45 BE 57 04 FB A3 CE 4C BD 31 14 69 
  0D D7 00 00 00 00 00 00 00 00 00 00 
2020-10-18 18:46:35.156101 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Advertising Data (0x08|0x0008) ncmd 1
    status 0x0c
    Error: Command Disallowed
2020-10-18 18:46:35.158694 < HCI Command: LE Set Advertise Enable (0x08|0x000a) plen 1
  00 
2020-10-18 18:46:35.159096 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Advertise Enable (0x08|0x000a) ncmd 1
    status 0x0c
    Error: Command Disallowed

I've also tried directly starting advertising with hciconfig but that fails with the same error:

$ sudo hciconfig hci0 leadv
LE set advertise enable on hci0 returned status 12

I saw other suggestions to try the following sequence of commands:

$ sudo hciconfig hci0 down
$ sudo hciconfig hci0 up
$ sudo hciconfig hci0 noscan
$ sudo hciconfig hci0 noleadv
$ sudo hciconfig hci0 leadv

But the noleadv and leadv commands both failed with the same error as above. sudo hciconfig hci0 leadv 3 also failed with the same error.

Does anyone have suggestions on how to further debug these issues?

Connect and immediate disconnect

Hi
I have installed bleno on a Vmware VM (running W10 11/2019 update), and run battery profile example. The BT device (BCM20702A0) is connected to the VM (with right WinUSB driver).
I have installed the same on another VM running Ubuntu 16 LTM, following the instructions.
I have used 3 different BT Scanner (on Android 10) : Renesas GattBrowser, Nordic nRfConnect, BLE Scanner. The BLE device is identified sometimes (frequently a rescan is needed), and when it is, connecting, dumping a log on noble console, I can see connect and immediate disconnect.

Thanks for any update/suggestion
Available for supporting and on providing further info
Thanks
Lorenzo

Crash, when unsubscribing from the default Generic Attribute 0x1801 primary service

When I subscribe to the Generic Attribute 0x1801 primary service and then unsubscribe again (i.e. using nRF Connect), then an error is thrown and the application exits.

From what I see there has already been a fix proposed here: #2, but somehow it did not make it into the code base.

node_modules/@abandonware/bleno/lib/hci-socket/gatt.js:914
            handleAttribute.emit('unsubscribe');
                            ^

TypeError: handleAttribute.emit is not a function
    at Gatt.handleWriteRequestOrCommand (node_modules/@abandonware/bleno/lib/hci-socket/gatt.js:914:29)
    at Gatt.handleRequest (node_modules/@abandonware/bleno/lib/hci-socket/gatt.js:344:23)
    at Gatt.onAclStreamData (node_modules/@abandonware/bleno/lib/hci-socket/gatt.js:274:8)
    at AclStream.emit (events.js:327:22)
    at AclStream.push (node_modules/@abandonware/bleno/lib/hci-socket/acl-stream.js:26:10)
    at BlenoBindings.onAclDataPkt (node_modules/@abandonware/bleno/lib/hci-socket/bindings.js:194:21)
    at Hci.emit (events.js:315:20)
    at Hci.onSocketData (node_modules/@abandonware/bleno/lib/hci-socket/hci.js:595:14)
    at BluetoothHciSocket.emit (events.js:315:20)

Cannot find module 'node-pre-gyp'

Thank you so much for the amazing work!

I was able to use this locally on my Mac. However, when running on Linux arm64, node v15.4.0, I get the following:

 error: uncaughtException: Cannot find module 'node-pre-gyp'
25.01.21 08:27:25 (-0700)  api  Require stack:
25.01.21 08:27:25 (-0700)  api  - /usr/src/app/node_modules/@abandonware/bluetooth-hci-socket/lib/native.js
25.01.21 08:27:25 (-0700)  api  - /usr/src/app/node_modules/@abandonware/bluetooth-hci-socket/index.js
25.01.21 08:27:25 (-0700)  api  - /usr/src/app/node_modules/@abandonware/bleno/lib/hci-socket/mgmt.js
25.01.21 08:27:25 (-0700)  api  - /usr/src/app/node_modules/@abandonware/bleno/lib/hci-socket/smp.js
25.01.21 08:27:25 (-0700)  api  - /usr/src/app/node_modules/@abandonware/bleno/lib/hci-socket/acl-stream.js
25.01.21 08:27:25 (-0700)  api  - /usr/src/app/node_modules/@abandonware/bleno/lib/hci-socket/bindings.js
25.01.21 08:27:25 (-0700)  api  - /usr/src/app/node_modules/@abandonware/bleno/lib/bleno.js
25.01.21 08:27:25 (-0700)  api  - /usr/src/app/node_modules/@abandonware/bleno/index.js
25.01.21 08:27:25 (-0700)  api  - /usr/src/app/dist/ble/index.js
25.01.21 08:27:25 (-0700)  api  - /usr/src/app/dist/index.js

I also tried it on node 12 and 14 while getting the same error.

I also tried upgrading to the latest node-pre-gyp (v0.17.0, v1.0.0-alpha1 and alpha2). Issue reported here.

Any help is appreciated. Thank you in advance ๐Ÿ™

TypeError: Cannot read property 'toString' of undefined

I receive the following crash.

/node_modules/@abandonware/bleno/lib/hci-socket/hci.js:476
debug('write acl data pkt frag ' + pkt.fragId + ' handle ' + pkt.handle + ' - writing: ' + pkt.pkt.toString('hex'));
^

TypeError: Cannot read property 'toString' of undefined
at Hci.writeOneAclDataPkt (/node_modules/@abandonware/bleno/lib/hci-socket/hci.js:476:102)
at Hci.pushAclOutQueue (/node_modules/@abandonware/bleno/lib/hci-socket/hci.js:463:10)
at Hci.onSocketData (/node_modules/@abandonware/bleno/lib/hci-socket/hci.js:526:12)
at BluetoothHciSocket.emit (events.js:311:20)

Commenting out line 476 resolves and bleno won't crash anymore. pkt is null for some reason.

Bleno wont advertise on mack if name has more than 8 character.

So I have updated my mac air (M1) to Monterey recently, but even before that I noticed even when I run simple code it wont advertise more than 8 character name.

Up to and 8 characters works fine. above 8 characters and Bluetooth LE defaults to computer name.

Not sure if anyone else has encountered this issue.

Here is the code I tried to run on my mac.

import bleno from '@abandonware/bleno'

const deviceName = '123456789'

var serviceUuids = ['fffffffffffffffffffffffffffffff0']
bleno.on('stateChange', function (state) {
console.log('on -> stateChange: ' + state)
if (state === 'poweredOn') {
bleno.startAdvertising(deviceName, serviceUuids, function (err) {
if (err) {
console.log(err)
}
})
} else {
bleno.stopAdvertising()
}
})

ASUS BT500 issue with bleno

Hello,
I have a problem with the bleno code that has been working so far, it communicated with CRS4.0 bluetooth and worked without error, it is currently using an ASUS BT500. Sometimes the bluetooth communication with the ASUS adapter stops, according to hciconfig and hcitool, everything is "UP AND RUNNING", there are no error messages. It's like it doesn't see anyone nearby.
Sometimes it works, sometimes it doesn't, but a restart always fixes it.
Our system: ubuntu 20.04 /[email protected]
Has anyone seen a similar problem?
Thanks for the help

Unable to install on Windows

I've been traying to install bleno in a window's project. When I run npm install bleno@npm:@abandonware/bleno this messages shows up:

npm WARN cleanup Failed to remove some directories [
npm WARN cleanup   [
npm WARN cleanup     'C:\\Users\\_\\workspace\\project_name\\node_modules\\@abandonware\\bluetooth-hci-socket',
npm WARN cleanup     [Error: EBUSY: resource busy or locked, rmdir 'C:\Users\_\workspace\project_name\node_modules\@abandonware\bluetooth-hci-socket'] {
npm WARN cleanup       errno: -4082,
npm WARN cleanup       code: 'EBUSY',
npm WARN cleanup       syscall: 'rmdir',
npm WARN cleanup       path: 'C:\\Users\\jared\\workspace\\Proyecto-Server-Conjunto-Habitacional\\node_modules\\@abandonware\\bluetooth-hci-socket'
npm WARN cleanup     }
npm WARN cleanup   ]
npm WARN cleanup ]
npm ERR! code 1
npm ERR! path C:\Users\_\workspace\project_name\bleno
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | win32 | x64
npm ERR! gyp info find Python using Python version 3.12.0 found at "C:\Users\_\scoop\apps\python\current\python.exe"
npm ERR! gyp info find VS using VS2022 (17.7.34018.315) found at:
npm ERR! gyp info find VS "C:\Program Files\Microsoft Visual Studio\2022\Community"
npm ERR! gyp info find VS run with --verbose for detailed information
npm ERR! gyp info spawn C:\Users\_\scoop\apps\python\current\python.exe
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   'C:\\Users\\_\\scoop\\persist\\nvm\\nodejs\\v20.5.0\\node_modules\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'msvs',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'C:\\Users\\_\\workspace\\project_name\\node_modules\\bleno\\build\\config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'C:\\Users\\_\\scoop\\persist\\nvm\\nodejs\\v20.5.0\\node_modules\\npm\\node_modules\\node-gyp\\addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'C:\\Users\\_\\AppData\\Local\\node-gyp\\Cache\\20.5.0\\include\\node\\common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=C:\\Users\\_\\AppData\\Local\\node-gyp\\Cache\\20.5.0',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=C:\\Users\\_\\scoop\\persist\\nvm\\nodejs\\v20.5.0\\node_modules\\npm\\node_modules\\node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=C:\\\\Users\\\\_\\\\AppData\\\\Local\\\\node-gyp\\\\Cache\\\\20.5.0\\\\<(target_arch)\\\\node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=C:\\Users\\_\\workspace\\project_name\\node_modules\\bleno',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'C:\\Users\\_\\workspace\\project_name\\node_modules\\bleno\\build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! Traceback (most recent call last):
npm ERR!   File "C:\Users\_\scoop\persist\nvm\nodejs\v20.5.0\node_modules\npm\node_modules\node-gyp\gyp\gyp_main.py", line 42, in <module>
npm ERR!     import gyp  # noqa: E402
npm ERR!     ^^^^^^^^^^
npm ERR!   File "C:\Users\_\scoop\persist\nvm\nodejs\v20.5.0\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 9, in <module>
npm ERR!     import gyp.input
npm ERR!   File "C:\Users\_\scoop\persist\nvm\nodejs\v20.5.0\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\input.py", line 19, in <module>
npm ERR!     from distutils.version import StrictVersion
npm ERR! ModuleNotFoundError: No module named 'distutils'
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (C:\Users\_\scoop\persist\nvm\nodejs\v20.5.0\node_modules\npm\node_modules\node-gyp\lib\configure.js:325:16)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:514:28)
npm ERR! gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:294:12)
npm ERR! gyp ERR! System Windows_NT 10.0.22621
npm ERR! gyp ERR! command "C:\\Users\\_\\scoop\\apps\\nvm\\current\\nodejs\\nodejs\\node.exe" "C:\\Users\\jared\\scoop\\persist\\nvm\\nodejs\\v20.5.0\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd C:\Users\_\workspace\project_name\node_modules\bleno
npm ERR! gyp ERR! node -v v20.5.0
npm ERR! gyp ERR! node-gyp -v v9.4.0
npm ERR! gyp ERR! not ok

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.