-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
43 lines (37 loc) · 868 Bytes
/
server.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
var http = require("http");
var gpio = require('gpio');
var gate = null;
http.createServer(function(request, response) {
if (request.url == "/check") {
response.write("The server is running.");
}
else if (request.url == "/run") {
if (request.method != "POST") {
response.statusCode = 405;
response.write("POST is required.");
}
else {
if (!gate) {
gate = gpio.export(4, {
direction: 'out',
interval: 200,
ready: function() {
setTimeout( function() {
gate.set(1);
}, 300);
}
});
}
gate.set(0, function() {
setTimeout( function() {
gate.set(1);
}, 300);
});
}
}
else {
response.statusCode = 404;
response.write("Page not found.");
}
response.end();
}).listen(8888);