Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding EID support #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 41 additions & 8 deletions lib/eddystone-beacon-scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var SERVICE_UUID = 'feaa';
var UID_FRAME_TYPE = 0x00;
var URL_FRAME_TYPE = 0x10;
var TLM_FRAME_TYPE = 0x20;
var EID_FRAME_TYPE = 0x30;

var EXIT_GRACE_PERIOD = 5000; // milliseconds

Expand Down Expand Up @@ -132,13 +133,19 @@ EddystoneBeaconScanner.prototype.parseBeacon = function(peripheral) {
beacon = this.parseTlmData(data);
break;

case EID_FRAME_TYPE:
type = 'eid';
beacon = this.parseEidData(data);
break;

default:
break;
}

beacon.id = peripheral.id;
beacon.type = type;
beacon.rssi = rssi;
beacon.address = peripheral.address

var txPower = beacon.txPower;
if (txPower !== undefined) {
Expand All @@ -159,24 +166,50 @@ EddystoneBeaconScanner.prototype.parseUidData = function(data) {
EddystoneBeaconScanner.prototype.parseUrlData = function(data) {
return {
txPower: data.readInt8(1),
url: urlDecode(data.slice(2))
url: urlDecode(data.slice(2)),
prefix: this.prefix(data.readInt8(2))
};
};

EddystoneBeaconScanner.prototype.parseTlmData = function(data) {
return {
tlm: {
version: data.readUInt8(1),
vbatt: data.readUInt16BE(2),
temp: data.readInt16BE(4) / 256,
advCnt: data.readUInt32BE(6),
secCnt: data.readUInt32BE(10)
}
version: data.readUInt8(1),
battery: data.readUInt16BE(2),
temperature: data.readInt16BE(4) / 256,
pdu: data.readUInt32BE(6),
time: data.readUInt32BE(10)
Comment on lines +176 to +180

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this is going to break the external API. Is that really necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, its not necessary

};
};

EddystoneBeaconScanner.prototype.parseEidData = function(data) {
return {
txPower: data.readInt8(1),
eid: data.slice(2, 10).toString('hex')
};
};

EddystoneBeaconScanner.prototype.calculateDistance = function(txPower, rssi) {
return Math.pow(10, ((txPower - rssi) - 41) / 20.0);
};

EddystoneBeaconScanner.prototype.prefix = function(number){
switch(number){
case 0:
return 'http://www.'
break;

case 1:
return 'https://www.'
break;

case 2:
return 'http://'
break;

case 3:
return 'https://'
break;
}
}

module.exports = EddystoneBeaconScanner;
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
"jshint": "^2.7.0"
},
"dependencies": {
"debug": "^2.1.3",
"noble": "^1.1.0",
"eddystone-url-encoding": "^1.0.0"
"bluetooth-hci-socket": "^0.5.1",
"debug": "^3.1.0",
"eddystone-url-encoding": "^1.0.1",
"noble": "^1.9.1",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This library should be using @abandonware/noble and @abandonware/bluetooth-hci-socket.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was built with the previous repo

"usb": "^1.3.2"
}
}