mirror of
https://github.com/KevinMidboe/fanController.git
synced 2025-10-29 17:40:22 +00:00
Now checks python script (forgot to add)
This commit is contained in:
18
server.js
18
server.js
@@ -5,7 +5,6 @@ var PythonShell = require('python-shell');
|
|||||||
|
|
||||||
app.use(express.static('public'));
|
app.use(express.static('public'));
|
||||||
|
|
||||||
var relayState = false;
|
|
||||||
|
|
||||||
// This responds with "Hello World" on the homepage
|
// This responds with "Hello World" on the homepage
|
||||||
app.get('/', function (req, res) {
|
app.get('/', function (req, res) {
|
||||||
@@ -63,8 +62,21 @@ app.post('/off', function (req, res) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
app.post('/toggle', function (req, res) {
|
app.post('/toggle', function (req, res) {
|
||||||
relayState = !relayState
|
var relayState;
|
||||||
var options = {
|
var options = {
|
||||||
|
pythonOptions: ['-u'],
|
||||||
|
args: 'get'
|
||||||
|
};
|
||||||
|
|
||||||
|
PythonShell.run('scripts/fanController.py', options, function (err, results) {
|
||||||
|
if (err) throw err;
|
||||||
|
if (results[0] == true)
|
||||||
|
relayState = true;
|
||||||
|
else
|
||||||
|
relayState = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
options = {
|
||||||
pythonOptions: ['-u'],
|
pythonOptions: ['-u'],
|
||||||
args: relayState
|
args: relayState
|
||||||
};
|
};
|
||||||
@@ -75,7 +87,7 @@ app.post('/toggle', function (req, res) {
|
|||||||
if (results[0] == true)
|
if (results[0] == true)
|
||||||
res.send('off')
|
res.send('off')
|
||||||
else
|
else
|
||||||
res.send('none')
|
res.send('on')
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user