-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracker.js
63 lines (54 loc) · 2.05 KB
/
tracker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//* distance < IMMEDIATE_RANGE, red light will go on. *//
//* IMMEDIATE_RANGE <= distance <= NEAR_RANGE, amber light goes on. *//
//* distance > NEAR_RANGE, green light will go on. *//
var IMMEDIATE_RANGE = 2;
var NEAR_RANGE = 4;
//* Number of beacon readings used for distance calculations, average taken. *//
var ROLLING_AVERAGE_SIZE = 5;
//* Load Node packages *//
var UriBeaconScanner = require('uri-beacon-scanner');
var BeaconLights = require('beaconLights');
//* Function run when beacon discovered *//
UriBeaconScanner.on('discover', function(uriBeacon) {
if(uriBeacon.uri.search(process.argv[2]) > 0) {
console.log(
'Beacon1: rssi = ' + uriBeacon.rssi +
' tx power = ' + uriBeacon.txPower
)
beacon1.discovered(
uriBeacon.rssi,
uriBeacon.txPower,
IMMEDIATE_RANGE,
NEAR_RANGE,
ROLLING_AVERAGE_SIZE
);
} else if (uriBeacon.uri.search(process.argv[3]) > 0) {
console.log(
'Beacon2: rssi = ' + uriBeacon.rssi +
' tx power = ' + uriBeacon.txPower
)
beacon2.discovered(
uriBeacon.rssi,
uriBeacon.txPower,
IMMEDIATE_RANGE,
NEAR_RANGE,
ROLLING_AVERAGE_SIZE
);
}
});
//* Main Code *//
//* If 2 beacon IDs not given give error message and exit.*//
if(process.argv.length < 4) {
console.log("Need to specify two beacons to track");
process.exit(1);
}
//* Prints progress messages to terminal.*//
console.log('Tracking Beacon1: ' + process.argv[2]);
console.log('Tracking Beacon2: ' + process.argv[3]);
//* Links beacon ID and pin numbers to display lights for each beacon. *//
//* See appendix 1. *//
//* BeaconLights(BeaconID, immediateLightPin, nearLightPin, farLightPin) *//
var beacon1 = new BeaconLights(process.argv[2], 21, 20, 16);
var beacon2 = new BeaconLights(process.argv[3], 7, 8, 25);
//* Start scanning for beacons *//
UriBeaconScanner.startScanning(true);