diff --git a/README.md b/README.md index 4e1296f..e28708a 100644 --- a/README.md +++ b/README.md @@ -404,6 +404,9 @@ Property | |Type |Description --------------------------------------- ## Release Note +* 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) diff --git a/lib/parser-ibeacon.js b/lib/parser-ibeacon.js index c18ee7b..24180e6 100644 --- a/lib/parser-ibeacon.js +++ b/lib/parser-ibeacon.js @@ -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'; diff --git a/lib/parser.js b/lib/parser.js index a89f00c..b609e3d 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -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'; @@ -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; @@ -25,15 +25,14 @@ 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); @@ -41,25 +40,25 @@ BeaconParser.prototype.parse = function(peripheral) { 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 { @@ -67,39 +66,43 @@ BeaconParser.prototype.parse = function(peripheral) { } }; -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 diff --git a/package.json b/package.json index 3189fa3..0c55662 100644 --- a/package.json +++ b/package.json @@ -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": [