bluetooth-classic-serialport-client
v0.1.25
Published
Bluetooth classic serial port client for Node.js
Downloads
7
Maintainers
Readme
Bluetooth classic serial port client for Node.js
A small Node.js library to :
- List bluetooth paired devices (Windows only)
- Scan nearby bluetooth devices (Linux only)
- Connect/Disconnect to Bluetooth device using RFCOMM
- Read/Write data
Currently using Nan as Native Addon (https://github.com/nodejs/nan).
Binaries are available here
- Windows (32 and 64 bits)
- Linux (64 bits)
Basic examples
Scan nearby bluetooth devices (only Linux)
Scanning process will last at most 25 seconds
const serial = new BluetoothClassicSerialportClient()
serial.scan()
.then((devices) => console.log('Scanned devices', devices))
.catch((err) => console.log('Error', err))
List paired bluetooth devices (only Windows)
const serial = new BluetoothClassicSerialportClient()
serial.listPairedDevices()
.then((devices) => console.log('Paired devices', devices))
.catch((err) => console.log('Error', err))
Connect to bluetooth device
const serial = new BluetoothClassicSerialportClient()
serial.connect(myBluetoothDevice.address)
.then(() => console.log('Connected'))
.catch((err) => console.log('Error', err))
Check bluetooth device is connected
const serial = new BluetoothClassicSerialportClient()
bool isConnected = serial.isOpen
Connect to bluetooth device
const serial = new BluetoothClassicSerialportClient()
serial.connect(myBluetoothDevice.address)
.then(() => console.log('Connected'))
.catch((err) => console.log('Error', err))
Write to a connected bluetooth device
const serial = new BluetoothClassicSerialportClient()
serial.write('whatever-you-want')
.then(() => console.log('Data successfully written'))
.catch((err) => console.log('Error', err)
Read from a connected bluetooth device
const serial = new BluetoothClassicSerialportClient()
serial.on('data', (data) => console.log(data))
Close connection
const serial = new BluetoothClassicSerialportClient()
serial.close()
.then(() => console.log('Connection successfully closed'))
.catch((err) => console.log('Error', err))