-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (33 loc) · 983 Bytes
/
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
let house = require('./Secrets/house.js')
let numbers = require('./Secrets/numbers.js')
let twilioAuth = require('./Secrets/twilio.js')
let twilio = new require('twilio')(twilioAuth.sid, twilioAuth.token)
let dateFormat = require('dateformat')
let now = new Date()
let Gpio = require('onoff').Gpio;
let button = new Gpio(4, 'in', 'falling', {debounceTimeout: 10});
let throttle = require('lodash/throttle')
let timeout = 8 * 60 * 1000
let options = {'trailing': false}
let sendAll = (err, value) => {
if (err) {
throw err;
}
numbers.forEach((number) => {
sendTo(number)
})
}
button.watch(
throttle(sendAll, timeout, options)
)
console.log("Started doorbell watcher ...")
function sendTo(number) {
twilio.messages.create({
body: "Doorbell at " + house.address + " (" + dateFormat(now, "HH:MM m/d/yy") + ")",
to: number,
from: twilioAuth.from
})
}
process.on('SIGINT', () => {
button.unexport();
});