node-hm-ble

0.0.2 • Public • Published

node-hm-ble

Node.js module to provide an easy stream interface to the low cost Huamao Technology CO BLE modules (tested with HM-10). These modules emulate a serial interface over RF.

Installation

Since node-hm-ble relies on the native noble package, you first need to install some dependencies:

$ sudo apt-get install bluetooth bluez-utils libbluetooth-dev

Then you can install node-hm-ble through npm:

$ npm install node-hm-ble

Implementation

The node-hm-ble module provides the BLESerial object. This object is implemented as a stream, allowing easy and familiar integration into node.js.

Import the module with:

> ble = require('node-hm-ble');

You can construct a stream interface to a BLE module with:

> bs = new ble.BLESerial();

If you have multiple HM modules in range and you want to connect to a specific one, you can specify the MAC address of your BLE module like this:

> bs = new ble.BLESerial('001122334455');

Once you have constructed your stream object, you can use it like any other stream as described in node's Stream documentation.

hmsocket

A command line tool called hmsocket is included that provides a socket on port 10191, through which the stream connection to the HM BLE module can be accessed. To use this tool, the module needs to be installed globally:

$ sudo su
$ npm install -g node-hm-ble

Then you can run the tool as root:

$ sudo su
$ hmsocket

Known defects

  • When the BLE connection is severed, and then the socket connection is closed and established again, the BLE connection will not automatically be established when the device comes back online. Closing the socket connection and opening it again seems to fix it.

Package Sidebar

Install

npm i node-hm-ble

Weekly Downloads

3

Version

0.0.2

License

MIT

Last publish

Collaborators

  • xorbit