mirror of
https://github.com/KevinMidboe/fanController.git
synced 2025-10-29 17:40:22 +00:00
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:
51
scripts/fanController.py
Executable file
51
scripts/fanController.py
Executable 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
BIN
scripts/fanState.db
Normal file
Binary file not shown.
Reference in New Issue
Block a user