Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import time, socket, datetime, os, fcntl, struct, sqlite3 #import time, IP, time and date
from flask import Flask, render_template, request, jsonify, request, send_file #import web app
from w1thermsensor import W1ThermSensor
import RPi.GPIO as GPIO
import netifaces as ni
def getCurrentBinary(relayNumber):
try:
B = open("data/currentBinary.txt", "r")
currentBinary = B.read()
if len(currentBinary) != 8*relayNumber:
currentBinary = "00000000"*relayNumber
writeCurrentBinary(currentBinary)
getCurrentBinary()
B.close()
except:
currentBinary = "00000000"*relayNumber
writeCurrentBinary(currentBinary)
return currentBinary
def writeCurrentBinary(Binary):
B = open("data/currentBinary.txt", "w")
B.write(Binary)
B.close()
''' OLD SHIFT CODE - BROKEN
def relayIndex(output, relayNumber):
currentBinary = getCurrentBinary(relayNumber)
#currentBinary = "00000000"
if 0 <= int(output) < len(currentBinary):
output = int(output)
if currentBinary[output] == "1":
currentBinary = currentBinary[:output] + "0" + currentBinary[output+1:]
elif currentBinary[output] == "0":
currentBinary = currentBinary[:output] + "1" + currentBinary[output+1:]
else:
print("Invalid Input")
shift(currentBinary[::-1], relayNumber)
writeCurrentBinary(currentBinary)
return currentBinary
def shift(output, relayNumber):
shiftSetup()
print(output)
parsed = ""
for i in range(8*relayNumber):
parsed = parsed + output[i]
time.sleep(0.2)
if output[i] == "1":
GPIO.output(23, GPIO.LOW)
print("1")
elif output[i] == "0":
GPIO.output(23, GPIO.HIGH)
print("0")
GPIO.output(22, GPIO.HIGH)
GPIO.output(22, GPIO.LOW)
GPIO.output(24, GPIO.HIGH)
GPIO.output(24, GPIO.LOW)
print(parsed)
'''
def shiftSetup():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
outpins = [22, 23, 24]
for i in outpins:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, GPIO.HIGH)
def Shift(output, relayNumber):
shiftSetup()
for i in range(7*relayNumber):
if output[i] == "1":
GPIO.output(23, GPIO.LOW)
elif output[i] == "0":
GPIO.output(23, GPIO.HIGH)
GPIO.output(22, GPIO.HIGH)
GPIO.output(22, GPIO.LOW)
GPIO.output(24, GPIO.HIGH)
GPIO.output(24, GPIO.LOW)
def get_url_rule():
rule = None
url_rule = request.url_rule
if url_rule is not None:
rule = url_rule.rule
return rule
def getTemperature():
return(0)
def getColour(number):
if number > 25:
colour = "FF0000"
elif number > 20:
colour = "FF4200"
elif number > 15:
colour = "FF6100"
elif number > 10:
colour = "008BFF"
elif number > 5:
colour = "00A6FF"
elif number > 0:
colour = "00C9FF"
elif number < 0:
colour = "00F7FF"
else:
print("COLOUR ERROR")
colour = "FF00EC"
return colour
def modifyInternalTemperature():
f = open("templates/indexTemplate.html", "r")
index = f.read()
f.close()
internalTemperature = 'style ="float: left; background-color: ' + getColour(getTemperature()) + '">Internal Temperature: ' + str(round(getTemperature(), 1)) + "°C"
index = index.replace('style ="float: left">Internal Temperature: ', internalTemperature)
f = open("templates/index.html", "w")
f.write(index)
f.close()
def modifyInternalTemperatureWebpage():
f = open("templates/internalTemperatureTemplate.html", "r")
index = f.read()
f.close()
internalTemperature = '<H1>' + str(round(getTemperature(), 1)) + "°C </H1>"
index = index.replace('<H1> </H1>', internalTemperature)
f = open("templates/internalTemperature.html", "w")
f.write(index)
f.close()
def modifyExternalTemperature():
f = open("templates/index.html", "r")
index = f.read()
f.close()
ExternalTemperature = 'style ="float: left; background-color: #4CAF50' '''+ getColour(getTemperature())''' + '">External Temperature: Not Connected' #+ str(round(getTemperature(), 1)) + "°C"
index = index.replace('style ="float: left">External Temperature: ', ExternalTemperature)
f = open("templates/index.html", "w")
f.write(index)
f.close()
def modifyExternalTemperatureWebpage():
f = open("templates/externalTemperatureTemplate.html", "r")
index = f.read()
f.close()
ExternalTemperature = '<H1>' + str(round(getTemperature(), 1)) + "°C </H1>"
index = index.replace('<H1> </H1>', ExternalTemperature)
f = open("templates/ExternalTemperature.html", "w")
f.write(index)
f.close()
def modifyWaterTemperature():
f = open("templates/index.html", "r")
index = f.read()
f.close()
WaterTemperature = 'style ="float: left; background-color: #4CAF50' '''+ getColour(getTemperature())''' + '">Water Temperature: Not Connected' #+ str(round(getTemperature(), 1)) + "°C"
index = index.replace('style ="float: left">Water Temperature: ', WaterTemperature)
f = open("templates/index.html", "w")
f.write(index)
f.close()
def modifyWaterTemperatureWebpage():
f = open("templates/waterTemperatureTemplate.html", "r")
index = f.read()
f.close()
WaterTemperature = '<H1>' + str(round(getTemperature(), 1)) + "°C </H1>"
index = index.replace('<H1> </H1>', WaterTemperature)
f = open("templates/WaterTemperature.html", "w")
f.write(index)
f.close()
def modifyIndex():
modifyInternalTemperature()
modifyExternalTemperature()
modifyWaterTemperature()
def get_IP():
'''Automatically gets the IP address of the Pi'''
ni.ifaddresses('eth0')
IP = ni.ifaddresses('eth0')[ni.AF_INET][0]['addr']
return IP
def displayTime():
'''Sorts the time out for the app'''
localtime = time.asctime( time.localtime(time.time()) ) #Gets the time
print (" * Current time :" + str(localtime)) #Displays Time