Skip to content

Commit

Permalink
Released v0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
futomi committed Nov 24, 2019
1 parent 0d3de3f commit 45255b3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 44 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ Property | |Type |Description
---------------------------------------
## <a id="Release-Note">Release Note</a>

* v0.2.2 (2019-11-24)
* Fixed a bug that the `txPower` of iBeacon was wrong. ([Thanks to @girtgirt](https://github.com/futomi/node-beacon-scanner/pull/12))
* Fixed a bug that an exception was thrown whenever it received an advertisement packet without service data. ([Thanks to @charlesread](https://github.com/futomi/node-beacon-scanner/issues/11))
* v0.2.1 (2019-11-02)
* Fixed a typo of a property name in the [`BeaconScannerAdvertisement` object for Eddystone](#BeaconScannerAdvertisement-object-eddystone) (`namespece` -> `namespace`). ([Thanks to @natcl](https://github.com/futomi/node-beacon-scanner/pull/10))
* v0.2.0 (2019-10-25)
Expand Down
4 changes: 2 additions & 2 deletions lib/parser-ibeacon.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* ------------------------------------------------------------------
* node-beacon-scanner - parser-ibeacon.js
*
* Copyright (c) 2017, Futomi Hatano, All rights reserved.
* Copyright (c) 2017-2019, Futomi Hatano, All rights reserved.
* Released under the MIT license
* Date: 2017-09-06
* Date: 2019-11-24
* ---------------------------------------------------------------- */
'use strict';

Expand Down
85 changes: 44 additions & 41 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Copyright (c) 2017-2018, Futomi Hatano, All rights reserved.
* Released under the MIT license
* Date: 2018-06-24
* Date: 2019-11-24
* ---------------------------------------------------------------- */
'use strict';

Expand All @@ -14,7 +14,7 @@ const mEddystone = require('./parser-eddystone.js');
/* ------------------------------------------------------------------
* Constructor: EstimoteAdvertising()
* ---------------------------------------------------------------- */
const BeaconParser = function() {
const BeaconParser = function () {
// Private properties
this._ESTIMOTE_TELEMETRY_SERVICE_UUID = 'fe9a';
this._ESTIMOTE_COMPANY_ID = 0x015d;
Expand All @@ -25,81 +25,84 @@ const BeaconParser = function() {
* Method: parse(peripheral)
* - peripheral: `Peripheral` object of the noble
* ---------------------------------------------------------------- */
BeaconParser.prototype.parse = function(peripheral) {
BeaconParser.prototype.parse = function (peripheral) {
let ad = peripheral.advertisement;
let manu = ad.manufacturerData;
let res = {
id : peripheral.id,
address : peripheral.address,
localName : ad.localName || null,
txPowerLevel : ad.txPowerLevel || null,
rssi : peripheral.rssi
id: peripheral.id,
address: peripheral.address,
localName: ad.localName || null,
txPowerLevel: ad.txPowerLevel || null,
rssi: peripheral.rssi
};

let beacon_type = this._detectBeaconType(peripheral);
res['beaconType'] = beacon_type;
let parsed = null;

// iBeacon
if(beacon_type === 'iBeacon') {
if (beacon_type === 'iBeacon') {
parsed = mIbeacon.parse(peripheral);
// Eddystone
} else if(beacon_type === 'eddystoneUid') {
// Eddystone
} else if (beacon_type === 'eddystoneUid') {
parsed = mEddystone.parseUid(peripheral);
} else if(beacon_type === 'eddystoneUrl') {
} else if (beacon_type === 'eddystoneUrl') {
parsed = mEddystone.parseUrl(peripheral);
} else if(beacon_type === 'eddystoneTlm') {
} else if (beacon_type === 'eddystoneTlm') {
parsed = mEddystone.parseTlm(peripheral);
} else if(beacon_type === 'eddystoneEid') {
} else if (beacon_type === 'eddystoneEid') {
parsed = mEddystone.parseEid(peripheral);
// Estimote
} else if(beacon_type === 'estimoteTelemetry') {
// Estimote
} else if (beacon_type === 'estimoteTelemetry') {
parsed = mEstimote.parseTelemetry(peripheral);
} else if(beacon_type === 'estimoteNearable') {
} else if (beacon_type === 'estimoteNearable') {
parsed = mEstimote.parseNearable(peripheral);
}

if(parsed) {
if (parsed) {
res[beacon_type] = parsed;
return res;
} else {
return null;
}
};

BeaconParser.prototype._detectBeaconType = function(peripheral) {
BeaconParser.prototype._detectBeaconType = function (peripheral) {
let ad = peripheral.advertisement;
let manu = ad.manufacturerData;
// Eddiystone
let eddystone_service = ad.serviceData.find((el) => {
return el.uuid === this._EDDYSTONE_SERVICE_UUID;
});
if(eddystone_service && eddystone_service.data) {
// https://github.com/google/eddystone/blob/master/protocol-specification.md
let frame_type = eddystone_service.data.readUInt8(0) >>> 4;
if(frame_type === 0b0000) {
return 'eddystoneUid';
} else if(frame_type === 0b0001) {
return 'eddystoneUrl';
} else if(frame_type === 0b0010) {
return 'eddystoneTlm';
} else if(frame_type === 0b0011) {
return 'eddystoneEid';
if (ad.serviceData) {
let eddystone_service = ad.serviceData.find((el) => {
return el.uuid === this._EDDYSTONE_SERVICE_UUID;
});
if (eddystone_service && eddystone_service.data) {
// https://github.com/google/eddystone/blob/master/protocol-specification.md
let frame_type = eddystone_service.data.readUInt8(0) >>> 4;
if (frame_type === 0b0000) {
return 'eddystoneUid';
} else if (frame_type === 0b0001) {
return 'eddystoneUrl';
} else if (frame_type === 0b0010) {
return 'eddystoneTlm';
} else if (frame_type === 0b0011) {
return 'eddystoneEid';
}
}
}
// iBeacon
if(manu && manu.length >= 4 && manu.readUInt32BE(0) === 0x4c000215) {
if (manu && manu.length >= 4 && manu.readUInt32BE(0) === 0x4c000215) {
return 'iBeacon';
}
// Estimote Telemetry
let telemetry_service = ad.serviceData.find((el) => {
return el.uuid === this._ESTIMOTE_TELEMETRY_SERVICE_UUID;
});
if(telemetry_service && telemetry_service.data) {
return 'estimoteTelemetry';
if (ad.serviceData) {
let telemetry_service = ad.serviceData.find((el) => {
return el.uuid === this._ESTIMOTE_TELEMETRY_SERVICE_UUID;
});
if (telemetry_service && telemetry_service.data) {
return 'estimoteTelemetry';
}
}
// Estimote Nearable
if(manu && manu.length >= 2 && manu.readUInt16LE(0) === this._ESTIMOTE_COMPANY_ID) {
if (manu && manu.length >= 2 && manu.readUInt16LE(0) === this._ESTIMOTE_COMPANY_ID) {
return 'estimoteNearable';
}
// Unknown
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-beacon-scanner",
"version": "0.2.1",
"version": "0.2.2",
"description": "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.",
"main": "./lib/scanner.js",
"files": [
Expand Down

0 comments on commit 45255b3

Please sign in to comment.