All Projects → eelcocramer → Node Bluetooth Serial Port

eelcocramer / Node Bluetooth Serial Port

Licence: other
Serial I/O over bluetooth for NodeJS

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Node Bluetooth Serial Port

Qtswissarmyknife
QSAK (Qt Swiss Army Knife) is a multi-functional, cross-platform debugging tool based on Qt.
Stars: ✭ 196 (-55.86%)
Mutual labels:  serial, server, client
Ts3admin.class
The ts3admin.class is a powerful api for communication with Teamspeak 3 Servers from your website! Your creativity knows no bounds!
Stars: ✭ 103 (-76.8%)
Mutual labels:  communication, server, client
Arduino Robust Serial
A simple and robust serial communication protocol. It was designed for Arduino but can be used for other purposes (e.g. bluetooth, sockets). Implementation in C Arduino, C++, Python and Rust.
Stars: ✭ 83 (-81.31%)
Mutual labels:  serial, communication, bluetooth
bluetooth-terminal
ES6 class for serial communication with your own Bluetooth Low Energy (Smart) devices
Stars: ✭ 43 (-90.32%)
Mutual labels:  serial, communication, bluetooth
Web Bluetooth Terminal
Progressive Web Application for serial communication with your own Bluetooth Low Energy (Smart) devices
Stars: ✭ 130 (-70.72%)
Mutual labels:  serial, communication, bluetooth
arduino-ble-gadget
Create your own Do-It-Yourself BLE enabled sensor gadget on the ESP32 platform.
Stars: ✭ 31 (-93.02%)
Mutual labels:  communication, bluetooth
BOSCH-GLM-rangefinder
Python script to remote control a BOSCH GLM 100C rangefinder via its Bluetooth serial interface
Stars: ✭ 41 (-90.77%)
Mutual labels:  serial, bluetooth
Happypandax
A cross-platform server and client application for managing and reading manga and doujinshi
Stars: ✭ 432 (-2.7%)
Mutual labels:  server, client
Study
A simple, progressive, client/server AB testing library 📚
Stars: ✭ 293 (-34.01%)
Mutual labels:  server, client
Eiskaltdcpp
File sharing program using DC and ADC protocols
Stars: ✭ 277 (-37.61%)
Mutual labels:  communication, client
Cserialport
基于C++的轻量级开源跨平台串口类库Lightweight cross-platform serial port library based on C++
Stars: ✭ 296 (-33.33%)
Mutual labels:  serial, communication
SerialTransfer
Arduino library to transfer dynamic, packetized data fast and reliably via Serial, I2C, or SPI
Stars: ✭ 273 (-38.51%)
Mutual labels:  serial, communication
android-bluetooth-serial
A library for Android to simplify basic serial communication over Bluetooth, for example when communicating with Arduinos.
Stars: ✭ 120 (-72.97%)
Mutual labels:  serial, bluetooth
yahdlc
yahdlc - Yet Another HDLC implementation
Stars: ✭ 47 (-89.41%)
Mutual labels:  serial, communication
Windterm
A quicker and better cross-platform SSH/Sftp/Shell/Telnet/Serial client.
Stars: ✭ 345 (-22.3%)
Mutual labels:  serial, client
Beast
HTTP and WebSocket built on Boost.Asio in C++11
Stars: ✭ 3,241 (+629.95%)
Mutual labels:  server, osx
Nodepolus
NodePolus is a JavaScript library containing multiple implementations of the Among Us network protocol.
Stars: ✭ 331 (-25.45%)
Mutual labels:  server, client
Networksocket
NetworkSocket是一个以中间件(middleware)扩展通讯协议,以插件(plug)扩展服务器功能的支持SSL安全传输的通讯框架;目前支持http、websocket、fast、flex策略与silverlight策略协议。
Stars: ✭ 435 (-2.03%)
Mutual labels:  server, client
Mumble
Mumble is an open-source, low-latency, high quality voice chat software.
Stars: ✭ 4,418 (+895.05%)
Mutual labels:  server, client
Arduino Cmdmessenger
CmdMessenger Communication library for Arduino & .NET
Stars: ✭ 175 (-60.59%)
Mutual labels:  serial, bluetooth

Bluetooth serial port communication for Node.js

DEPRECATED Currently I have no plans to add support for nodejs version 1.13 and up. If you want to help out by adding support please contact me. It was a great experience maintaining this project for almost 8 years. It was great to see people step in to improve this project. Thank you all!

Build Status Build status

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.

New in the last release

  • Changes node version to lts in the Dockerfile

Check the release notes for an overview of the change history.

Prerequisites on Linux

  • Needs Bluetooth development packages to build

apt-get install build-essential libbluetooth-dev

Note on RFCOMM Server Sockets

As the initial implementation of the RFCOMM server sockets is based on BlueZ4, in order to work with SDP we need to change the bluetoothd service configuration file by modifing the systemd unit file: bluetooth.service:

(Debian based distro)

sudo vim /lib/systemd/system/bluetooth.service

(RedHat based distro)

sudo vim /usr/lib/systemd/system/bluetooth.service

and adding the --compat flag to the ExecStart value:

ExecStart=/usr/lib/bluetooth/bluetoothd--compat

Finally, restart the service:

sudo systemctl daemon-reload
sudo systemctl restart bluetooth

Prerequisites on macOS

  • Needs Xcode and Xcode command line tools installed.

Prerequisites on Windows

  • Needs Visual Studio (Visual C++) and its command line tools installed.
  • Needs Python 2.x installed and accessible from the command line path.

Install

npm install bluetooth-serial-port

Test build Linux using docker

docker build -t bluetooth-serial-port .

Documentation

Basic client usage

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(Buffer.from('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();

Basic server usage (only on Linux)

var server = new(require('bluetooth-serial-port')).BluetoothSerialPortServer();

var CHANNEL = 10; // My service channel. Defaults to 1 if omitted.
var UUID = '38e851bc-7144-44b4-9cd8-80549c6f2912'; // My own service UUID. Defaults to '1101' if omitted

server.on('data', function(buffer) {
    console.log('Received data from client: ' + buffer);

    // ...

    console.log('Sending data to the client');
    server.write(Buffer.from('...'), function (err, bytesWritten) {
        if (err) {
            console.log('Error!');
        } else {
            console.log('Send ' + bytesWritten + ' to the client!');
        }
    });
});

server.listen(function (clientAddress) {
    console.log('Client: ' + clientAddress + ' connected!');
}, function(error){
	console.error("Something wrong happened!:" + error);
}, {uuid: UUID, channel: CHANNEL} );

API

BluetoothSerialPort

Event: ('data', buffer)

Emitted when data is read from the serial port connection.

  • buffer - the data that was read into a Buffer object.

Event: ('closed')

Emitted when a connection was closed either by the user (i.e. calling close or remotely).

Event: ('failure', err)

Emitted when reading from the serial port connection results in an error. The connection is closed.

Event: ('found', address, name)

Emitted when a bluetooth device was found.

  • address - the address of the device
  • name - the name of the device (or the address if the name is unavailable)

Event: ('finished')

Emitted when the device inquiry execution did finish.

BluetoothSerialPort.inquire()

Starts searching for bluetooth devices. When a device is found a 'found' event will be emitted.

BluetoothSerialPort.inquireSync()

Starts searching synchronously for bluetooth devices. When a device is found a 'found' event will be emitted.

BluetoothSerialPort.findSerialPortChannel(address, callback[, errorCallback])

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.

BluetoothSerialPort.close()

Closes the connection.

BluetoothSerialPort.isOpen()

Check whether the connection is open or not.

BluetoothSerialPort.write(buffer, callback)

Writes a Buffer to the serial port connection.

  • buffer - the Buffer to be written.
  • callback(err, bytesWritten) - is called when the write action has been completed. When the 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.

BluetoothSerialPort.listPairedDevices(callback)

NOT AVAILABLE ON LINUX

Lists the devices that are currently paired with the host.

  • callback(pairedDevices) - is called when the paired devices object has been populated. See the pull request for more information on the pairedDevices object.

BluetoothSerialPortServer

BluetoothSerialPortServer.listen(callback[, errorCallback, options])

Listens for an incoming bluetooth connection. It will automatically advertise the server via SDP

  • callback(address) - is called when a new client is connecting.
  • errorCallback(err) - is called when an error occurs.
  • options - An object with these properties:
    • uuid - [String] The UUID of the server. If omitted the default value will be 1101 (corresponding to Serial Port Profile UUID). Can be a 16 bit or 32 bit UUID.

    • channel - [Number] The RFCOMM channel the server is listening on, in the range of 1-30. If omitted the default value will be 1.

      Example: var options = { uuid: 'ffffffff-ffff-ffff-ffff-fffffffffff1', channel: 10 }

BluetoothSerialPortServer.write(buffer, callback)

Writes data from a buffer to a connection.

  • buffer - the buffer to send over the connection.
  • callback(err, len) - called when the data is send or an error did occur. error contains the error is appropriated. len has the number of bytes that were written to the connection.

BluetoothSerialPortServer.close()

Stops the server.

BluetoothSerialPortServer.disconnectClient()

Disconnects the currently-connected client and re-listens and re-publishes to SDP.

BluetoothSerialPortServer.isOpen()

Checks is a server is listening or not.

Event: ('data', buffer)

Emitted when data is read from the serial port connection.

  • buffer - the data that was read into a Buffer object.

Event: ('disconnected')

Emitted when a connection was disconnected (i.e. from calling disconnectClient or if the bluetooth device disconnects (turned off or goes out of range)).

Event: ('closed')

Emitted when the server is closed (i.e. from calling close or as the result of a non-disconnect error).

Event: ('failure', err)

Emitted when reading from the serial port connection results in an error. The connection is closed.

Typescript support

The type script declaration file is bundled with this module.

import * as btSerial from "bluetooth-serial-port";

btSerial.findSerialPortChannel(address: string, (channel: number) => {
    btSerial.connect(address: string, channel: number, () => {
        btSerial.write(Buffer.from("yes"), (err) => {
	    if (err) {
                console.error(err);
            }
        });
    }, (err?: Error) => {
            if (err) {
                console.error(err);
            }
        });
        btSerial.on("data", (buffer: Buffer) => console.log(buffer.toString("ascii")));
}, () => {
        console.error("Cannot find channel!");
});

LICENSE

This module is available under a FreeBSD license, see the LICENSE file for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].