-
Notifications
You must be signed in to change notification settings - Fork 1
/
MDBT42Q.js
47 lines (37 loc) · 1.01 KB
/
MDBT42Q.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
const SENSOR = D14;
var state = false;
var time = getTime();
var newTime = 0;
var options = {
name: "Skookum Stall Monitor",
interval:1000,
manufacturer:0x0590
};
function setAdvertisingData(doorState, duration) {
options.manufacturerData = JSON.stringify({
l: doorState ? 1 : 0,
d: Math.round(duration)
});
//console.log(options);
NRF.setAdvertising({
0x180F : [Math.round((NRF.getBattery()-2.5)/0.8*100)]
// This causes a DATA_SIZE error
//0x1809 : [Math.round(E.getTemperature())]
}, options
);
}
// Initialization
pinMode(D14, 'input_pulldown');
NRF.setLowPowerConnection(true);
setAdvertisingData(!SENSOR.read(), 0);
// Main
setWatch(function(e) {
if(state !== e.state) {
newTime = getTime();
//console.log('Door', e.state ? 'Unlocked' : 'Locked');
//console.log('Duration:', (newTime - time));
setAdvertisingData(!e.state, newTime - time);
time = newTime;
}
state = e.state;
}, SENSOR, { repeat: true, edge: 'both', debounce: 1000 });