Git Product home page Git Product logo

node-bluetooth's Introduction

node-bluetooth NPM version

Bluetooth serial port communication for Node.js

Requirements

This package require node-gyp installed .

Linux

You'll need libbluetooth-dev. On Ubuntu/Debian : $ sudo apt-get install libbluetooth-dev

Installation

$ npm install node-bluetooth --save

Example

create device

const bluetooth = require('node-bluetooth');

// create bluetooth device instance
const device = new bluetooth.DeviceINQ();

list already paired devices

device.listPairedDevices(console.log);

will output

  node-bluetooth git:(master)  node example/index.js
[ { name: 'Lsong’s Trackpad',
    address: 'd0-a6-37-f1-e7-87',
    services: [ [Object], [Object] ] },
  { name: 'Lsong’s iPhone',
    address: 'dc-2b-2a-82-76-29',
    services: [ [Object], [Object], [Object], [Object] ] },
  { name: 'Lsong’s Keyboard',
    address: '60-c5-47-19-d3-76',
    services: [ [Object], [Object] ] } ]

find devices

device
.on('finished',  console.log.bind(console, 'finished'))
.on('found', function found(address, name){
  console.log('Found: ' + address + ' with name ' + name);
}).scan();

will output

➜  node-bluetooth git:(master) ✗ node example/index.js
Found: 22-22-a3-0d-63-09 with name Meizu MX4 Pro
Found: dc-2b-2a-82-76-29 with name Lsong's iPhone
Found: 38-bc-1a-37-2d-d4 with name MEIZU MX5
finished

find serial port channel

device.findSerialPortChannel(address, function(channel){
  console.log('Found RFCOMM channel for serial port on %s: ', name, channel);

  // make bluetooth connect to remote device
  bluetooth.connect(address, channel, function(err, connection){
    if(err) return console.error(err);
    connection.write(new Buffer('Hello!', 'utf-8'), () => {
      console.log("wrote");
    });
  });

});

create connection to device, read and write

// make bluetooth connect to remote device
bluetooth.connect(address, channel, function(err, connection){
  if(err) return console.error(err);

  connection.on('data', (buffer) => {
    console.log('received message:', buffer.toString());
  });

  connection.write(new Buffer('Hello!', 'utf-8'), () => {
    console.log("wrote");
  });
});

API

Contributing

  • Fork this Repo first
  • Clone your Repo
  • Install dependencies by $ npm install
  • Checkout a feature branch
  • Feel free to add your features
  • Make sure your features are fully tested
  • Publish your local branch, Open a pull request
  • Enjoy hacking <3

MIT license

Copyright (c) 2016 lsong

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


node-bluetooth's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-bluetooth's Issues

Can't install on Ubuntu 18.0.4

Hello, module can't install on ubuntu. Here the trace :

sudo node-gyp configure build
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp info find Python using Python version 3.6.9 found at "/usr/bin/python3"
gyp info spawn /usr/bin/python3
gyp info spawn args [
gyp info spawn args '/usr/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/home/fennia/restaurants/node_modules/node-bluetooth/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/usr/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/home/fennia/.cache/node-gyp/14.4.0/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/home/fennia/.cache/node-gyp/14.4.0',
gyp info spawn args '-Dnode_gyp_dir=/usr/lib/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/home/fennia/.cache/node-gyp/14.4.0/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/home/fennia/restaurants/node_modules/node-bluetooth',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/home/fennia/restaurants/node_modules/node-bluetooth/build'
CXX(target) Release/obj.target/BluetoothSerialPort/src/linux/BluetoothSerialPort.o
../src/linux/BluetoothSerialPort.cc:28:14: error: variable or field ‘InitAll’ declared void
void InitAll(Handle exports) {
^~~~~~
../src/linux/BluetoothSerialPort.cc:28:14: error: ‘Handle’ was not declared in this scope
../src/linux/BluetoothSerialPort.cc:28:14: note: suggested alternative: ‘rand_r’
void InitAll(Handle exports) {
^~~~~~
rand_r
../src/linux/BluetoothSerialPort.cc:28:27: error: expected primary-expression before ‘>’ token
void InitAll(Handle exports) {
^
../src/linux/BluetoothSerialPort.cc:28:29: error: ‘exports’ was not declared in this scope
void InitAll(Handle exports) {
^~~~~~~
In file included from ../src/linux/BluetoothSerialPort.cc:13:0:
../src/linux/BluetoothSerialPort.cc:36:34: error: ‘InitAll’ was not declared in this scope
NODE_MODULE(BluetoothSerialPort, InitAll)
^
/home/fennia/.cache/node-gyp/14.4.0/include/node/node.h:729:36: note: in definition of macro ‘NODE_MODULE_X’
(node::addon_register_func) (regfunc),
^~~~~~~
../src/linux/BluetoothSerialPort.cc:36:1: note: in expansion of macro ‘NODE_MODULE’
NODE_MODULE(BluetoothSerialPort, InitAll)
^~~~~~~~~~~
BluetoothSerialPort.target.mk:117: recipe for target 'Release/obj.target/BluetoothSerialPort/src/linux/BluetoothSerialPort.o' failed
make: *** [Release/obj.target/BluetoothSerialPort/src/linux/BluetoothSerialPort.o] Error 1
make: Leaving directory '/home/fennia/restaurants/node_modules/node-bluetooth/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/lib/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack at ChildProcess.emit (events.js:315:20)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
gyp ERR! System Linux 4.15.0-65-generic
gyp ERR! command "/usr/bin/node" "/usr/bin/node-gyp" "configure" "build"
gyp ERR! cwd /home/fennia/restaurants/node_modules/node-bluetooth
gyp ERR! node -v v14.4.0
gyp ERR! node-gyp -v v7.0.0
gyp ERR! not ok

Can somebody help ??
Thanks.

Electron rebuild fails because in electron 5 v8::Handle has not been declared

Electron 5.0.1
electron-rebuild: 1.8.5
Linux x64

In file included from ../src/linux/BluetoothSerialPort.cc:13:
../src/DeviceINQ.h: At global scope:
../src/DeviceINQ.h:49:30: error: ‘v8::Handle’ has not been declared
   49 |         static void Init(v8::Handle<v8::Object> exports);
      |                              ^~~~~~
../src/DeviceINQ.h:49:36: error: expected ‘,’ or ‘...’ before ‘<’ token
   49 |         static void Init(v8::Handle<v8::Object> exports);
      |                                    ^
In file included from ../src/linux/BluetoothSerialPort.cc:14:
../src/BTSerialPortBinding.h:43:30: error: ‘v8::Handle’ has not been declared
   43 |         static void Init(v8::Handle<v8::Object> exports);
      |                              ^~~~~~
../src/BTSerialPortBinding.h:43:36: error: expected ‘,’ or ‘...’ before ‘<’ token
   43 |         static void Init(v8::Handle<v8::Object> exports);
      |                                    ^
../src/linux/BluetoothSerialPort.cc:18:14: error: variable or field ‘InitAll’ declared void
   18 | void InitAll(Handle<Object> exports) {
      |              ^~~~~~
../src/linux/BluetoothSerialPort.cc:18:14: error: ‘Handle’ was not declared in this scope
../src/linux/BluetoothSerialPort.cc:18:27: error: expected primary-expression before ‘>’ token
   18 | void InitAll(Handle<Object> exports) {
      |                           ^
../src/linux/BluetoothSerialPort.cc:18:29: error: ‘exports’ was not declared in this scope
   18 | void InitAll(Handle<Object> exports) {
      |                             ^~~~~~~
In file included from ../src/linux/BluetoothSerialPort.cc:12:
../src/linux/BluetoothSerialPort.cc:23:34: error: ‘InitAll’ was not declared in this scope
   23 | NODE_MODULE(BluetoothSerialPort, InitAll)
      |                                  ^~~~~~~

https://electronjs.org/blog/nodejs-native-addons-and-electron-5

I can successfully compile if I replace all references of v8::Handle with v8::Local

connect problem

Hi this is my error message. how can I solve it? thx!

Found RFCOMM channel for serial port on BRA-801:  1
2018-11-09 21:40:56.290 node[2668:117275] instantiateOnDevice for regular
/Users/ca/Desktop/bluetooth/node_modules/node-bluetooth/lib/connection.js:9
    const self = this;
                 ^

ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor
    at new Connection (/Users/cai/Desktop/bluetooth/node_modules/node-bluetooth/lib/connection.js:9:18)
    at /Users/cai/Desktop/bluetooth/node_modules/node-bluetooth/index.js:18:33

Detecting bluetooth device disconnects/crashes

Hi!
I couldn't find a way to detect if a connection has crashed or disconnected so I tried to implement my own.
In lib/connection.js, I noticed that - if I printed the chunks of the read method - they stop printing as soon as I turn off my bluetooth device; after ~20seconds of apparent frozen behavior, this method continued working, printing chunks of zero length buffers.
Thus, I added the following line
if(chunk.length == 0){ self.emit('error')}
in

(function read(){
      self.isOpen() && self.port.read((err, chunk) => {
        process.nextTick(read);
        if(err) return self.emit('error', err);
        self.emit('data', chunk);
        if(chunk.length == 0){ self.emit('error')}
      });
    })();

This allows me to fetch error events like so:

    connect(address, 1, (err, linkage) => {
      if (err) {
        console.log('connection attempt error');
      } else {
        linkage.on('error', (err) => {
          console.log('disconnected!);
        });
      }
    )}

However my approach assumes I won't be receiving zero length buffers when connected which I realize that might not always be true (or not for all devices);
Also, any thoughts on how to detect the disconnect before the ~20seconds pass?
Thanks!

electron-rebuild fails

  • os x 10.13.6
  • electron 3.0.11
  • electron-rebuild 1.8.2
$ NODE_ENV=development electron-rebuild && electron src/index

An unhandled error occurred inside electron-rebuild
  CXX(target) Release/obj.target/BluetoothSerialPort/src/osx/DeviceINQ.o
In file included from ../src/osx/DeviceINQ.mm:14:
../node_modules/nan/nan.h:1081:96: error: too many arguments to function call, expected at most 4, have5
        length_ = string->WriteUtf8(v8::Isolate::GetCurrent(), str_, static_cast<int>(len), 0, flags);
                  ~~~~~~~~~~~~~~~~~                                                            ^~~~~
/Users/daniellizik/.electron-gyp/.node-gyp/iojs-3.0.11/deps/v8/include/v8.h:2590:3: note: 'WriteUtf8' declared here
  int WriteUtf8(char* buffer,
  ^
../src/osx/DeviceINQ.mm:75:16: warning: 'Call' is deprecated [-Wdeprecated-declarations]
        found->Call(2, argv);
               ^
../node_modules/nan/nan.h:1657:3: note: 'Call' has been explicitly marked deprecated here
  NAN_DEPRECATED inline v8::Local<v8::Value>
  ^
../node_modules/nan/nan.h:103:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
../src/osx/DeviceINQ.mm:78:15: warning: 'Call' is deprecated [-Wdeprecated-declarations]
    callback->Call(0, 0);
              ^
../node_modules/nan/nan.h:1657:3: note: 'Call' has been explicitly marked deprecated here
  NAN_DEPRECATED inline v8::Local<v8::Value>
  ^
../node_modules/nan/nan.h:103:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
../src/osx/DeviceINQ.mm:109:16: warning: 'Call' is deprecated [-Wdeprecated-declarations]
    baton->cb->Call(1, argv);
               ^
../node_modules/nan/nan.h:1657:3: note: 'Call' has been explicitly marked deprecated here
  NAN_DEPRECATED inline v8::Local<v8::Value>
  ^
../node_modules/nan/nan.h:103:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
../src/osx/DeviceINQ.mm:228:16: warning: 'Call' is deprecated [-Wdeprecated-declarations]
        found->Call(2, argv);
               ^
../node_modules/nan/nan.h:1657:3: note: 'Call' has been explicitly marked deprecated here
  NAN_DEPRECATED inline v8::Local<v8::Value>
  ^
../node_modules/nan/nan.h:103:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
../src/osx/DeviceINQ.mm:231:15: warning: 'Call' is deprecated [-Wdeprecated-declarations]
    callback->Call(0, 0);
              ^
../node_modules/nan/nan.h:1657:3: note: 'Call' has been explicitly marked deprecated here
  NAN_DEPRECATED inline v8::Local<v8::Value>
  ^
../node_modules/nan/nan.h:103:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
../src/osx/DeviceINQ.mm:246:23: warning: 'Utf8Value' is deprecated [-Wdeprecated-declarations]
    String::Utf8Value address(info[0]);
                      ^
/Users/daniellizik/.electron-gyp/.node-gyp/iojs-3.0.11/deps/v8/include/v8.h:2819:5: note: 'Utf8Value' has been explicitly marked deprecated here
    V8_DEPRECATED("Use Isolate version",
    ^
/Users/daniellizik/.electron-gyp/.node-gyp/iojs-3.0.11/deps/v8/include/v8config.h:321:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated))

javascript error when closing connection

(first, thanks for developing this library, the on to the bug)

after successfully connecting to a device, whenever .close() is called on the connection object, an error occurs:

A Javascript error occurred in the main process.
Uncaught exception: Error: Error reading from connection

ChannelId -1

Hello there,

Whenever i try to run the example, this error comes up:
/home/pi/node-bluetooth/node_modules/node-bluetooth/index.js:18
const port = new BTSerialPortBinding(address, channel, function (err) {
^

TypeError: ChannelID should be a positive int value.
at Function.connect (/home/pi/node-bluetooth/node_modules/node-bluetooth/index.js:18:18)
at /home/pi/node-bluetooth/script.js:17:15

How can i solve this?

Greetings,
Bart

example/index.js: Segmentation fault

Reproduced on node-blueooth v1.2.6 running in a container

  • Official Docker image node:10.17
  • node v10.17.0
  • Debian GNU/Linux 9 (stretch)
root@1fe89f7b3fe0:/app/node_modules/node-bluetooth# node --version
v10.17.0
root@1fe89f7b3fe0:/app/node_modules/node-bluetooth# node example/index.js
Segmentation fault
root@1fe89f7b3fe0:/app/node_modules/node-bluetooth#

Receiving

This is a really nice library. I notice in the example you've sent data to the bluetooth device. Do you know if it is possible to receive data FROM the bluetooth device?? Thanks!

Travis test fail becaise of missing bluetooth.h

I get `

[email protected] install /home/travis/build/frankjoke/ioBroker.radar2/node_modules/node-bluetooth
node-gyp configure build
make: Entering directory /home/travis/build/frankjoke/ioBroker.radar2/node_modules/node-bluetooth/build' CXX(target) Release/obj.target/BluetoothSerialPort/src/linux/BluetoothSerialPort.o CXX(target) Release/obj.target/BluetoothSerialPort/src/linux/DeviceINQ.o ../src/linux/DeviceINQ.cc:35:37: fatal error: bluetooth/bluetooth.h: No such file or directory #include <bluetooth/bluetooth.h> ^ compilation terminated. make: *** [Release/obj.target/BluetoothSerialPort/src/linux/DeviceINQ.o] Error 1 make: Leaving directory /home/travis/build/frankjoke/ioBroker.radar2/node_modules/node-bluetooth/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2`

errors and cannot test my package on Travis (for linuix) but on Raspian and Ubuntu install works.

The error is: /src/linux/DeviceINQ.cc:35:37: fatal error: bluetooth/bluetooth.h
and I could not find it as well.

On windows tester AppVeyor the installation works and all tests passes.

The effect started when I added your package to mine. If I remove the dependency it's installing fine.

Feature Request: Expose RSSI

For proximity it would be useful to have the RSSI value exposed. It should be possible to listen to changes of the RSSI.

Unable to install package

Working on an Electron JS app for linux.
Followed the installation process given in about page, getting following errors while installing the package unable to proceed further.

> [email protected] install /home/user/Documents/electronjs/bluetooth_test/node_modules/node-bluetooth
> node-gyp configure build

make: Entering directory '/home/user/Documents/electronjs/bluetooth_test/node_modules/node-bluetooth/build'
  CXX(target) Release/obj.target/BluetoothSerialPort/src/linux/BluetoothSerialPort.o
../src/linux/BluetoothSerialPort.cc:18:14: error: variable or field ‘InitAll’ declared void
 void InitAll(Handle<Object> exports) {
              ^
../src/linux/BluetoothSerialPort.cc:18:14: error: ‘Handle’ was not declared in this scope
../src/linux/BluetoothSerialPort.cc:18:27: error: expected primary-expression before ‘>’ token
 void InitAll(Handle<Object> exports) {
                           ^
../src/linux/BluetoothSerialPort.cc:18:29: error: ‘exports’ was not declared in this scope
 void InitAll(Handle<Object> exports) {
                             ^
In file included from ../src/linux/BluetoothSerialPort.cc:12:0:
../src/linux/BluetoothSerialPort.cc:23:34: error: ‘InitAll’ was not declared in this scope
 NODE_MODULE(BluetoothSerialPort, InitAll)
                                  ^
/home/user/.cache/node-gyp/12.8.1/include/node/node.h:556:36: note: in definition of macro ‘NODE_MODULE_X’
       (node::addon_register_func) (regfunc),                          \
                                    ^
../src/linux/BluetoothSerialPort.cc:23:1: note: in expansion of macro ‘NODE_MODULE’
 NODE_MODULE(BluetoothSerialPort, InitAll)
 ^
BluetoothSerialPort.target.mk:115: recipe for target 'Release/obj.target/BluetoothSerialPort/src/linux/BluetoothSerialPort.o' failed
make: *** [Release/obj.target/BluetoothSerialPort/src/linux/BluetoothSerialPort.o] Error 1
make: Leaving directory '/home/user/Documents/electronjs/bluetooth_test/node_modules/node-bluetooth/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/home/user/.nvm/versions/node/v12.8.1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:196:23)
gyp ERR! stack     at ChildProcess.emit (events.js:203:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Linux 4.15.0-66-generic
gyp ERR! command "/home/user/.nvm/versions/node/v12.8.1/bin/node" "/home/user/.nvm/versions/node/v12.8.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /home/user/Documents/electronjs/bluetooth_test/node_modules/node-bluetooth
gyp ERR! node -v v12.8.1
gyp ERR! node-gyp -v v5.0.3
gyp ERR! not ok 
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp configure build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

OS - Ubuntu 16.04
Node - 12.8.1
NPM - 6.10.2
Electron JS - 7.0.1
Node-gyp - 5.0.3

node-bluetooth causing build error

Environments :

  • Windows 10 version 1903
  • Visual Studio Enterprise 2019
  • Python 2.7
  • node v12.9.1
  • node-gyp v5.0.3

The problem
I was trying to use ESCPOS_2.5.2 when node-gyp start building the ( node-bluetooth ) module, warnings and errors start to pop on the console till

gyp ERR! build error
gyp ERR! stack Error: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe" failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Users\xxxx\AppData\Roaming\npm\node_modules\node-gyp\lib\build.js:196:23)
gyp ERR! stack at ChildProcess.emit (events.js:209:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\xxxx\AppData\Roaming\npm\node_modules\node-gyp\bin\node-gyp.js" "configure" "build"
gyp ERR! cwd D:_Node_field\pos_printer\node_modules\node-bluetooth
gyp ERR! node -v v12.9.1
gyp ERR! node-gyp -v v5.0.3
gyp ERR! not ok
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\node-bluetooth):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: node-gyp configure build
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status

is something with the environment causing the problem?

Error: The connection has been closed

Thank First

code in example works with Elelctron, but when I shutdown my bluetooth device, it repeats like..........

Error: The connection has been closed
    at read (/Users/project/node_modules/node-bluetooth/lib/connection.js:14:34)
    at process._tickCallback (internal/process/next_tick.js:61:11)
Error: The connection has been closed
    at read (/Users/project/node_modules/node-bluetooth/lib/connection.js:14:34)
    at process._tickCallback (internal/process/next_tick.js:61:11)
Error: The connection has been closed
    at read (/Users/project/node_modules/node-bluetooth/lib/connection.js:14:34)
    at process._tickCallback (internal/process/next_tick.js:61:11)
Error: The connection has been closed
    at read (/Users/project/node_modules/node-bluetooth/lib/connection.js:14:34)
    at process._tickCallback (internal/process/next_tick.js:61:11)
Error: The connection has been closed
    at read (/Users/project/node_modules/node-bluetooth/lib/connection.js:14:34)
    at process._tickCallback (internal/process/next_tick.js:61:11)
Error: The connection has been closed
    at read (/Users/project/node_modules/node-bluetooth/lib/connection.js:14:34)
    at process._tickCallback (internal/process/next_tick.js:61:11)

Failed to install on Mac

Tried to downgrade nan as per #38 with no luck.

> [email protected] install /Users/extempl/Projects/escpos/node_modules/node-bluetooth
> node-gyp configure build

  CXX(target) Release/obj.target/BluetoothSerialPort/src/osx/DeviceINQ.o
../src/osx/DeviceINQ.mm:75:16: warning: 'Call' is deprecated [-Wdeprecated-declarations]
        found->Call(2, argv);
               ^
../../nan/nan.h:1739:3: note: 'Call' has been explicitly marked deprecated here
  NAN_DEPRECATED inline v8::Local<v8::Value>
  ^
../../nan/nan.h:104:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
../src/osx/DeviceINQ.mm:78:15: warning: 'Call' is deprecated [-Wdeprecated-declarations]
    callback->Call(0, 0);
              ^
../../nan/nan.h:1739:3: note: 'Call' has been explicitly marked deprecated here
  NAN_DEPRECATED inline v8::Local<v8::Value>
  ^
../../nan/nan.h:104:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
../src/osx/DeviceINQ.mm:109:16: warning: 'Call' is deprecated [-Wdeprecated-declarations]
    baton->cb->Call(1, argv);
               ^
../../nan/nan.h:1739:3: note: 'Call' has been explicitly marked deprecated here
  NAN_DEPRECATED inline v8::Local<v8::Value>
  ^
../../nan/nan.h:104:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
../src/osx/DeviceINQ.mm:121:28: error: expected ')'
void DeviceINQ::Init(Handle<Object> target) {
                           ^
../src/osx/DeviceINQ.mm:121:21: note: to match this '('
void DeviceINQ::Init(Handle<Object> target) {
                    ^
../src/osx/DeviceINQ.mm:121:17: error: out-of-line definition of 'Init' does not match any declaration in 'DeviceINQ'
void DeviceINQ::Init(Handle<Object> target) {
                ^~~~
../src/osx/DeviceINQ.mm:133:5: error: use of undeclared identifier 'target'
    target->Set(Nan::New("DeviceINQ").ToLocalChecked(), t->GetFunction());
    ^
../src/osx/DeviceINQ.mm:133:72: error: too few arguments to function call, single argument 'context' was not specified
    target->Set(Nan::New("DeviceINQ").ToLocalChecked(), t->GetFunction());
                                                        ~~~~~~~~~~~~~~ ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8.h:5955:3: note: 'GetFunction' declared here
  V8_WARN_UNUSED_RESULT MaybeLocal<Function> GetFunction(
  ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8config.h:351:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/osx/DeviceINQ.mm:134:5: error: use of undeclared identifier 'target'
    target->Set(Nan::New("DeviceINQ").ToLocalChecked(), t->GetFunction());
    ^
../src/osx/DeviceINQ.mm:134:72: error: too few arguments to function call, single argument 'context' was not specified
    target->Set(Nan::New("DeviceINQ").ToLocalChecked(), t->GetFunction());
                                                        ~~~~~~~~~~~~~~ ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8.h:5955:3: note: 'GetFunction' declared here
  V8_WARN_UNUSED_RESULT MaybeLocal<Function> GetFunction(
  ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8config.h:351:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/osx/DeviceINQ.mm:135:5: error: use of undeclared identifier 'target'
    target->Set(Nan::New("DeviceINQ").ToLocalChecked(), t->GetFunction());
    ^
../src/osx/DeviceINQ.mm:135:72: error: too few arguments to function call, single argument 'context' was not specified
    target->Set(Nan::New("DeviceINQ").ToLocalChecked(), t->GetFunction());
                                                        ~~~~~~~~~~~~~~ ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8.h:5955:3: note: 'GetFunction' declared here
  V8_WARN_UNUSED_RESULT MaybeLocal<Function> GetFunction(
  ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8config.h:351:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/osx/DeviceINQ.mm:136:5: error: use of undeclared identifier 'target'
    target->Set(Nan::New("DeviceINQ").ToLocalChecked(), t->GetFunction());
    ^
../src/osx/DeviceINQ.mm:136:72: error: too few arguments to function call, single argument 'context' was not specified
    target->Set(Nan::New("DeviceINQ").ToLocalChecked(), t->GetFunction());
                                                        ~~~~~~~~~~~~~~ ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8.h:5955:3: note: 'GetFunction' declared here
  V8_WARN_UNUSED_RESULT MaybeLocal<Function> GetFunction(
  ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8config.h:351:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/osx/DeviceINQ.mm:228:16: warning: 'Call' is deprecated [-Wdeprecated-declarations]
        found->Call(2, argv);
               ^
../../nan/nan.h:1739:3: note: 'Call' has been explicitly marked deprecated here
  NAN_DEPRECATED inline v8::Local<v8::Value>
  ^
../../nan/nan.h:104:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
../src/osx/DeviceINQ.mm:231:15: warning: 'Call' is deprecated [-Wdeprecated-declarations]
    callback->Call(0, 0);
              ^
../../nan/nan.h:1739:3: note: 'Call' has been explicitly marked deprecated here
  NAN_DEPRECATED inline v8::Local<v8::Value>
  ^
../../nan/nan.h:104:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
../src/osx/DeviceINQ.mm:246:23: error: no matching constructor for initialization of 'String::Utf8Value'
    String::Utf8Value address(info[0]);
                      ^       ~~~~~~~
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8.h:3009:5: note: candidate constructor not viable: no known conversion from 'v8::Local<v8::Value>' to 'const v8::String::Utf8Value' for
      1st argument
    Utf8Value(const Utf8Value&) = delete;
    ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8.h:3002:5: note: candidate constructor not viable: requires 2 arguments, but 1 was provided
    Utf8Value(Isolate* isolate, Local<v8::Value> obj);
    ^
../src/osx/DeviceINQ.mm:297:20: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
        deviceObj->Set(Nan::New("name").ToLocalChecked(), Nan::New([device.nameOrAddress UTF8String]).ToLocalChecked());
                   ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8.h:3365:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/osx/DeviceINQ.mm:298:20: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
        deviceObj->Set(Nan::New("address").ToLocalChecked(), Nan::New([device.addressString UTF8String]).ToLocalChecked());
                   ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8.h:3365:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/osx/DeviceINQ.mm:308:25: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
            serviceObj->Set(Nan::New("channel").ToLocalChecked(), Nan::New((int)channelID));
                        ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8.h:3365:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/osx/DeviceINQ.mm:311:29: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
                serviceObj->Set(Nan::New("name").ToLocalChecked(), Nan::New([[service getServiceName] UTF8String]).ToLocalChecked());
                            ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8.h:3365:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/osx/DeviceINQ.mm:313:29: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
                serviceObj->Set(Nan::New("name").ToLocalChecked(), Nan::Undefined());
                            ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8.h:3365:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/osx/DeviceINQ.mm:315:28: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
            servicesArray->Set(j, serviceObj);
                           ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8.h:3374:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/osx/DeviceINQ.mm:317:20: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
        deviceObj->Set(Nan::New("services").ToLocalChecked(), servicesArray);
                   ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8.h:3365:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/osx/DeviceINQ.mm:319:22: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
        resultArray->Set(i, deviceObj);
                     ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8.h:3374:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON("Use maybe version",
  ^
/Users/extempl/Library/Caches/node-gyp/12.7.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
../src/osx/DeviceINQ.mm:325:9: error: too few arguments to function call, expected 4, have 3; did you mean 'Nan::Call'?
    cb->Call(Nan::GetCurrentContext()->Global(), 1, argv);
        ^~~~
        Nan::Call
../../nan/nan_maybe_43_inl.h:345:30: note: 'Nan::Call' declared here
inline MaybeLocal<v8::Value> Call(
                             ^
13 warnings and 12 errors generated.
make: *** [Release/obj.target/BluetoothSerialPort/src/osx/DeviceINQ.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/extempl/.nvm/versions/node/v12.7.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:203:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Darwin 18.7.0
gyp ERR! command "/Users/extempl/.nvm/versions/node/v12.7.0/bin/node" "/Users/extempl/.nvm/versions/node/v12.7.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /Users/extempl/Projects/escpos/node_modules/node-bluetooth
gyp ERR! node -v v12.7.0
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok 

Battery status?

Hi, I skimmed thru the repo, but I have not seen a way to check the battery status of a BT device, is that even possible?

Can't install in Windows

I've already installed the node-gyp
then try to run npm install node-bluetooth --save
but I got this error.

gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:210:5)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Windows_NT 10.0.17763
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "build"
gyp ERR! cwd C:\Users\MonstaX\Downloads\Compressed\node-bluetooth-master
gyp ERR! node -v v12.13.0
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `prebuild-install || node-gyp configure build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\MonstaX\AppData\Roaming\npm-cache\_logs\2019-11-13T11_24_01_389Z-debug.log

Finding specific devices

If I know the MAC address of a BT device that is not paired to the host (and not in pairing mode) can I use this library to determine if it is present?

As far as I can tell it would not be able to do this.

Receive buffer full of all data

Hello! thank you for sharing this, it is great. i noticed that if an application is not reading from the bt client the serial receive buffer accumulates a ton of data. is there a way to invoke a flush on startup?

thank you.

cannot read property, ...

Trying this on raspbian. Node v11.2. Using the standard example.

`Found: 30:AE:A4:24:C1:EE with name ESP32test
finished
Found RFCOMM channel for serial port on ESP32test: 1
/home/pi/node_modules/node-bluetooth/lib/connection.js:13
this.isOpen() && this.port.read((err, chunk) => {
^

TypeError: Cannot read property 'isOpen' of undefined
at read (/home/pi/node_modules/node-bluetooth/lib/connection.js:13:12)
at new Connection (/home/pi/node_modules/node-bluetooth/lib/connection.js:18:7)
at /home/pi/node_modules/node-bluetooth/index.js:19:33
`

Install not working on OSX Node12

➜  bluetooth node-gyp build                          
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | darwin | x64
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: *** No rule to make target `Release/obj.target/BluetoothSerialPort/src/osx/DeviceINQ.o', needed by `Release/BluetoothSerialPort.node'.  Stop.
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/node-gyp/lib/build.js:196:23)
gyp ERR! stack     at ChildProcess.emit (events.js:203:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Darwin 18.6.0
gyp ERR! command "/usr/local/Cellar/node/12.6.0/bin/node" "/usr/local/bin/node-gyp" "build"
gyp ERR! cwd /Development/Node/bluetooth
gyp ERR! node -v v12.6.0
gyp ERR! node-gyp -v v5.0.3
gyp ERR! not ok 
➜  bluetooth 

Cant install On windows

I've installed node-gyp succesfuly but when installing node-bluetooth this is the following output :
gyp ERR! build error
gyp ERR! stack Error: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:194:23)
gyp ERR! stack at ChildProcess.emit (events.js:210:5)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "configure" "build"
gyp ERR! cwd C:\Users\marou\Documents\OSC\Node\node_modules\node-bluetooth
gyp ERR! node -v v12.13.1
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\xpc-connection):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node-gyp configure build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\marou\AppData\Roaming\npm-cache_logs\2020-09-09T10_17_15_477Z-debug.log

Not working with Electron App

I am trying to make an app that uses the node-bluetooth module found in npm. But I am getting the following error :

App threw an error during load
Error: The module '/home/pi/AlucentOs/node_modules/node- 
bluetooth/build/Release/BluetoothSerialPort.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 57. This version of Node.js requires
NODE_MODULE_VERSION 64. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
at process.module.(anonymous function) [as dlopen] 
(ELECTRON_ASAR.js:166:20)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:740:18)
at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:166:20)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:559:12)
at Function.Module._load (internal/modules/cjs/loader.js:551:3)
at Module.require (internal/modules/cjs/loader.js:658:17)
at require (internal/modules/cjs/helpers.js:20:18)
at bindings (/home/pi/AlucentOs/node_modules/bindings/bindings.js:76:44)
at Object.<anonymous> (/home/pi/AlucentOs/node_modules/node- 
bluetooth/index.js:3:48)

I have tryed deleting node_modules file, and reinstalling everything, but it doesn't work. I am running the following line :

 electron .

Package.json:

 {
  "name": "alucentos",
  "version": "1.0.0",
  "description": "AlucentX Operating System",
  "main": "index.js",
  "scripts": {
  "start": "electron .",
 },
 "author": "meddahAbdallah",
 "license": "ISC",
 "devDependencies": {
 "electron": "^4.1.2",
 "node-bluetooth": "^1.2.5"
 },
 "dependencies": {
 "node-bluetooth": "^1.2.5"
 }
}

MacOS High Sierra build issue

When the module is built by node-gyp there are many deprecations that result on errors while connecting.

> [email protected] install /Users/sarriaroman/Dropbox/Desarrollo/Payments/POCs/btdevice/node_modules/node-bluetooth
> node-gyp configure build

  CXX(target) Release/obj.target/BluetoothSerialPort/src/osx/DeviceINQ.o
../src/osx/DeviceINQ.mm:68:16: warning: 'Call' is deprecated [-Wdeprecated-declarations]
    baton->cb->Call(1, argv);
               ^
../../nan/nan.h:1617:3: note: 'Call' has been explicitly marked deprecated here
  NAN_DEPRECATED inline v8::Local<v8::Value>
  ^
../../nan/nan.h:98:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
../src/osx/DeviceINQ.mm:145:18: warning: 'MakeCallback' is deprecated [-Wdeprecated-declarations]
            Nan::MakeCallback(info.This(), "emit", 3, argv);
                 ^
../../nan/nan.h:971:3: note: 'MakeCallback' has been explicitly marked deprecated here
  NAN_DEPRECATED inline v8::Local<v8::Value> MakeCallback(
  ^
../../nan/nan.h:98:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
../src/osx/DeviceINQ.mm:156:10: warning: 'MakeCallback' is deprecated [-Wdeprecated-declarations]
    Nan::MakeCallback(info.This(), "emit", 1, argv);
         ^
../../nan/nan.h:971:3: note: 'MakeCallback' has been explicitly marked deprecated here
  NAN_DEPRECATED inline v8::Local<v8::Value> MakeCallback(
  ^
../../nan/nan.h:98:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
3 warnings generated.
  CXX(target) Release/obj.target/BluetoothSerialPort/src/osx/BluetoothWorker.o
../src/osx/BluetoothWorker.mm:117:39: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
    keepAliveTimer = [[NSTimer alloc] initWithFireDate:[NSDate distantFuture]
                                      ^
../src/osx/BluetoothWorker.mm:117:39: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
    keepAliveTimer = [[NSTimer alloc] initWithFireDate:[NSDate distantFuture]
                                      ^
../src/osx/BluetoothWorker.mm:359:57: warning: 'getAddressString' is deprecated: first deprecated in macOS 10.7 [-Wdeprecated-declarations]
        [self disconnectFromDevice: [[rfcommChannel getDevice] getAddressString]];
                                                               ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/IOBluetooth.framework/Headers/objc/IOBluetoothDevice.h:477:1: note: 'getAddressString' has been explicitly
      marked deprecated here
- (NSString *)getAddressString DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
^
../src/osx/BluetoothWorker.mm:380:35: warning: 'getAddressString' is deprecated: first deprecated in macOS 10.7 [-Wdeprecated-declarations]
                        strcpy(info->address, [[device getAddressString] UTF8String]);
                                                       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/IOBluetooth.framework/Headers/objc/IOBluetoothDevice.h:477:1: note: 'getAddressString' has been explicitly
      marked deprecated here
- (NSString *)getAddressString DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;
^
../src/osx/BluetoothWorker.mm:381:32: warning: 'getNameOrAddress' is deprecated: first deprecated in macOS 10.6 [-Wdeprecated-declarations]
                        strcpy(info->name, [[device getNameOrAddress] UTF8String]);
                                                    ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/IOBluetooth.framework/Headers/objc/IOBluetoothDevice.h:448:1: note: 'getNameOrAddress' has been explicitly
      marked deprecated here
- (NSString *)getNameOrAddress DEPRECATED_IN_MAC_OS_X_VERSION_10_6_AND_LATER;
^
5 warnings generated.
  CC(target) Release/obj.target/BluetoothSerialPort/src/osx/pipe.o
  CXX(target) Release/obj.target/BluetoothSerialPort/src/osx/BluetoothDeviceResources.o
  CXX(target) Release/obj.target/BluetoothSerialPort/src/osx/BluetoothSerialPort.o
  CXX(target) Release/obj.target/BluetoothSerialPort/src/osx/BTSerialPortBinding.o
../src/osx/BTSerialPortBinding.mm:79:20: warning: 'Call' is deprecated [-Wdeprecated-declarations]
        baton->cb->Call(0, NULL);
                   ^
../../nan/nan.h:1617:3: note: 'Call' has been explicitly marked deprecated here
  NAN_DEPRECATED inline v8::Local<v8::Value>
  ^
../../nan/nan.h:98:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
../src/osx/BTSerialPortBinding.mm:84:21: warning: 'Call' is deprecated [-Wdeprecated-declarations]
        baton->ecb->Call(1, argv);
                    ^
../../nan/nan.h:1617:3: note: 'Call' has been explicitly marked deprecated here
  NAN_DEPRECATED inline v8::Local<v8::Value>
  ^
../../nan/nan.h:98:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
../src/osx/BTSerialPortBinding.mm:131:21: warning: 'Call' is deprecated [-Wdeprecated-declarations]
    data->callback->Call(2, argv);
                    ^
../../nan/nan.h:1617:3: note: 'Call' has been explicitly marked deprecated here
  NAN_DEPRECATED inline v8::Local<v8::Value>
  ^
../../nan/nan.h:98:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
../src/osx/BTSerialPortBinding.mm:190:57: warning: 'NewInstance' is deprecated [-Wdeprecated-declarations]
        Local<Object> resultBuffer = bufferConstructor->NewInstance(1, constructorArgs);
                                                        ^
/Users/sarriaroman/.node-gyp/8.11.1/include/node/v8.h:3846:3: note: 'NewInstance' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/sarriaroman/.node-gyp/8.11.1/include/node/v8config.h:321:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated))
                            ^
../src/osx/BTSerialPortBinding.mm:197:16: warning: 'Call' is deprecated [-Wdeprecated-declarations]
    baton->cb->Call(2, argv);
               ^
../../nan/nan.h:1617:3: note: 'Call' has been explicitly marked deprecated here
  NAN_DEPRECATED inline v8::Local<v8::Value>
  ^
../../nan/nan.h:98:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
../src/osx/BTSerialPortBinding.mm:357:13: warning: 'Call' is deprecated [-Wdeprecated-declarations]
        nc->Call(2, argv);
            ^
../../nan/nan.h:1617:3: note: 'Call' has been explicitly marked deprecated here
  NAN_DEPRECATED inline v8::Local<v8::Value>
  ^
../../nan/nan.h:98:40: note: expanded from macro 'NAN_DEPRECATED'
# define NAN_DEPRECATED __attribute__((deprecated))
                                       ^
6 warnings generated.
  SOLINK_MODULE(target) Release/BluetoothSerialPort.node

Receiving Connections

I know there's a way to receive data from a device that I'm already connected to, but I haven't be able to find a way to get a connection object for a received connection. Is there some event that I'm missing in the device object, or is this feature simply not out yet? I may just be missing some obvious portion of the docs, but I would appreciate some information.

Thanks

node-gyp

Pls, add a node-gyp dependence in readme.

How to solve the problem of Chinese garbled

����3s
bluetooth1.1.js:19 Found: 1C:CD:E5:8C:05:88 with name ����3s1
bluetooth1.1.js:18 RG-BLE-22
bluetooth1.1.js:19 Found: 1E:03:E0:81:39:BB with name RG-BLE-222
events.js:86 finished

BLE connection problem

Hi @song940 .
I'm using node-bluetooth package to transmit data via laptop Bluetooth and I've successfully transmitted data to an ordinary hc-05 Bluetooth device. When I list all available devices, it shows all of the paired Bluetooth devices even if they're not physically available at the time EXCEPT for an MLT-BT05 BLE device which is also already paired in windows Bluetooth settings.
Is this package compatible with BLE?
If it's not what package do you recommend to communicate with BLE devices?

Thank in advance.

TypeError: this.port.on is not a function

I tired this module. Just run an example on OSX Sierra (10.12.5) and got the following error while connecting to the device. Any help with this?

Found: 00-06-66-80-d2-94 with name RNBT-D294
2017-07-25 21:16:46.682 node[2148:28121] Update serviceMask RNBT-D294 0
finished
Found RFCOMM channel for serial port on RNBT-D294:  1
/Users/poly/ws/node-bluetooth-master/index.js:21
  this.port.on('data', function(buffer){
            ^

TypeError: this.port.on is not a function
    at new Connection (/Users/poly/ws/node-bluetooth-master/index.js:21:13)
    at /Users/poly/ws/node-bluetooth-master/index.js:80:31

close connection on macos

Very nice interface. Much better then bluetooth-serial-port. Thanks for this library.

This is interface of connection close:

  Connection.prototype.close = function(callback)

As I see from native code, callback in fact is address. The problem comes because connection closed event never happens.

Installation Python and Gyp Error

I have python-3.7.2-amd64 and node-gyp installed (global), when I try to install the module with:
npm install node-bluetooth --save

I receive the following errors:

C:\Projects\BluetoothServer\node_modules\node-bluetooth>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\....\node_modules\node-gyp\bin\node-gyp.js" configure build ) else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" configure build )
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\Users\Marcelo\AppData\Local\Programs\Python\Python37\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack File "", line 1
gyp ERR! stack import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack ^
gyp ERR! stack SyntaxError: invalid syntax

gyp ERR! stack
gyp ERR! stack at ChildProcess.exithandler (child_process.js:276:12)
gyp ERR! stack at emitTwo (events.js:126:13)
gyp ERR! stack at ChildProcess.emit (events.js:214:7)
gyp ERR! stack at maybeClose (internal/child_process.js:915:16)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "configure" "build"
gyp ERR! cwd C:\Projects\BluetoothServer\node_modules\node-bluetooth
gyp ERR! node -v v8.12.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN enoent ENOENT: no such file or directory, open 'C:\Projects\BluetoothServer\package.json'
npm WARN BluetoothServer No description
npm WARN BluetoothServer No repository field.
npm WARN BluetoothServer No README data
npm WARN BluetoothServer No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node-gyp configure build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Marcelo\AppData\Roaming\npm-cache_logs\2019-03-08T20_35_51_000Z-debug.log

C:\Projects\BluetoothServer>path
PATH=C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client;C:\Program Files\Intel\iCLS Client;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Acer ProShield;C:\Program Files\Acer ProShield\x86;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Amazon\AWSCLI;C:\Program Files\PuTTY;C:\Program Files\nodejs;C:\Users\Marcelo\AppData\Local\Programs\Python\Python37\Scripts;C:\Users\Marcelo\AppData\Local\Programs\Python\Python37;C:\Users\Marcelo\AppData\Local\Microsoft\WindowsApps;C:\Users\Marcelo\AppData\Roaming\npm

C:\Projects\BluetoothServer>
C:\Projects\BluetoothServer>npm i node-bluetooth

[email protected] install C:\Projects\BluetoothServer\node_modules\node-bluetooth
node-gyp configure build

C:\Projects\BluetoothServer\node_modules\node-bluetooth>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\....\node_modules\node-gyp\bin\node-gyp.js" configure build ) else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" configure build )
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\Users\Marcelo\AppData\Local\Programs\Python\Python37\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack File "", line 1
gyp ERR! stack import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack at ChildProcess.exithandler (child_process.js:276:12)
gyp ERR! stack at emitTwo (events.js:126:13)
gyp ERR! stack at ChildProcess.emit (events.js:214:7)
gyp ERR! stack at maybeClose (internal/child_process.js:915:16)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "configure" "build"
gyp ERR! cwd C:\Projects\BluetoothServer\node_modules\node-bluetooth
gyp ERR! node -v v8.12.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN enoent ENOENT: no such file or directory, open 'C:\Projects\BluetoothServer\package.json'
npm WARN BluetoothServer No description
npm WARN BluetoothServer No repository field.
npm WARN BluetoothServer No README data
npm WARN BluetoothServer No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node-gyp configure build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Marcelo\AppData\Roaming\npm-cache_logs\2019-03-08T20_41_44_146Z-debug.log

NULLing out io_service_t. Error: Cannot connect

Got this error trying to connect to an iPhone.

2017-07-25 20:24:39.900 node[50282:2060186] [establishKernelConnection] Received an error from IOServiceOpen() - 0xe00002c7.  NULLing out io_service_t.
Error: Cannot connect

Here is my code.

    device
        .on('finished', console.log.bind(console, 'finished'))
        .on('found', function found(address, name) {

            console.log('Found: ' + address + ' with name ' + name);

            // find serial port channel
            device.findSerialPortChannel(address, (channel) => {
                console.log('Found RFCOMM channel for serial port on %s: ', name, channel);

                // make bluetooth connect to remote device
                bluetooth.connect(address, channel, (err, connection) => {
                    if (err) return console.error(err);

                    connection.on('data', (buffer) => {
                        console.log('received message:', buffer.toString());
                    });

                    connection.write(new Buffer('Hello!', 'utf-8'), () => {
                        console.log('wrote');
                    });
                });

            });

        }).inquire();

Missing symbol?

Hey, I'm trying to make an electron app that searches for bluetooth devices as a test to see if I can get it to work, but I get this error when running my code.

dyld: lazy symbol binding failed: Symbol not found: __ZN2v811HandleScope12CreateHandleEPNS_8internal10HeapObjectEPNS1_6ObjectE
  Referenced from: /Volumes/HaydenDrive/Code/Personal/Applications/Bluetooth/node_modules/node-bluetooth/build/Release/BluetoothSerialPort.node
  Expected in: flat namespace

I'm not entirely sure what to do, as I've only just built the package using NPM.
I'm running macOS 10.14.03, using the v4.0 of electron.

Here's my code in the js file linked to my index.html:

    const bl = require('node-bluetooth');
    const device = new bl.DeviceINQ();
    device
        .on('finished',  console.log.bind(console, 'finished'))
        .on('found', function found(address, name){
            let row = deviceTable.insertRow()
            let devName = row.insertCell(0);
            let devMAC = row.insertCell(1);
            devName.innerHTML = name;
            devMAC.innerHTML = address;
        }).scan();

connectivity problems

I have tested om Mac with High Sierra.

When bt connection is lost error event is emitted with message "The connection has been closed", but never emitted closed event.

Also have problems with inquire() method. It freezes my app and the only way is to kill the process. There are not any reported errors. Anyhow inquire should be async.

How to connect this with my mobile bluetooth terminal?

Its showing connected to mobile device but, it is not showing the buffer values in my mobile device, i used all the apps but the buffer value that is sent from my laptop to my mobile is not showing, it keeps pushing the data to the mobile, but in mobile it is not visible.

Installation Fails

Tried this many times, cannot install and the error logs don't really tell me anything !

Any idea what may be the cause ?

/root/.node-gyp/10.10.0/include/node/v8.h: In instantiation of 'void v8::PersistentBase<T>::SetWeak(P*, typename v8::WeakCallbackInfo<P>::Callback, v8::WeakCallbackType) [with P = Nan::ObjectWrap; T = v8::Object; typename v8::WeakCallbackInfo<P>::Callback = void (*)(const v8::WeakCallbackInfo<Nan::ObjectWrap>&)]':
../../nan/nan_object_wrap.h:66:61:   required from here
/root/.node-gyp/10.10.0/include/node/v8.h:9496:16: warning: cast between incompatible function types from 'v8::WeakCallbackInfo<Nan::ObjectWrap>::Callback' {aka 'void (*)(const v8::WeakCallbackInfo<Nan::ObjectWrap>&)'} to 'Callback' {aka 'void (*)(const v8::WeakCallbackInfo<void>&)'} [-Wcast-function-type]
make: *** [BluetoothSerialPort.target.mk:107: Release/obj.target/BluetoothSerialPort/src/linux/BTSerialPortBinding.o] Error 1
make: Leaving directory '/usr/share/nodejs/nwjs-sdk/node_modules/node-bluetooth/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System Linux 4.14.69-1-lts
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /usr/share/nodejs/nwjs-sdk/node_modules/node-bluetooth
gyp ERR! node -v v10.10.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp configure build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-09-17T04_41_19_346Z-debug.log

How can I know if the connection is always open ?

Hi,

For beginning thank you for this node module :).

I have an electron program that open a bluetooth connection and listening the event "data".

How can I know if the connection is always open ?

Before write data I check if the connection is open with connection.isOpen() but this method return true if the connection has been open and lost.

I have try to listen the events "closed", "close", "failure" without any success.

If the connection has been open and lost, when I write data I have an uncatched exception:
Error : Error reading from connection.

The calls to the write method is in try/catch block

Node version : v8.12.0
node-bluetooth: v1.2.5

Thank you for your help.

Maintenance status?

Hi,

Are further updates for this software planned or has it essentially been abandoned?

If it is the latter, I filed a request for @abandonware to take over maintenance.

If further updates are planned, please feel free to close this issue and leave a comment in the abandonware project that no transfer is desired.
If you are willing to transfer this project, would you be willing to transfer ownership of this repository?

EDIT: The request is located here: abandonware/abandonware.github.io#13

Connecting to a device with a pin pairing

Im connecting to a HC-06 device that requires a pin to pair.

Before manually pairing, Error: Cannot Connect is thrown
After manually pairing, works like a charm.

Is there any API to assist in pin pairing?

Typo in Bluetooth.connect

index.js:70 reads

    callback(null, new Buletooth.Connection(port));

Buletooth should be Bluetooth.

After changing it seems to work!

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.