Scan example using Nodejs library
Introduction
In this example, we are going to
- install node js libray
- connect to BleuIO dongle
- set the dongle to central role
- scan for nearby bluetooth devies
- show the result into the screen
- run the script
First install the library using
npm i bleuio-nodejs-library
Creater a script.js file and paste the following code
import { bleuIO } from "bleuio-nodejs-library/bleuIO-nodejs-library/index.js";
const portUtils = bleuIO("/dev/cu.usbmodem4048FDE6EBCB1");
portUtils.writeData("AT+CENTRAL").then(() => {
portUtils.writeData("AT+GAPSCAN=2").then(() => {
portUtils.readData().then((data) => {
setTimeout(() => {
console.log("Data read from serial port:", data);
}, 3000);
});
});
});
Here '/dev/cu.usbmodem4048FDE6EBCB1' is the path of the dongle. To get the conencted dongle path , write the following code for MAc
ls /dev/cu.*
For windows, devie path can be found on device information screen After scanning for three seconds ,we wait for the response and show it on the screen.
To run the script, we simply type follwing code on terminal
node script.js