question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HELP - const gattServer = await device.gatt()- don't work :/

See original GitHub issue

1. const { createBluetooth } = require('node-ble')
2. const { TEST_DEVICE, TEST_SERVICE, TEST_CHARACTERISTIC, TEST_NOTIFY_SERVICE, TEST_NOTIFY_CHARACTERISTIC } = process.env
3. 
4. async function main () {
5.   const { bluetooth, destroy } = createBluetooth()
6. 
7.   // get bluetooth adapter
8.   const adapter = await bluetooth.defaultAdapter()
9.   await adapter.startDiscovery()
10.   console.log('discovering')
11. 
12.   // get device and connect
13.   const device = await adapter.waitDevice(TEST_DEVICE)
14.   console.log('got device', await device.getAddress(), await device.getName())
15.   await device.connect()
16.   console.log('connected')
17.   // console.log(device)
18.   console.log(await device.getRSSI())
19.   const gattServer = await device.gatt()
20.   console.log(gattServer)
21.   // read write characteristic
22.   const service1 = await gattServer.getPrimaryService("0000180f-0000-1000-8000-00805f9b34fb")
23.   // console.log(service1)
24.   const characteristic1 = await service1.getCharacteristic("00002a19-0000-1000-8000-00805f9b34fb")
25.   // await characteristic1.writeValue(Buffer.from('Hello world'))
26.   const buffer = await characteristic1.readValue()
27.   console.log('read', buffer, buffer.toString())
28. 
29.   destroy()
30. }
31. 
32. main()
33.   .then(console.log)
34.   .catch(console.error)
35. 

out:

discovering
got device EC:21:E5:43:94:CA BLESmart_00000044EC21E54394CA
connected
-43


I have trying to connect my blood pressure monitor to extract the data, but in line 19 - (const gattServer = await device.gatt()) doesn’t seem to work. The code stay in line 19 and never get the service in line 22. May some one help me? please!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
rzumbuehlcommented, Dec 1, 2021

@mathbozzi thanks for your reply. I just noticed, that the device immediately gets disconnected after the device.connect() call. That’s the reason in my case why the device.gatt() call does not return. I need to further investigate on this.

0reactions
afturnercommented, Jan 3, 2022

@rzumbuehl I was curious if you had discovered why the device was closing the connection immediately. I am observing the same behavior.

Read more comments on GitHub >

github_iconTop Results From Across the Web

when connected and receive data from BLE device I get DOM ...
I believe what you're experiencing is not Web Bluetooth related, but a GATT Protocol error as described in the Bluetooth Core Specification ...
Read more >
Can't discover service, and then 'org.bluez.Error.Failed' after a ...
I can discover the device, but not the service. ... const gattServer = await device.gatt() // read write characteristic const service1 = await...
Read more >
pi 4 - Trouble connecting to bluetooth device
How these two types of Bluetooth work is very different. ... waitDevice(deviceGUID); await device.connect(); const gattServer = await ...
Read more >
GattServer - API references and tutorials - Mbed
Application code can add a GattService object to the server with the help of the function addService() . That function registers all the...
Read more >
node-ble - npm
Use an adapter to get a remote Bluetooth device, then connect to it and bind to the GATT (Generic Attribute Profile) server. const...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found