Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
bluetooth-serial-port
Advanced tools
This node module lets you communicate over Bluetooth serial port with devices using Node.js. The goal is have an easy to use API. This module is great for communicating with Bluetooth enabled Arduino devices.
If you have any problems make sure to checkout the FAQ.
apt-get install build-essential libbluetooth-dev
npm install bluetooth-serial-port
docker build -t bluetooth-serial-port .
var btSerial = new (require('bluetooth-serial-port')).BluetoothSerialPort();
btSerial.on('found', function(address, name) {
btSerial.findSerialPortChannel(address, function(channel) {
btSerial.connect(address, channel, function() {
console.log('connected');
btSerial.write(new Buffer('my data', 'utf-8'), function(err, bytesWritten) {
if (err) console.log(err);
});
btSerial.on('data', function(buffer) {
console.log(buffer.toString('utf-8'));
});
}, function () {
console.log('cannot connect');
});
// close the connection when you're ready
btSerial.close();
}, function() {
console.log('found nothing');
});
});
btSerial.inquire();
var server = new(require('bluetooth-serial-port')).BluetoothSerialPortServer();
var PORT = 1;
var UUID = '38e851bc-7144-44b4-9cd8-80549c6f2912';
server.listen(UUID, PORT, function (clientAddress) {
console.log('Client: ' + clientAddress + ' connected!');
server.on('data' function(buffer) {
console.log('Received data from client: ' + buffer);
// ...
console.log('Sending data to the client');
server.write(new Buffer('...'), function (err, bytesWritten) {
if (error) {
console.log('Error!');
} else {
console.log('Send ' + bytesWritten + ' to the client!');
}
});
});
});
server.advertise(UUID, function(err) {
if (err) {
console.log('Cannot advertise the server');
}
});
Emitted when data is read from the serial port connection.
Emitted when a connection was closed either by the user (i.e. calling close
or remotely).
Emitted when reading from the serial port connection results in an error. The connection is closed.
Emitted when a bluetooth device was found.
Emitted when the device inquiry execution did finish.
Starts searching for bluetooth devices. When a device is found a 'found' event will be emitted.
Checks if a device has a serial port service running and if it is found it passes the channel id to use for the RFCOMM connection.
callback(channel) - called when finished looking for a serial port on the device.
errorCallback - called the search finished but no serial port channel was found on the device. Connects to a remote bluetooth device.
bluetoothAddress - the address of the remote Bluetooth device.
channel - the channel to connect to.
[successCallback] - called when a connection has been established.
[errorCallback(err)] - called when the connection attempt results in an error. The parameter is an Error object.
Closes the connection.
Check whether the connection is open or not.
Writes a Buffer to the serial port connection.
err
parameter is set an error has occured, in that case err
is an Error object. When err
is not set the write action was successful and bytesWritten
contains the amount of bytes that is written to the connection.ONLY ON OSX
Lists the devices that are currently paired with the host.
pairedDevices
object.Listens for an incoming bluetooth connection. It will automatically advertise the server via SDP
Writes data from a buffer to a connection.
error
contains the error is appropriated. len
has the number of bytes that were written to the connection.Stops the server
Checks is a server is listening or not.
Emitted when data is read from the serial port connection.
Emitted when a connection was closed either by the user (i.e. calling close
or remotely).
Emitted when reading from the serial port connection results in an error. The connection is closed.
This module is available under a FreeBSD license, see the LICENSE file for details.
FAQs
Bluetooth serial port communication for Node.js
The npm package bluetooth-serial-port receives a total of 104 weekly downloads. As such, bluetooth-serial-port popularity was classified as not popular.
We found that bluetooth-serial-port demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.