abandonware / bleno

A Node.js module for implementing BLE (Bluetooth Low Energy) peripherals
https://mastodon.social/@rzr/106068437787315146#bleno
MIT License
147 stars 50 forks source link

Connect and immediate disconnect #11

Open lorenzotsi opened 4 years ago

lorenzotsi commented 4 years ago

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

hypermoose commented 4 years ago

On linux make sure you stop the built in bluetoothd service using sudo systemctl stop bluetooth and then use hcitool to bring up hci0 using sudo hcitool hci0 up

That was causing me similar issues

xXD4rkM4tt3rXx commented 4 years ago

Same issue here. Any solution for that? I'mn Working on RPI

hypermoose commented 4 years ago

Did you try stopping the service?

Same issue here. Any solution for that? I'mn Working on RPI

xXD4rkM4tt3rXx commented 4 years ago

Yes i did. First of all i've installed a fresh image of raspbian via the RPI Image Creator. After that i've installed Node and installed the requiered libaries and bleno via: sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev --> npm i @abandonware/bleno Then i've stopped service with: sudo systemctl stop bluetooth Afterwards i've used hciconfig hci0 up and started the test.js

The Lightblue App detects the RPI but the connection can't be established. The output looks like this: bleno on -> stateChange: poweredOn, address = b8:27:eb:bd:53:8c on -> advertisingStart: success on -> servicesSet: success on -> accept, client: 4f:88:9a:91:12:6c on -> rssiUpdate: -44 on -> disconnect, client: 4f:88:9a:91:12:6c

The LightBlue Logs looks like this: 12:52:04.378 — Connecting to nearby peripheral: raspberrypi 12:52:04.814 — Failed to connect to nearby peripheral: <CBPeripheral: 0x2839217c0, identifier = 98E346A6-CF2F-5C12-68D5-A7808743DB56, name = raspberrypi, state = disconnected> (Error: Peer removed pairing information) 12:52:04.817 — Disconnecting from nearby peripheral: raspberrypi

xXD4rkM4tt3rXx commented 4 years ago

+++Update+++

With my iPad and LightBlue App everything works fine. With my iPhone XS and LightBlue App it doesn't work.

Every idea on that?

rzr commented 4 years ago

is this issue reproducible on GNU/Linux ?

Shadplay commented 4 years ago

@rzr So do you mean that I should try to connect a linux device to the bleno instance?

rzr commented 4 years ago

yes, it looks like the problem hasn't been isolated yet

niklas-braun commented 2 years ago

For everyone who still got an immediately disconnecting after connecting to a device.

Info: This solution worked on Raspberry Pi Zero 2 W.

I ran into the same error over and over again. The solution ist not the best, but it helped me to let the devices be connected over minutes.

Step 1

Delete package.json, package-lock.json and node_modules folder

Step 2

Copy package.json from battery-service example into your project root folder and run npm install

Step 3

Import bleno with var bleno = require('@abandonware/bleno');

rzr commented 2 years ago

ok good to know can you please try to narrow more which dep should be changed ?

niklas-braun commented 2 years ago

@rzr i looked up package.json and package-lock.json and the only changes I found were some minor version changes in included dependencies of "@abandonware/bleno".

Info: Since now I did not really got the time to test the different packages. The above solution was just the quickest one for me. In future I will have a look at the different versions. Maybe I will find out, why the connection unfortunately disconnects directly after connecting to a device

Working package-lock.json

    "node_modules/@abandonware/bleno": {
      "version": "0.5.1-3",
      "resolved": "https://registry.npmjs.org/@abandonware/bleno/-/bleno-0.5.1-3.tgz",
      "integrity": "sha512-QDhWz57s0qS21MH8xoHmHHp3bu3Z5c9z2koMXt5newnBVFNJaGcmOileQBpP9JTrxWVFvhJcweFD3UMxSuVQ/Q==",
      "hasInstallScript": true,
      "os": [
        "darwin",
        "linux",
        "android",
        "freebsd",
        "win32"
      ],
      "dependencies": {
        "debug": "^4.2.0",
        "napi-thread-safe-callback": "0.0.6",
        "node-addon-api": "^3.0.2"
      },
      "engines": {
        "node": ">=6"
      },
      "optionalDependencies": {
        "@abandonware/bluetooth-hci-socket": "^0.5.3-6",
        "bplist-parser": "0.2.0",
        "xpc-connect": "^2.0.0"
      }
    },
    "node_modules/@abandonware/bluetooth-hci-socket": {
      "version": "0.5.3-7",
      "resolved": "https://registry.npmjs.org/@abandonware/bluetooth-hci-socket/-/bluetooth-hci-socket-0.5.3-7.tgz",
      "integrity": "sha512-CaGDBeXEooRjaVJlgmnaWeI+MXlEBVN9705tp2GHCF2IFARH3h15lqf6eHjqFsdpQOiMWiBa/QZUAOGjzBrhmA==",
      "hasInstallScript": true,
      "optional": true,
      "os": [
        "linux",
        "android",
        "freebsd",
        "win32"
      ],
      "dependencies": {
        "debug": "^4.3.1",
        "nan": "^2.14.2",
        "node-pre-gyp": "^0.17.0"
      },
      "optionalDependencies": {
        "usb": "^1.6.3"
      }
    },

NOT working package-lock.json

    "node_modules/@abandonware/bleno": {
      "version": "0.5.1-4",
      "resolved": "https://registry.npmjs.org/@abandonware/bleno/-/bleno-0.5.1-4.tgz",
      "integrity": "sha512-2K/gbDxh4l4TV8xT/XUCwCT3e5aGDGmYad8gxt19CEvBMCs0+JScZ7roNyX0Jzice5rrR5RETcsMwIjJSzbeCQ==",
      "hasInstallScript": true,
      "os": [
        "darwin",
        "linux",
        "android",
        "freebsd",
        "win32"
      ],
      "dependencies": {
        "debug": "^4.3.1",
        "napi-thread-safe-callback": "0.0.6",
        "node-addon-api": "^3.1.0"
      },
      "engines": {
        "node": ">=6"
      },
      "optionalDependencies": {
        "@abandonware/bluetooth-hci-socket": "^0.5.3-7",
        "bplist-parser": "0.3.0",
        "xpc-connect": "^2.0.0"
      }
    },
    "node_modules/@abandonware/bluetooth-hci-socket": {
      "version": "0.5.3-8",
      "resolved": "https://registry.npmjs.org/@abandonware/bluetooth-hci-socket/-/bluetooth-hci-socket-0.5.3-8.tgz",
      "integrity": "sha512-JIUkTZpAo6vKyXd94OasynjnmAxgCvn3VRrQJM/KXBKbm/yW59BMK6ni1wLy/JLM4eFhsLkd2S907HJnXBSWKw==",
      "hasInstallScript": true,
      "optional": true,
      "os": [
        "linux",
        "android",
        "freebsd",
        "win32"
      ],
      "dependencies": {
        "@mapbox/node-pre-gyp": "^1.0.5",
        "debug": "^4.3.2",
        "nan": "^2.15.0"
      },
      "optionalDependencies": {
        "usb": "^1.7.2"
      }
    },
rzr commented 2 years ago

if anyone had time try to apply above changes one per one until it work