Added a toggle endpoint that checks the db for button state then uses that to set it to the opposite.

This commit is contained in:
2017-09-04 18:54:24 +02:00
parent bbba4b2792
commit c5ba6b8621

View File

@@ -5,6 +5,7 @@ var PythonShell = require('python-shell');
app.use(express.static('public'));
var relayState = false;
// This responds with "Hello World" on the homepage
app.get('/', function (req, res) {
@@ -61,6 +62,23 @@ app.post('/off', function (req, res) {
});
})
app.post('/toggle', function (req, res) {
relayState = !relayState
var options = {
pythonOptions: ['-u'],
args: relayState
};
PythonShell.run('scripts/fanController.py', options, function (err, results) {
if (err) throw err;
if (results[0] == true)
res.send('off')
else
res.send('none')
});
})
var server = app.listen(3000, function () {
var host = server.address().address