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
310 stars 45 forks source link

gatt.services() returns nothing #18

Closed TIB28 closed 3 years ago

TIB28 commented 3 years ago

Here is my code where the gatt.services() function returns nothing:

const connectDevice = async (deviceName) => {
  const adapter = await bluetooth.defaultAdapter()

  if (! await adapter.isDiscovering())
    await adapter.startDiscovery()

  var devices = await adapter.devices()

  for (deviceMac of devices) {
    const device = await adapter.waitDevice(deviceMac)
    const name = await device.getAlias()
    if (name == deviceName) {
      console.log(deviceName + " found !!") // the device is found
      const gatt = await device.gatt()
      var services = await gatt.services();
      console.log(services) // give me nothing here
    } else {
      device.disconnect()
    }
  }

}

connectDevice("myDevice")

Also i'm running that on a raspberry pi 4 with sudo and nodeJS v10.21.0 from apt if ever that matters.

TIB28 commented 3 years ago

I just figure out that i never connect to the device. So just adding await device.connect()fix it.