Changed the fanToggling to only be done by one script, changed server.js to reflect these changes and also needed to do some changes to index.html. These being checking the return text and some linting.

This commit is contained in:
2017-02-19 11:55:48 +01:00
parent 5c4cf195e0
commit 0cb52876a1
13 changed files with 110 additions and 541 deletions

51
scripts/fanController.py Executable file
View File

@@ -0,0 +1,51 @@
#!/usr/bin/env python3
import CHIP_IO.GPIO as GPIO #import the GPIO library
import sqlite3
from sys import argv
path = "scripts/fanState.db"
def updateFanstate(state):
conn = sqlite3.connect(path)
c = conn.cursor()
c.execute('UPDATE fanstate SET state='+str(state))
conn.commit()
conn.close()
def getFanstate():
conn = sqlite3.connect(path)
c = conn.cursor()
c.execute('SELECT state FROM fanstate')
state = c.fetchone()[0]
conn.close()
return state
def turnFanON():
if not getFanstate():
updateFanstate(1)
GPIO.setup("CSID0", GPIO.OUT) #set CSID0 as an output
GPIO.output("CSID0", GPIO.HIGH) #set CSID0 (LED) HIGH (On)
return '1'
def turnFanOFF():
if getFanstate():
updateFanstate(0)
GPIO.setup("CSID0", GPIO.OUT) #set CSID0 as an output
GPIO.output("CSID0", GPIO.LOW) #set CSID0 (LED) HIGH (On)
return '1'
if __name__ == '__main__':
arg = argv[1]
if (arg == 'on'):
print(turnFanON())
elif (arg == 'off'):
print(turnFanOFF())
elif (arg == 'get'):
print(getFanstate())
else:
print("Invalid input")

BIN
scripts/fanState.db Normal file

Binary file not shown.