Now the toggleing is done withing the first python call because it is a async call.

This commit is contained in:
2017-09-04 19:35:58 +02:00
parent 01abf33d78
commit b1f9f2965b

View File

@@ -62,7 +62,6 @@ app.post('/off', function (req, res) {
})
app.post('/toggle', function (req, res) {
var relayState;
var options = {
pythonOptions: ['-u'],
args: 'get'
@@ -70,24 +69,37 @@ app.post('/toggle', function (req, res) {
PythonShell.run('scripts/fanController.py', options, function (err, results) {
if (err) throw err;
if (results[0] == true)
relayState = true;
else
relayState = false;
});
options = {
if (results[0] == true) {
var toggleOptions = {
pythonOptions: ['-u'],
args: relayState
args: 'off'
};
PythonShell.run('scripts/fanController.py', options, function (err, results) {
PythonShell.run('scripts/fanController.py', toggleOptions, function (err, results) {
if (err) throw err;
if (results[0] == true)
res.send('off')
else
res.send('none')
});
}
else {
var toggleOptions = {
pythonOptions: ['-u'],
args: 'on'
};
PythonShell.run('scripts/fanController.py', toggleOptions, function (err, results) {
if (err) throw err;
if (results[0] == true)
res.send('on')
else
res.send('none')
});
}
});
})