-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
101 lines (86 loc) · 2.88 KB
/
index.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
define(['dom7'], function ($$) {
'use strict';
function status(msg) {
$$('#status').html(msg);
}
function uint8ArrayToString(uint8Array)
{
function format(x)
{
var hex = x.toString(16);
return hex.length < 2 ? '0' + hex : hex;
}
var result = '';
for (var i = 0; i < uint8Array.length; ++i)
{
result += format(uint8Array[i]) + ' ';
}
return result;
}
function log(msg) {
$$('#log').append('<li>' + msg + '</li>');
}
function htmlBeaconName(beacon) {
var name = beacon.name || 'no name';
return '<strong>' + name + '</strong><br/>';
}
function htmlBeaconURL(beacon) {
return beacon.url ?
'URL: ' + beacon.url + '<br/>' : '';
}
function htmlBeaconNID(beacon) {
return beacon.nid ?
'NID: ' + uint8ArrayToString(beacon.nid) + '<br/>' : '';
}
function htmlBeaconBID(beacon) {
return beacon.bid ?
'BID: ' + uint8ArrayToString(beacon.bid) + '<br/>' : '';
}
function htmlBeaconVoltage(beacon) {
return beacon.voltage ?
'Voltage: ' + beacon.voltage + '<br/>' : '';
}
function htmlBeaconTemperature(beacon) {
return beacon.temperature && beacon.temperature != 0x8000 ?
'Temperature: ' + beacon.temperature + '<br/>' : '';
}
function htmlBeaconRSSI(beacon) {
return beacon.rssi ?
'RSSI: ' + beacon.rssi + '<br/>' : '';
}
function htmlMac(beacon) {
return beacon.address ?
'Address: ' + beacon.address + '<br/>' : '';
}
function htmlIBeacon(beacon) {
return beacon.ibeacon ?
'IBeacon UUID: ' + beacon.ibeacon + '<br/>' : '';
}
$$(document).on('click', '#scanEddy', function () {
evothings.eddystone.stopScan();
status('Scanning...');
evothings.eddystone.startScan(
function (beacon)
{
var htmlBeacon = htmlBeaconName(beacon)
+ htmlBeaconURL(beacon)
+ htmlMac(beacon)
+ htmlIBeacon(beacon)
+ htmlBeaconNID(beacon)
+ htmlBeaconBID(beacon)
+ htmlBeaconVoltage(beacon)
+ htmlBeaconTemperature(beacon)
+ htmlBeaconRSSI(beacon);
log(htmlBeacon);
},
function (error)
{
status('Eddystone scan error: ' + error);
});
return false;
});
return {
'init': function (page) {
}
};
});