mirror of
https://github.com/KevinMidboe/fanController.git
synced 2025-10-29 09:30:23 +00:00
Now the toggleing is done withing the first python call because it is a async call.
This commit is contained in:
48
server.js
48
server.js
@@ -62,32 +62,44 @@ app.post('/off', function (req, res) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
app.post('/toggle', function (req, res) {
|
app.post('/toggle', function (req, res) {
|
||||||
var relayState;
|
|
||||||
var options = {
|
var options = {
|
||||||
pythonOptions: ['-u'],
|
pythonOptions: ['-u'],
|
||||||
args: 'get'
|
args: 'get'
|
||||||
};
|
};
|
||||||
|
|
||||||
PythonShell.run('scripts/fanController.py', options, function (err, results) {
|
PythonShell.run('scripts/fanController.py', options, function (err, results) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
if (results[0] == true)
|
|
||||||
relayState = true;
|
if (results[0] == true) {
|
||||||
else
|
var toggleOptions = {
|
||||||
relayState = false;
|
pythonOptions: ['-u'],
|
||||||
});
|
args: 'off'
|
||||||
|
};
|
||||||
|
|
||||||
options = {
|
PythonShell.run('scripts/fanController.py', toggleOptions, function (err, results) {
|
||||||
pythonOptions: ['-u'],
|
if (err) throw err;
|
||||||
args: relayState
|
|
||||||
};
|
if (results[0] == true)
|
||||||
|
res.send('off')
|
||||||
|
else
|
||||||
|
res.send('none')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var toggleOptions = {
|
||||||
|
pythonOptions: ['-u'],
|
||||||
|
args: 'on'
|
||||||
|
};
|
||||||
|
|
||||||
PythonShell.run('scripts/fanController.py', options, function (err, results) {
|
PythonShell.run('scripts/fanController.py', toggleOptions, function (err, results) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
if (results[0] == true)
|
if (results[0] == true)
|
||||||
res.send('off')
|
res.send('on')
|
||||||
else
|
else
|
||||||
res.send('on')
|
res.send('none')
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user