/
index.js
30 lines (27 loc) · 919 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
var SerialPort = require("serialport").SerialPort,
serialPort = new SerialPort("/dev/cu.LightBlue-Bean", {
baudrate: 57600
}),
request = require('request');
serialPort.on("open", function () {
console.log("Connected to LightBlue Bean serial port");
serialPort.on("data", function(data) {
console.log("Data: " + data);
data = data + "";
if (data == "CLOSED") {
request.post({
url: "http://maker.ifttt.com/trigger/bean_door_closed/with/key/YOURKEYHERE"
}, function(error, response, body) {
console.log(body);
if (error) console.log("Error was ", error);
});
} else if (data == "OPEN") {
request.post({
url: "http://maker.ifttt.com/trigger/bean_door_open/with/key/YOURKEYHERE"
}, function(error, response, body) {
console.log(body);
if (error) console.log("Error was ", error);
});
}
});
});