Auteur | SHA1 | Bericht | Datum |
---|---|---|---|
James Peret | 8090f2a1e4 | 7 jaren geleden |
@@ -14,6 +14,7 @@ |
||
14 | 14 |
"ejs": "^2.5.7", |
15 | 15 |
"express": "^4.15.4", |
16 | 16 |
"express-ejs-layouts": "^2.3.1", |
17 |
+ "rpio": "^0.9.17", |
|
17 | 18 |
"socket.io": "^2.0.3", |
18 | 19 |
"winston": "^2.3.1" |
19 | 20 |
} |
@@ -1,8 +1,17 @@ |
||
1 | 1 |
var logger = require('winston'); |
2 |
+var rpio = require("rpio") |
|
3 |
+ |
|
4 |
+var relay_status = [ |
|
5 |
+ { |
|
6 |
+ code: "L01", |
|
7 |
+ status: true, |
|
8 |
+ pin: 35 |
|
9 |
+ } |
|
10 |
+] |
|
2 | 11 |
|
3 | 12 |
module.exports.start = function(router, channel){ |
4 | 13 |
logger.info("Starting Relay controller module"); |
5 |
- |
|
14 |
+ rpio.open(relay_status[0].pin, rpio.OUTPUT, rpio.LOW); |
|
6 | 15 |
router.post('/switch_relay', function (req, res) { |
7 | 16 |
logger.info("Received request for switching relays", req.body); |
8 | 17 |
if(req.body != undefined){ |
@@ -26,17 +35,19 @@ module.exports.monitor = function(socket, channel){ |
||
26 | 35 |
}); |
27 | 36 |
} |
28 | 37 |
|
29 |
-var relay_status = [ |
|
30 |
- { |
|
31 |
- code: "L01", |
|
32 |
- status: true |
|
33 |
- } |
|
34 |
-] |
|
38 |
+ |
|
35 | 39 |
|
36 | 40 |
var switchRelay = function(code, status){ |
37 | 41 |
switch (code) { |
38 | 42 |
case "L01": |
39 | 43 |
// switch on light relay |
44 |
+ if(status == true) { |
|
45 |
+ rpio.write(relay_status[0].pin, rpio.HIGH); |
|
46 |
+ logger.debug("Switched L01 ON"); |
|
47 |
+ } else { |
|
48 |
+ rpio.write(relay_status[0].pin, rpio.LOW); |
|
49 |
+ logger.debug("Switched L01 OFF"); |
|
50 |
+ } |
|
40 | 51 |
relay_status[0].status = status; |
41 | 52 |
return true; |
42 | 53 |
break; |
@@ -126,7 +126,7 @@ |
||
126 | 126 |
|
127 | 127 |
<script src="/socket.io/socket.io.js"></script> |
128 | 128 |
<script> |
129 |
- var socket = io.connect('http://localhost:3100/'); |
|
129 |
+ var socket = io.connect('/'); |
|
130 | 130 |
|
131 | 131 |
var http_post = function(url, data){ |
132 | 132 |
var xhr = new XMLHttpRequest(); |
@@ -184,7 +184,7 @@ |
||
184 | 184 |
socket.emit('relay_switch_update', {}); |
185 | 185 |
setInterval(function () { |
186 | 186 |
socket.emit('relay_switch_update', {}); |
187 |
- }, 5000); |
|
187 |
+ }, 3000000); |
|
188 | 188 |
|
189 | 189 |
|
190 | 190 |
</script> |