mirror of
				https://github.com/KevinMidboe/fanController.git
				synced 2025-10-29 17:40:22 +00:00 
			
		
		
		
	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:
		
							
								
								
									
										18
									
								
								server.js
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								server.js
									
									
									
									
									
								
							| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user