Remove gpio portions
Signed-off-by: Lukas Schaefer <lukas@lschaefer.xyz>
This commit is contained in:
@@ -1,12 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
import router # Custom library that has router controls
|
||||
import urllib.request
|
||||
try: # Will check if device supports GPIO otherwise will print/log statements
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
skipGPIO = False
|
||||
except:
|
||||
skipGPIO = True
|
||||
import json
|
||||
|
||||
import time
|
||||
@@ -132,14 +126,6 @@ try:
|
||||
continue
|
||||
internetOnDeafult = ["23", "0", "5", "0", "2147483000", "1"]
|
||||
internet = False
|
||||
if not skipGPIO:
|
||||
# Will setup the gpio button
|
||||
GPIO.setmode(GPIO.BOARD)
|
||||
GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
GPIO.setup(8, GPIO.OUT)
|
||||
# Will setup the GPIO fan
|
||||
GPIO.setup(16, GPIO.OUT)
|
||||
GPIO.output(16, GPIO.LOW)
|
||||
|
||||
def writeLog(message, kind): # Will automatically add to the log
|
||||
print(message, time.time())
|
||||
@@ -160,36 +146,20 @@ try:
|
||||
timeEnd += 60 * 24
|
||||
if times >= timeStart and times <= timeEnd:
|
||||
if status:
|
||||
if skipGPIO:
|
||||
print("LED turning on")
|
||||
else:
|
||||
GPIO.output(8, GPIO.HIGH)
|
||||
writeLog("Internet turning off", 6)
|
||||
if not developmentMachine:
|
||||
status = router.turnOffInternet()
|
||||
else:
|
||||
status = False
|
||||
writeLog("Internet turned off", 6)
|
||||
if skipGPIO:
|
||||
print("LED turning off")
|
||||
else:
|
||||
GPIO.output(8, GPIO.LOW)
|
||||
else:
|
||||
if not status:
|
||||
if skipGPIO:
|
||||
print("LED turning on")
|
||||
else:
|
||||
GPIO.output(8, GPIO.HIGH)
|
||||
writeLog("Internet turning on", 7)
|
||||
if not developmentMachine:
|
||||
status = router.turnOnInternet()
|
||||
else:
|
||||
status = True
|
||||
writeLog("Internet turned on", 7)
|
||||
if skipGPIO:
|
||||
print("LED turning off")
|
||||
else:
|
||||
GPIO.output(8, GPIO.LOW)
|
||||
return status
|
||||
|
||||
def callTime(): # Will return the time
|
||||
@@ -284,9 +254,6 @@ try:
|
||||
f.write("""Order allow,deny
|
||||
Deny from all""")
|
||||
|
||||
# Will add to log if a library could not be connected to
|
||||
if skipGPIO:
|
||||
writeLog("Could not import GPIO library", 9)
|
||||
while True: # will wait until connected to internet
|
||||
try:
|
||||
urllib.request.urlopen("https://google.com")
|
||||
@@ -429,28 +396,6 @@ Deny from all""")
|
||||
os.remove(location + "maintenance-mode")
|
||||
except:
|
||||
1
|
||||
if not skipGPIO:
|
||||
# Checks if the fans need to turn on or off
|
||||
if temp() > configuration["fanStart"] and not fanOn:
|
||||
GPIO.output(16, GPIO.HIGH)
|
||||
fanOn = True
|
||||
writeLog(f'Fan was turned on with a temprature of {temp()}', 13)
|
||||
elif temp() < configuration["fanStop"] and fanOn:
|
||||
GPIO.output(16, GPIO.LOW)
|
||||
fanOn = False
|
||||
writeLog(f'Fan was turned off with a temprature of {temp()}', 13)
|
||||
if GPIO.input(10):
|
||||
GPIO.output(8, GPIO.HIGH)
|
||||
time.sleep(0.2)
|
||||
GPIO.output(8, GPIO.LOW)
|
||||
time.sleep(0.1)
|
||||
if GPIO.input(10):
|
||||
GPIO.output(8, GPIO.HIGH)
|
||||
try:
|
||||
buttonPress(internetOn)
|
||||
except:
|
||||
writeLog("Button press failed", 9)
|
||||
break
|
||||
# Alternative to simulate a button press by putting button into this folder
|
||||
elif os.path.isfile(location + "button.json"):
|
||||
try:
|
||||
@@ -468,25 +413,6 @@ except Exception as e:
|
||||
f.close()
|
||||
os.system("chmod 750 -R " + location)
|
||||
os.system("chown -R www-data:www-data " + location)
|
||||
if skipGPIO:
|
||||
raise Exception
|
||||
else:
|
||||
while True:
|
||||
GPIO.output(8, GPIO.HIGH)
|
||||
time.sleep(1)
|
||||
GPIO.output(8, GPIO.LOW)
|
||||
if GPIO.input(10):
|
||||
time.sleep(0.5)
|
||||
if GPIO.input(10):
|
||||
writeLog("Server is being restarted through button", 12)
|
||||
for x in range(10):
|
||||
GPIO.output(8, GPIO.HIGH)
|
||||
time.sleep(0.1)
|
||||
GPIO.output(8, GPIO.LOW)
|
||||
time.sleep(0.1)
|
||||
os.system(f"python3 {__file__}")
|
||||
exit()
|
||||
time.sleep(1)
|
||||
except Exception:
|
||||
print("crash")
|
||||
while True:
|
||||
|
||||
Reference in New Issue
Block a user