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

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

Open mathbozzi opened this issue 4 years ago • 10 comments


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!

mathbozzi avatar Feb 20 '21 22:02 mathbozzi

I ran into the same issue. Any solution available?

rzumbuehl avatar Nov 30 '21 12:11 rzumbuehl

Please, try to disconnect the device to all gatways. Or, try to factory reset your device.

mathbozzi avatar Nov 30 '21 15:11 mathbozzi

@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.

rzumbuehl avatar Dec 01 '21 10:12 rzumbuehl

@rzumbuehl did you find a cause for this issue? I am running into the same problem.

afturner avatar Dec 27 '21 07:12 afturner

@rzumbuehl looks you are using omron's device. Correct? I have the same device. I have similar issue. I can connect to the devices but could not manage to get any data from the notification Services.If you manage to get any data out please share

rabee05 avatar Dec 27 '21 07:12 rabee05

@rzumbuehl did you find a cause for this issue? I am running into the same problem.

As mentioned, the root cause of my problem was that the BLE device closed the connection to the BLE Central (Raspberry PI) immediately after the device.connect() call. This was the reason why device.gatt() call did not return.

rzumbuehl avatar Dec 27 '21 10:12 rzumbuehl

@rzumbuehl looks you are using omron's device. Correct? I have the same device. I have similar issue. I can connect to the devices but could not manage to get any data from the notification Services.If you manage to get any data out please share

No, I'm actually using another BLE device (wearable). Sorry, I can't help here.

rzumbuehl avatar Dec 27 '21 10:12 rzumbuehl

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

afturner avatar Jan 03 '22 02:01 afturner

hello. this theme is actual. i am cant get device.gatt() .

this code not working too. and this not resolve problem .

try {
            this.gattServer = await Promise.race([
                device.gatt(),
                new Promise((resolve, reject) => setTimeout(() => {
                    reject('cant get device.gatt()');
                }, this.timeout)),
            ]);
            logger.info(`get gatt`);
            this.device = device;
        } catch (error) {
            throw error;
        }

lesha369 avatar Nov 10 '23 20:11 lesha369

has there been any progress on this issue ?

mteichtahl avatar Feb 23 '24 06:02 mteichtahl