Open DrCWO opened 1 year ago
Hi again, found the solution by myself. Here the code that works...
'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();
async function showDevices () {
console.log ('------------------------------');
var myDevices = await myAdapter.devices();
console.log (myDevices);
setTimeout (showDevices, 2000);
}
}
main();
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:
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()
.Support would be appreciated. Best DrCWO