Giter Site home page Giter Site logo

rasata / node-bluetooth-serial-port Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eelcocramer/node-bluetooth-serial-port

0.0 2.0 0.0 1010 KB

Serial I/O over bluetooth for NodeJS

License: Other

Python 0.91% JavaScript 6.85% Objective-C 5.22% C++ 33.50% C 31.61% Objective-C++ 21.91%

node-bluetooth-serial-port's Introduction

Bluetooth serial port communication for Node.js

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 this release

  • Fixes a critical runtime error on all platforms.
  • Improves travis build.

Pre-requests on Linux

  • Needs Bluetooth development packages to build

apt-get install build-essential libbluetooth-dev

Pre-request on OS X

  • Needs XCode and XCode command line tools installed.

Pre-request 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 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(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();

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.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.

BluetoothSerialPort.connect(bluetoothAddress, channel[, successCallback, errorCallback])

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)

ONLY ON OSX

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.

LICENSE

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

node-bluetooth-serial-port's People

Contributors

eelcocramer avatar edsadr avatar programmarchy avatar langholz avatar ericsmekens avatar imyller avatar joostverdoorn avatar bebraw avatar

Watchers

Zo-Hasina Rasatavohary avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.