-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNUapp.js
121 lines (109 loc) · 4.04 KB
/
NUapp.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//$ npm install socket.io
//, io = require('socket.io').listen(app)
//, gpio = require('rpi-gpio')
var http = require('http');
var app = require('express.io')();
var PythonShell = require('python-shell');
app.http().io();
var express = require('express');
var port = 8080;
// Setup the ready route, and emit talk event.
app.io.route('ready', function(req) {
req.io.emit('talk', {
message: 'io event from an io route on the server'
})
})
app.use(express.static('public'));
// Send the client html.
app.get('/', function(req, res) {
res.sendfile(__dirname + '/public/index.html');
})
app.get('/js/main.js', function(req, res) {
res.sendfile(__dirname + '/public/js/main.js');
})
app.get('/js/vendor/modernizr-2.8.3-respond-1.4.2.min.js', function(req, res) {
res.sendfile(__dirname + '/public/js/vendor/modernizr-2.8.3-respond-1.4.2.min.js');
})
app.get('/js/vendor/jquery-1.11.2.min.js', function(req, res) {
res.sendfile(__dirname + '/public/js/vendor/jquery-1.11.2.min.js');
})
app.get('/js/vendor/bootstrap.min.js', function(req, res) {
res.sendfile(__dirname + '/public/js/vendor/bootstrap.min.js');
})
app.get('/css/bootstrap.min.css', function(req, res) {
res.sendfile(__dirname + '/public/css/bootstrap.min.css');
})
app.get('/css/bootstrap-theme.min.css', function(req, res) {
res.sendfile(__dirname + '/public/css/bootstrap-theme.min.css');
})
app.get('/css/main.css', function(req, res) {
res.sendfile(__dirname + '/public/css/main.css');
})
app.get('/css/font-awesome.min.css', function(req, res) {
res.sendfile(__dirname + '/public/css/font-awesome.min.css');
})
app.get('/css/font-awesome-animation.min.css', function(req, res) {
res.sendfile(__dirname + '/public/css/font-awesome-animation.min.css');
})
app.get('/img/wisesocket-logo.png', function(req, res) {
res.sendfile(__dirname + '/public/img/wisesocket-logo.png');
})
app.get('/fonts/fontawesome-webfont.eot?v=4.3.0', function(req, res) {
res.sendfile(__dirname + '/fonts/fontawesome-webfont.eot?v=4.3.0');
})
app.get('/fonts/fontawesome-webfont.eot?#iefix&v=4.3.0', function(req, res) {
res.sendfile(__dirname + '/fonts/fontawesome-webfont.eot?#iefix&v=4.3.0');
})
app.get('/fonts/fontawesome-webfont.woff2?v=4.3.0', function(req, res) {
res.sendfile(__dirname + '/fonts/fontawesome-webfont.woff2?v=4.3.0');
})
app.get('/fonts/fontawesome-webfont.woff?v=4.3.0', function(req, res) {
res.sendfile(__dirname + '/fonts/fontawesome-webfont.woff?v=4.3.0');
})
app.get('/fonts/fontawesome-webfont.ttf?v=4.3.0', function(req, res) {
res.sendfile(__dirname + '/fonts/fontawesome-webfont.ttf?v=4.3.0');
})
app.get('/fonts/fontawesome-webfont.svg?v=4.3.0#fontawesomeregular', function(req, res) {
res.sendfile(__dirname + '/fonts/fontawesome-webfont.svg?v=4.3.0#fontawesomeregular');
})
app.io.route('socket1Toggle', function(data) {
console.log(data.data.status);
if(data.data.status =='ON'){
PythonShell.run('/ledoff.py', function(err){
if (err) console.log(err);
console.log('turned off');
});
}else{
PythonShell.run('/led.py', function(err){
if (err) console.log(err);
console.log('turned on');
});
}
});
app.io.route('motionToggle', function(data) {
console.log("motion code behind");
console.log(data.data.status);
// turn default state to off
PythonShell.run('/ledoff.py', function(err){
//if (err) console.log(err);
console.log('motion turned off');
});
if(data.data.status =='ON'){
console.log("turning motion on");
PythonShell.run('/sensor.py', function(err){
//if (err) console.log(err);
console.log('motion sensing on');
});
}else{
console.log("turning things off");
// turn default state to off
PythonShell.run('/ledoff.py', function(err){
//if (err) console.log(err);
console.log('turned things off');
});
console.log("END:motion code behind");
}
});
app.listen(port);
//app.use(express.static(__dirname + '/public'));
console.log("Server is running on port " + port);