Skip to content
Permalink
Browse files
initial commit
  • Loading branch information
hollan84 committed Dec 2, 2019
0 parents commit 0facfdd322ef8a951bf8c9e05e3228b53df48745
Show file tree
Hide file tree
Showing 17 changed files with 928 additions and 0 deletions.
@@ -0,0 +1 @@
# SmartBoat-V2
@@ -0,0 +1,84 @@
import RPi.GPIO as GPIO

import time

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

outpins = [22, 23, 24]

relayNumber = 2

for i in outpins:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, GPIO.HIGH)

def Shift(output, relayNumber):
for i in range(8*relayNumber):
if output[i] == "1":
GPIO.output(23, GPIO.LOW)
elif output[i] == "0":
GPIO.output(23, GPIO.HIGH)
else:
print("ERROR")
GPIO.output(22, GPIO.HIGH)
GPIO.output(22, GPIO.LOW)
GPIO.output(24, GPIO.HIGH)
GPIO.output(24, GPIO.LOW)

def demo(relayNumber):
connected = 12
timer = 0.1
while True:
for i in range(connected):
output = (i-1)*"0" + "1" + (8*relayNumber-i)*"0"
print(output)
Shift(output[::-1], relayNumber)
time.sleep(timer)
#timer = timer - timer/10

def checkOutput(output, relayNumber):
if len(output)>8*relayNumber:
print("Only " + str(8*relayNumber) + " bits will be displayed")
elif len(output)<8*relayNumber:
output = output + "0"*(8*relayNumber-len(output))
return output[::-1]

def binary(relayNumber):
output = input("What binary do you want to display? > ")
output = checkOutput(output, relayNumber)
Shift(output, relayNumber)
binary(relayNumber)

def relayIndex(relayNumber, currentBinary):
print(currentBinary)
output = input("What relay number do you want to toggle? > ")
if int(output) > len(currentBinary)-1:
print("This relay number doesn't exist")
elif 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)
relayIndex(relayNumber, currentBinary)

def main(relayNumber):
output = "00000000"*relayNumber
Shift(output, relayNumber)
output = input("What input do you want? Binary/Demo/Index > ")
if output == "Binary":
binary(relayNumber)
elif output == "Demo":
demo(relayNumber)
elif output == "Index":
relayIndex(relayNumber, "00000000"*relayNumber)
else:
main(relayNumber)



main(relayNumber)
@@ -0,0 +1,37 @@
'''Import all system libraries'''
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, redirect, url_for #import web app
import netifaces as ni
import RPi.GPIO as GPIO
import SystemLibrary as L

GPIO.setmode(GPIO.BCM) # choose BCM or BOARD
GPIO.setup(14, GPIO.OUT)

os.system('clear')

IP = L.get_IP()
L.displayTime()
#L.shift(str(L.getCurrentBinary), 2)

app = Flask(__name__)

global int_time
int_time = datetime.datetime.now()

@app.route('/') #Sets index
def index():
return render_template('index.html') #Displays HTML page 'Relay.html'#

@app.route('/relay/<username>', methods=['GET', 'POST'])
def checkSwitch(username):
timing = float(username)
GPIO.output(14, 0) # set GPIO24 to 1/GPIO.HIGH/True
time.sleep(timing) # wait half a second
GPIO.output(14, 1) # set GPIO24 to 0/GPIO.LOW/False
time.sleep(timing) # wait half a second
return render_template('index.html')

if __name__ == '__main__':
app.run(debug=True, host=(str(IP)), threaded=True, port=80)
GPIO.cleanup()
@@ -0,0 +1,190 @@
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

Binary file not shown.
@@ -0,0 +1 @@
10000000
@@ -0,0 +1,5 @@
r = ""
for i in range(25, 1025, 50):
r = r + '<form action="/relay/'+str(i/1000)+'"><button class="button" style ="height: 20px; float:left">'+str(i)+'ms</button></form>'
r = r + '<form action="/relay/'+str((i+25)/1000)+'"><button class="button" style ="height: 20px; float:right">'+str(i+25)+'ms</button></form>'
print(r)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN +1.36 MB static/background.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,11 @@
<HTML>
<HEAD>
<TITLE> Godiva Weather Station </TITLE>
<link rel="shortcut icon" href="static/icon.ico" />
</HEAD>
<BODY>
<H1> <CENTER> Godiva Weather Station - ALWIN </CENTER> </H1>
<H2> <CENTER> (A Live Weather Internet Network) </CENTER> </H2>
<p> <center> This Weather Station Has Been Used 10256 Times </center> </p> <p> <center> Temperature (Up to 3dp): 14.375°C </center> </p> <center> <p> Uptime: 0 day(s), 0 hour(s), 1 minute(s) and 35 second(s) </center> <center> The Highest Temperature Recorded Has Been 32.25°C <br> <center> The Lowest Temperature Recorded Has Been -2.75°C </center><iframe width="600" height="371" seamless frameborder="0" scrolling="no" src="https://docs.google.com/spreadsheets/d/e/2PACX-1vTHIxAgP9aeqUZrgdvna3HJicz-zhZWB-kh_8EreBLBLZdQTA72ad1_AQIX05qnlBJtisSIgpPubz4D/pubchart?oid=115658784&amp;format=interactive"></iframe>
</BODY>
</HTML>

0 comments on commit 0facfdd

Please sign in to comment.