-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
67 lines (55 loc) · 1.49 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var express = require('express');
var bodyParser = require('body-parser');
var pythonShell = require('python-shell');
var app;
var shell;
sent = false;
var PORT = 4000;
app = express();
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
var server = app.listen(PORT, function() {
console.log('Express Started');
});
app.get('/', function(req, res) {
res.end('Welcome to the Home Automation System!');
});
app.get('/on', function(req, res) {
if(shell != undefined) {
shell.send('stop').end(function(err) {});
shell = undefined;
}
shell = new pythonShell('python_scripts/on.py');
res.end('You sent on');
});
app.get('/off', function(req, res) {
if(shell != undefined) {
shell.send('stop').end(function(err) {});
shell = undefined;
}
shell = new pythonShell('python_scripts/off.py');
res.end('You sent off');
});
app.get('/blink', function(req, res) {
if(shell != undefined) {
shell.send('stop').end(function(err) {});
shell = undefined;
}
shell = new pythonShell('python_scripts/blink.py');
res.end('You sent blink');
});
app.get('/pwm', function(req, res) {
if(shell != undefined) {
shell.send('stop').end(function(err) {});
shell = undefined;
}
shell = new pythonShell('python_scripts/pwm.py');
res.end('You sent pwm');
});
app.get('/stop', function(req, res) {
if(shell != undefined) {
shell.send("stop").end(function(err) {});
shell = undefined;
}
res.end('You sent Stop.');
});