8000 How to get list of devices?? · Issue #57 · chrvadala/node-ble · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
How to get list of devices?? #57
Open
@DrCWO

Description

@DrCWO

Hi,
first thank you for making node-ble. Hope it will help me connecting to my devices 👍
I have a question but maybe it is also an issue, I don't know.

I like to start discovery and get the devices discovered so I can decide to which one I like to connect. In my example below I use myAdapter.devices() but is only returns an empty object. Any ideas?

I have bluetoothctl open at the same time and see that discovery starts. I also see the device announcing its UUID after some time but my code shows nothing.

Here my code:

'use strict';

async function main() {
	const { createBluetooth } = require('node-ble');
	const { bluetooth, destroy } = createBluetooth();
	var myAdapter = await bluetooth.defaultAdapter();

	console.log(myAdapter.adapter);

	if (! await myAdapter.isDiscovering()) {
		console.log ("startDiscovery");
		myAdapter.startDiscovery();
	}

	await myAdapter.isDiscovering();
	console.log ('isDiscovering');


	showDevices();

	function showDevices () {
		console.log (JSON.stringify(myAdapter.devices(), null,2));
		setTimeout (showDevices, 2000);
	}
}

main();

I can connect to one of my devices using its UUID (see working code blow). But before being able to do so I first have to find out the UUID which I expected to get with myAdapter.devices().

	const device = await adapter.waitDevice('70:BC:10:86:85:C5');
	await device.connect();

Support would be appreciated.
Best DrCWO

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0