chrvadala / node-ble

Bluetooth Low Energy (BLE) library written with pure Node.js (no bindings) - baked by Bluez via DBus
https://www.npmjs.com/package/node-ble
MIT License
315 stars 46 forks source link

DBuserror (Rapsberry Pi) #3

Closed buildog closed 4 years ago

buildog commented 4 years ago

I'm trying to use it on a raspberry pi 3B, but I got an error from DBus

const {createBluetooth} = require('node-ble')

async function main () {
  const {bluetooth, destroy} = createBluetooth()
  const adapter = await bluetooth.defaultAdapter()
  const discovery =  await adapter.startDiscovery()
  console.log('discovering')
  console.log(await adapter.devices());

  const device = await adapter.waitDevice('04:EE:03:B1:47:DF')
  await device.connect()
  console.log('connected')

  const gattServer = await device.gatt()
  console.log(await gattServer.services());
}

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

busconfig (also tried with pi user)

<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
  "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
  <policy user="root">
   <allow own="org.bluez"/>
    <allow send_destination="org.bluez"/>
    <allow send_interface="org.bluez.GattCharacteristic1"/>
    <allow send_interface="org.bluez.GattDescriptor1"/>
    <allow send_interface="org.freedesktop.DBus.ObjectManager"/>
    <allow send_interface="org.freedesktop.DBus.Properties"/>
  </policy>
</busconfig>
discovering
[ '04:EE:03:B1:47:DF' ]
DBusError: Software caused connection abort
    at _methodReturnHandlers.<computed> (/home/pi/bergepi/node_modules/dbus-next/lib/bus.js:339:27)
    at handleMessage (/home/pi/bergepi/node_modules/dbus-next/lib/bus.js:98:11)
    at EventEmitter.<anonymous> (/home/pi/bergepi/node_modules/dbus-next/lib/bus.js:147:9)
    at EventEmitter.emit (events.js:315:20)
    at EventEmitter.emit (domain.js:482:12)
    at /home/pi/bergepi/node_modules/dbus-next/lib/connection.js:112:14
    at Socket.<anonymous> (/home/pi/bergepi/node_modules/dbus-next/lib/message.js:63:9)
    at Socket.emit (events.js:315:20)
    at Socket.EventEmitter.emit (domain.js:482:12)
    at emitReadable_ (_stream_readable.js:556:12) {
  type: 'org.bluez.Error.Failed',
  text: 'Software caused connection abort',
  reply: Message {
    type: 3,
    _sent: false,
    _serial: 58,
    path: undefined,
    interface: undefined,
    member: undefined,
    errorName: 'org.bluez.Error.Failed',
    replySerial: 12,
    destination: ':1.26',
    sender: ':1.13',
    signature: 's',
    body: [ 'Software caused connection abort' ],
    flags: 1
  }
}

BlueZ version 5.50

pi@raspberrypi:/etc/dbus-1/system.d $ bluetoothctl -v
bluetoothctl: 5.50
buildog commented 4 years ago

fixed after a fresh reinstall