node-ble icon indicating copy to clipboard operation
node-ble copied to clipboard

Can't discover service, and then 'org.bluez.Error.Failed' after a minute

Open mohse-n opened this issue 5 years ago • 10 comments

I'm using RPi 4 (with node 14.9.0, BlueZ 5.50). I can discover the device, but not the service.

require('dotenv').config()

const { createBluetooth } = require('.')
const { TEST_DEVICE, TEST_SERVICE, TEST_CHARACTERISTIC, TEST_NOTIFY_SERVICE, TEST_NOTIFY_CHARACTERISTIC } = process.env

async function main () {
  const { bluetooth, destroy } = createBluetooth()

  // get bluetooth adapter
  const adapter = await bluetooth.defaultAdapter()
  await adapter.startDiscovery()
  console.log('discovering')

  // get device and connect
  const device = await adapter.waitDevice('D4:CA:6E:F1:84:BE')
  console.log('got device', await device.getAddress(), await device.getName())
  await device.connect()
  console.log('connected')

  const gattServer = await device.gatt()

  // read write characteristic
  const service1 = await gattServer.getPrimaryService('15172000-4947-11e9-8646-d663bd873d93')
  console.log('got primary service.')
  const characteristic1 = await service1.getCharacteristic('15172001-4947-11e9-8646-d663bd873d93')
  console.log('got control characteristic.')
  //await characteristic1.writeValue(Buffer.from('Hello world'))
  const buffer = await characteristic1.readValue()
  console.log('read', buffer, buffer.toString())

}

main()
  .then(console.log)
  .catch(console.error)

Console output

discovering
got device D4:CA:6E:F1:84:BE Xsens DOT
DBusError: Software caused connection abort
    at _methodReturnHandlers.<computed> (/home/pi/node-ble-master/node_modules/dbus-next/lib/bus.js:339:27)
    at handleMessage (/home/pi/node-ble-master/node_modules/dbus-next/lib/bus.js:98:11)
    at EventEmitter.<anonymous> (/home/pi/node-ble-master/node_modules/dbus-next/lib/bus.js:147:9)
    at EventEmitter.emit (events.js:314:20)
    at /home/pi/node-ble-master/node_modules/dbus-next/lib/connection.js:112:14
    at Socket.<anonymous> (/home/pi/node-ble-master/node_modules/dbus-next/lib/message.js:63:9)
    at Socket.emit (events.js:314:20)
    at emitReadable_ (_stream_readable.js:563:12)
    at processTicksAndRejections (internal/process/task_queues.js:79:21) {
  type: 'org.bluez.Error.Failed',
  text: 'Software caused connection abort',
  reply: Message {
    type: 3,
    _sent: false,
    _serial: 1494,
    path: undefined,
    interface: undefined,
    member: undefined,
    errorName: 'org.bluez.Error.Failed',
    replySerial: 13,
    destination: ':1.68',
    sender: ':1.22',
    signature: 's',
    body: [ 'Software caused connection abort' ],
    flags: 1
  }
}


mohse-n avatar Sep 08 '20 22:09 mohse-n

@mohse-n have your solved the problem, i catch the same case.

chenkaiC4 avatar Oct 21 '20 07:10 chenkaiC4

i am use ubuntu18.04. when i connect to device,it never give a correct response, but a “Software caused connection abort”

chenkaiC4 avatar Oct 21 '20 07:10 chenkaiC4

Same here, "Software caused connection abort" when trying to connect to the device. I run on Ubuntu 18.04 as well.

titaniumwhite avatar Nov 29 '20 11:11 titaniumwhite

I was using Raspberry Pi 3 and 4. Upgrading to the latest version of Raspbian (Raspberry Pi OS) solved the problem for me.

mohse-n avatar Dec 02 '20 22:12 mohse-n

I got the same problem. I am using node-ble inside a homebridge plugin. My Raspberry Pi Zero W is running the latest Raspberry Pi OS and node.

Any ideas how to fix it?

ManDon5 avatar Jan 14 '21 20:01 ManDon5

In order to debug the issue, I suggest you the following lines:

$  bluetoothctl
> connect DC:A6:32:3F:7B:7A
> menu gatt
> list-attributes

Does bluetoothctl list the expected services?

chrvadala avatar Jan 17 '21 18:01 chrvadala

Thank you for your quick respond. I think that was a mistake of mine. I will check it at the weekend and get back in touch here.

ManDon5 avatar Jan 18 '21 19:01 ManDon5

I checked my implementation. I am getting the following error after a few seconds if the peripheral is not reachable:

DBusError: Software caused connection abort

Is it possible to search/wait for the peripheral till it is available? I want to integrated node-ble inside my homebridge plugin and it should search for peripherals in an endless loop if it is not reachable.

If my peripheral is reachable everything runs fine.

ManDon5 avatar Jan 22 '21 14:01 ManDon5

Hello! I get the same error. It connects to the device and can display my phone's name, but when I try device.connect() it throws that error after a bit. I'm running it from a RPi 4 using Raspbian.

Also, I can connect to my device using bluetoothctl, but nothing is listed when I use the list-attributes command.

Has anyone found a solution?

rick-loz avatar Feb 11 '21 08:02 rick-loz

In order to debug the issue, I suggest you the following lines:

$  bluetoothctl
> connect DC:A6:32:3F:7B:7A
> menu gatt
> list-attributes

Does bluetoothctl list the expected services?

I get the same problem. I'm running in a Docker Image on a RPi4.

I can ssh into the docker image and when I try https://github.com/chrvadala/node-ble/issues/13#issuecomment-761858089 I get the following :

[bluetooth]#
[CHG] Device 7B:41:00:00:04:98 ManufacturerData Value: 0x00
[bluetooth]#
[CHG] Device 7B:41:00:00:04:98 ManufacturerData Value: 0x00
[bluetooth]# connect 7B:41:00:00:04:98
Attempting to connect to 7B:41:00:00:04:98
[bluetooth]#
Failed to connect: org.bluez.Error.Failed
[bluetooth]#

In my code, I can get the device, and getAddress and getName work as expected, but when I attempt to connect, I get :

*** BLE devices: [ '7B:41:00:00:04:98', 'DC:0D:30:01:14:C3' ] got device 7B:41:00:00:04:98 ThermoBeacon false (node:32) UnhandledPromiseRejectionWarning: DBusError: Software caused connection abort at methodReturnHandlers.(anonymous function) (/srv/node_modules/dbus-next/lib/bus.js:343:27) at handleMessage (/srv/node_modules/dbus-next/lib/bus.js:101:11) at EventEmitter.MessageBus.conn.on (/srv/node_modules/dbus-next/lib/bus.js:151:9) at EventEmitter.emit (events.js:198:13) at /srv/node_modules/dbus-next/lib/connection.js:116:14 at Socket. (/srv/node_modules/dbus-next/lib/message.js:63:9) at Socket.emit (events.js:198:13) [Logs] [4/10/2021, 1:23:47 PM] [smart-hub] at emitReadable (_stream_readable.js:555:12) [Logs] [4/10/2021, 1:23:47 PM] [smart-hub] at process._tickCallback (internal/process/next_tick.js:63:19)

dave190265 avatar Apr 10 '21 12:04 dave190265