Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
akvadrako opened this issue Nov 11, 2020 · 9 comments

Comments

@akvadrako
Copy link

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

@rzr
Copy link

rzr commented Nov 11, 2020

I think I faced something similar and workaround-ed it somehow

@krater
Copy link

krater commented Dec 3, 2020

Some problem here when using btlejuice.

@chwong008
Copy link

Yes, I got same problem sometimes.

@krater
Copy link

krater commented Jan 12, 2021

This repo is dead. Use software thats based on the dbus-api for bluetooth. All other will not work as expected.

@akvadrako
Copy link
Author

akvadrako commented Jan 12, 2021

I don't agree. It's true that the other projects are badly maintained but bluetoothd is a mess for services. The connections are unstable and requires experimental flags plus custom dbus permissions to do simple stuff like customize advertisments.

I did give up on bleno but I forked pybleno and got it working: https://github.com/akvadrako/pybleno.

@jmbldwn
Copy link

jmbldwn commented Feb 14, 2021

This error is triggered because the crypto function 'swap' does not handle undefined inputs.

However, the root cause seems to be that somehow the characteristics are being defined as needing encryption. I'm seeing my iPhone try to pair with my peripheral, which only happens if permissions are specified to be encryted.

Trying to figure out why that's happening...

@gerdklingler
Copy link

Suddenly same problem here.

@pi3ch
Copy link

pi3ch commented Jan 13, 2022

Same here. didn't have this issue last year when I was using this tool on the same devices.

Any workaround?

@yakupad
Copy link

yakupad commented Feb 23, 2024

Please take into account the prerequisites mentioned in the Readme.md. I have implemented the following solution for Raspberry Pi OS.

1. Installing Required Packages

First, install the necessary Bluetooth libraries and tools:

sudo apt-get update
sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev libusb-1.0-0-dev

2. Installing Node.js

Node.js needs to be installed on your system if it is not already. You can use the following commands with the NodeSource package to install it:

curl -sL https://deb.nodesource.com/setup_current.x | sudo bash -
sudo apt-get install -y nodejs

If the node command does not work but nodejs does, you can solve this by creating a symbolic link:

sudo ln -s /usr/bin/nodejs /usr/bin/node

3. Stopping and Disabling the Bluetooth Service

Use the following commands to stop and disable the Bluetooth service:

For System V:

To stop once:

sudo service bluetooth stop

To prevent Bluetooth from starting on reboot:

sudo update-rc.d bluetooth remove

For systemd:

To stop once:

sudo systemctl stop bluetooth

To prevent Bluetooth from starting on reboot:

sudo systemctl disable bluetooth

4. Note on noble and bleno

If you are using both noble and bleno modules at the same time and cannot get the service list of connected BLE devices, check out the bleno compatibility section in noble's documentation.

You can follow these steps to perform the configurations mentioned. If you get stuck anywhere or need further assistance, do not hesitate to reach out to me.

Learning about the System Boot and Service Management Mechanism

System V and systemd are two different system boot and service management mechanisms. Which one you will use depends on the Linux distribution and version you are working on. One of these management systems generally comes as a default in modern Linux distributions.

  • System V (sysVinit): A traditional start-up and service management system commonly found in older Linux distributions.

  • systemd: A more modern start-up and service management system equipped with newer features, found by default in most current Linux distributions.

To determine which system manager you should use, run the following command in the terminal:

ps --no-headers -o comm 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants