Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-beacon-scanner

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-beacon-scanner

The node-beacon-scanner is a Node.js module which allows you to scan BLE beacon packets and parse the packet data. This module supports iBeacon, Eddystone, and Estimote.

  • 0.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

node-beacon-scanner

The node-beacon-scanner is a Node.js module which allows you to scan BLE beacon packets and parse the packet data. This module supports iBeacon, Eddystone, and Estimote.

The supported beacon data formats are as follows:

  • iBeacon
  • Eddystone-UID
  • Eddystone-URL
  • Eddystone-TLM (Unencrypted)
  • Eddystone-EID
  • Estimote-Telemetry
  • Estimote-Nearable

Dependencies

  • Node.js 6 +
  • @abandonware/noble

See the document of the @abandonware/noble for details on installing the @abandonware/noble.

Note that the noble has to be run as root on most of Linux environments. See the the document of the @abandonware/noble for details.

The early versions of this module depended on noble for BLE handling. But the noble seems not to support Node v10 or later versions. Now, this module is employing @abandonware/noble, which was forked from noble. For the purouse of the backward compatibility, this module works with noble on Node v8 or earlier versions.

Installation

$ cd ~
$ npm install @abandonware/noble
$ npm install node-beacon-scanner

Table of Contents


Quick Start

This sample code shows how to start scanning and how to get parsed packets.

const BeaconScanner = require('node-beacon-scanner');
const scanner = new BeaconScanner();

// Set an Event handler for becons
scanner.onadvertisement = (ad) => {
  console.log(JSON.stringify(ad, null, '  '));
};

// Start scanning
scanner.startScan().then(() => {
  console.log('Started to scan.')  ;
}).catch((error) => {
  console.error(error);
});

The sample code above will output the result as follows:

Started to scan.
{
  "id": "c7dfbfd9f64a",
  "address": "c7:df:bf:d9:f6:4a",
  "localName": null,
  "txPowerLevel": null,
  "rssi": -59,
  "beaconType": "iBeacon",
  "iBeacon": {
    "uuid": "B9407F30-F5F8-466E-AFF9-25556B57FE6D",
    "major": 21983,
    "minor": 57807,
    "txPower": 180
  }
}
...

BeaconScanner object

In order to use the node-beacon-scanner, you have to load the node-beacon-scanner module as follows:

const BeaconScanner = require('node-beacon-scanner');

You can get an BeaconScanner constructor from the code above. Then you have to create an BeaconScanner object from the BeaconScanner constructor as follows:

const scanner = new BeaconScanner();

The BeaconScanner constructor takes an argument optionally. It must be a hash object containing the properties as follows:

PropertyTypeRequiredDescription
nobleNobleoptiona Noble object of the noble module

The node-beacon-scanner module uses the noble module in order to scan the beacons coming from the BLE beacon device(s). If you want to interact other BLE devices using the noble module, you can create an Noble object by yourself, then pass it to this module. If you don't specify a Noble object to the noble property, this module automatically create a Noble object internally.

The sample code below shows how to pass a Nobel object to the Linking constructor.

// Create a Noble object
const noble = require('noble');

// Create a Linking object
const BeaconScanner = require('node-beacon-scanner');
const scanner = new BeaconScanner({'noble': noble});

In the code snippet above, the variable scanner is a BeaconScanner object. The BeaconScanner object has methods as described in sections below.

scartScan() method

The startScan() method starts to scan advertising packets from BLE beacon devices. This method returns a Promise object.

Whenever a packet is received, the callback function set to the onadvertisement property of the BeaconScanner object will be called. When a packet is received, an BeaconScannerAdvertisement object will be passed to the callback function.

// Set an Event handler for becons
scanner.onadvertisement = (ad) => {
  console.log(JSON.stringify(ad, null, '  '));
};

// Start scanning
scanner.startScan().then(() => {
  console.log('Started to scan.')  ;
}).catch((error) => {
  console.error(error);
});

stopScan() method

The stopScan() method stops to scan advertising packets from BLE beacon devices. See the section "startScan() method" for details.

onadvertisement event handler

If a callback function is set to the onadvertisement property, the callback function will be called whenever an advertising packet is received from a BLE beacon device during the scan is active (from the moment when the startScan() method is called, to the moment when the stopScan() method is called).

See the section "startScan() method" for details.


BeaconScannerAdvertisement object

The BeaconScannerAdvertisement object represents an advertising data coming from the BLE beacon device. This object is just a hash object containing properties as follows. Note that the structure varies depending on the format of the beacon. You can know the format of the beacon from the value of the beaconType property.

iBeacon

{
  "id": "c7dfbfd9f64a",
  "address": "c7:df:bf:d9:f6:4a",
  "localName": null,
  "txPowerLevel": null,
  "rssi": -59,
  "beaconType": "iBeacon",
  "iBeacon": {
    "uuid": "B9407F30-F5F8-466E-AFF9-25556B57FE6D",
    "major": 21983,
    "minor": 57807,
    "txPower": 180
  }
}

The value of the iBeacon property contains the properties as follows:

PropertyTypeDescription
uuidStringProximity UUID
majorNumberMajor
minorNumberMinor
txPowerNumberMeasured Power (dBm)

Eddystone-UID

{
  "id": "c6debed8f549",
  "address": "c6:de:be:d8:f5:49",
  "localName": null,
  "txPowerLevel": null,
  "rssi": -59,
  "beaconType": "eddystoneUid",
  "eddystoneUid": {
    "txPower": -35,
    "namespace": "EDD1EBEAC04E5DEFA017",
    "instance": "2D3EA3203B6B"
  }
}

The value of the eddystoneUid property contains the properties as follows:

PropertyTypeDescription
namespaceStringNamespace ID
instanceStringInstance ID
txPowerNumberCalibrated Tx power (dBm)

Eddystone-URL

{
  "id": "c6debed8f549",
  "address": "c6:de:be:d8:f5:49",
  "localName": null,
  "txPowerLevel": null,
  "rssi": -59,
  "beaconType": "eddystoneUrl",
  "eddystoneUrl": {
    "txPower": -35,
    "url": "http://go.esti.be/"
  }
}

The value of the eddystoneUrl property contains the properties as follows:

PropertyTypeDescription
urlStringDecoded URL
txPowerNumberCalibrated Tx power (dBm)

Eddystone-TLM (Unencrypted)

{
  "id": "c6debed8f549",
  "address": "c6:de:be:d8:f5:49",
  "localName": null,
  "txPowerLevel": null,
  "rssi": -59,
  "beaconType": "eddystoneTlm",
  "eddystoneTlm": {
    "batteryVoltage": 6059,
    "temperature": 28.59765625,
    "advCnt": 83,
    "secCnt": 361299
  }
}

The value of the eddystoneTlm property contains the properties as follows:

PropertyTypeDescription
batteryVoltageNumberBattery voltage (mV)
temperatureNumberBeacon temperature (°C)
advCntNumberAdvertising PDU count
secCntNumberTime since power-on or reboot

Eddystone-EID

{
  "id": "d9d9fe86fb61",
  "address": "d9:d9:fe:86:fb:61",
  "localName": null,
  "txPowerLevel": null,
  "rssi": -59,
  "beaconType": "eddystoneEid",
  "eddystoneEid": {
    "txPower": -35,
    "eid": "79c58b83f198ddbe"
  }
}

The value of the eddystoneEid property contains the properties as follows:

PropertyTypeDescription
eidStringEphemeral Identifier
txPowerNumberCalibrated Tx power (dBm)

Estimote-Telemetry

There are two types in the Estimote Telemetry beacon data: Type A and Type B. The types can be obtained checking the value of the subFrameType property. If the type is A, the value is 0. If the type is B, the value is 1.

Type A

{
  "id": "c9e1c1dbf84c",
  "address": "c9:e1:c1:db:f8:4c",
  "localName": null,
  "txPowerLevel": null,
  "rssi": -59,
  "beaconType": "estimoteTelemetry",
  "estimoteTelemetry": {
    "frameType": 2,
    "subFrameType": 0,
    "protocolVersion": 2,
    "shortIdentifier": "2d3ea3203b6b2446",
    "acceleration": {
      "x": -0.015748031496062992,
      "y": -0.07874015748031496,
      "z": 0.9921259842519685
    },
    "moving": false,
    "gpio": {
      "pin0": "low",
      "pin1": "low",
      "pin2": "high",
      "pin3": "high"
    },
    "errors": {
      "firmware": false,
      "clock": false
    },
    "pressure": 100304.9765625
  }
}

Type B

{
  "id": "c9e1c1dbf84c",
  "address": "c9:e1:c1:db:f8:4c",
  "localName": null,
  "txPowerLevel": null,
  "rssi": -59,
  "beaconType": "estimoteTelemetry",
  "estimoteTelemetry": {
    "frameType": 2,
    "subFrameType": 1,
    "protocolVersion": 2,
    "shortIdentifier": "2d3ea3203b6b2446",
    "magneticField": {
      "x": 0,
      "y": 0,
      "z": 0
    },
    "light": 80.64,
    "uptime": {
      "unitCode": 1,
      "unitDesc": "minutes",
      "value": 596
    },
    "temperature": 28.75,
    "batteryVoltage": 6059,
    "batteryLevel": 95
  }
}

Estimote-Nearable

{
  "id": "f8d3c05e8001",
  "address": "f8:d3:c0:5e:80:01",
  "localName": null,
  "txPowerLevel": null,
  "rssi": -59,
  "beaconType": "estimoteNearable",
  "estimoteNearable": {
    "nearableId": "bd20de5cd074de8d",
    "temperature": 25.75,
    "moving": false,
    "acceleration": {
      "x": -15.625,
      "y": -78.125,
      "z": -1031.25
    }
  }
}

The value of the estimoteNearable property contains the properties as follows:

PropertyTypeDescription
nearableIdStringNearable identifier
temperatureNumberTemperature (°C)
movingBooleanMoving state (true: moving)
accelerationObjectAcceleration
--xNumberAcceleration on the X axis (milli G)
--yNumberAcceleration on the Y axis (milli G)
--zNumberAcceleration on the Z axis (milli G)

Release Note

  • v0.2.2 (2019-11-24)
  • v0.2.1 (2019-11-02)
  • v0.2.0 (2019-10-25)
  • v0.1.1 (2018-12-27)
    • Fixed the bug that Eddystone beacons were not discovered if iBeacons were present as well. (Thanks to @Tiggu)
  • v0.1.0 (2018-07-14)
  • v0.0.3 (2018-06-24)
    • Fixed a bug that an exception was thrown when an unknown packet came.
  • v0.0.2 (2017-09-15)
    • Fixed a bug that an exception was thrown when an unknown packet came.
  • v0.0.1 (2017-09-06)
    • First public release

References


License

The MIT License (MIT)

Copyright (c) 2017-2019 Futomi Hatano

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.

Keywords

FAQs

Package last updated on 24 Nov 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc