Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mathbozzi opened this issue Feb 20, 2021 · 9 comments
Open

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

mathbozzi opened this issue Feb 20, 2021 · 9 comments

Comments

@mathbozzi
Copy link


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!

@rzumbuehl
Copy link

I ran into the same issue. Any solution available?

@mathbozzi
Copy link
Author

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

@rzumbuehl
Copy link

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

@afturner
Copy link

afturner commented Dec 27, 2021

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

@rzumbuehl
Copy link

@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
Copy link

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

@afturner
Copy link

afturner commented 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.

@lesha369
Copy link

lesha369 commented Nov 10, 2023

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;
        }

@mteichtahl
Copy link

has there been any progress on this issue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants