-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrylight.js
42 lines (34 loc) · 858 Bytes
/
trylight.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
var gpio = require("gpio");
var socket = require('socket.io-client')('https://fbchatbot1.appspot.com');
//var socket = require('socket.io-client')('http://localhost:3000');
var turnLightOn = function(pinNumber){
gpioPin = gpio.export(pinNumber,{
ready: function(){
gpioPin.set();
setTimeout(function() {
gpioPin.reset();
}, 1000 );
}
});
}
socket.on('connect', function(){
console.log("connect emitted from server");
});
socket.on('fb-message', function(data){
var msg = "";
try{
msg = JSON.parse(data).text;
}catch(err){
msg = data.text;
}
console.log(msg);
if(msg.indexOf('green') > -1){
turnLightOn(18);
}
if(msg.indexOf('red') > -1){
turnLightOn(16);
}
});
socket.on('disconnect', function(){
console.log("disconnected!");
});