Skip to content

Commit

Permalink
updated app, install.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
mayorquinmachines committed Mar 19, 2018
1 parent 0ec64c4 commit 53f8301
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.pyc
app/config.py
68 changes: 53 additions & 15 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from flask import Flask
from flask import render_template, Response, request
from flask_ask import Ask, statement, session
from pyowm import OWM
from datetime import datetime
from config import *

app=Flask(__name__)
ask = Ask(app, '/')
Expand All @@ -11,7 +14,7 @@ def all_logs():
log_lst = []
lst = sorted(glob.glob('/home/pi/kindbot/app/logs/kindbot.*'), reverse=True)
for fl in lst:
with open(fl, 'r') as f:
with open(fl, 'rb') as f:
dict_str = f.read()
log_lst.append(eval(dict_str))
return log_lst
Expand All @@ -28,55 +31,90 @@ def dashboard():
read_dict = eval(last_rd)
all_l = all_logs()
time_data = [str(x['Time']) for x in all_l]
temp_data= [int(x['Temperature']) for x in all_l]
humid_data = [int(x['Humidity']) for x in all_l]
return render_template('dashboard.html', temp=str(read_dict['Temperature']), hum=str(read_dict['Humidity']),
lux=str(read_dict['Lumens']), time_data=time_data, temp_data=temp_data, humid_data=humid_data)
temp_data = [int(x['Temperature']) for x in all_l]
return render_template('dashboard.html', temp=str(read_dict['Temperature']), hum=str(read_dict['Humidity']), lux=str(read_dict['Lumens']), time_data=time_data, humid_data=humid_data, temp_data=temp_data)

@app.route('/camera')
def camera():
pic_lst = ['../static/images/' + str(x) for x in os.listdir("static/images")]
pic_lst = ['../static/images/' + str(x) for x in os.listdir("/home/pi/kindbot/app/static/images")]
pic_lst.sort()
pic_lst = pic_lst[::-1]
return render_template('camera.html', pic_lst=pic_lst)

@app.route('/automate', methods=['POST', 'GET'])
def automate():
if os.path.exist("/home/pi/kindbot/app/logs/schedule_app.logs"):
try:
with open("/home/pi/kindbot/app/logs/schedule_app.logs", "rb") as fl:
event_lst = fl.readlines()
events = [{'id': x['id'], 'start': x['date']+'T'+x['time']}]
else:
except:
events = []
if request.method == 'POST':
date = request.form['date']
time = request.form['time']
monday = request.form.get("monday") != None
tuesday = request.form.get("tuesday") != None
wednesday = request.form.get("wednesday") != None
wednesday = request.form.get("wednesday") != None
thursday = request.form.get("thursday") != None
friday = request.form.get("friday") != None
saturday = request.form.get("saturday") != None
sunday = request.form.get("sunday") != None
saturday = request.form.get("saturday") != None
sunday = request.form.get("sunday") != None
with open('/home/pi/kindbot/app/logs/schedule_app.logs', 'a') as fl:
schedule_dict = {'date': date, 'time': time, 'repeat': {'monday':monday, 'tuesday': tuesday, 'wednesday': wednesday, 'thursday':thursday, 'friday': friday, 'saturday': saturday, 'sunday': sunday}, 'id'=str(random.randint(1,10000))}
schedule_dict = {'date': date, 'time': time, 'id': '10','repeat': {'monday':monday, 'tuesday': tuesday, 'wednesday': wednesday, 'thursday':thursday, 'friday': friday, 'saturday': saturday, 'sunday': sunday}}
fl.write(str(schedule_dict) + '\n')
return render_template('automate.html', events=events)

@app.route('/settings')
def settings():
return render_template('settings.html')


############### Alexa Intents #################

def lux_checker(lux):
if int(lux) < 30000:
return "It's a bit dark in here. Try moving the light closer."
if int(lux) == 0:
return "Your lights are off."
elif 30000 < int(lux) < 50000:
return "The lighting is spot on!"
elif int(lux) > 50000:
return "Blinded by the light! Try moving the light further away."



@ask.intent('stats')
def stats():
""" Returns last reading """
temps_lst = []
owm = OWM(OWM_APIKEY)
fc = owm.three_hours_forecast('Berkeley,CA')
f = fc.get_forecast()
for weather in f:
tm_stmp = datetime.fromtimestamp(weather.get_reference_time()).strftime('%Y-%m-%d %H:%M:%S')
temp = 9 / 5 * (weather.get_temperature()['temp'] - 273.15) + 32
humi = weather.get_humidity()
dd = {'tm_stmp': tm_stmp, 'temp': temp, 'humid': humi}
temps_lst.append(dd)
with open('/home/pi/kindbot/app/logs/kindbot.log', 'rb') as fl:
last_rd = fl.read()
read_dict = eval(last_rd)
speech_text = 'Last reading was taken at %s. The temperature is %s degrees Fahrenheit and humidity is at %s percent. The lux levels are %s.' % (read_dict['Time'], read_dict['Temperature'],read_dict['Humidity'], read_dict['Lumens'])
try:
alert = next(x for x in temps_lst if x['temp'] < 40 or x['temp'] > 85)
except:
alert = None
lux = int(round(read_dict['Lumens'], -3))
lux_sentence = lux_checker(lux)
speech_text = "Last reading was taken at %s. The temperature is %s degrees Fahrenheit and humidity is at %s percent. " % (read_dict['Time'][:-3], read_dict['Temperature'],read_dict['Humidity']) + lux_sentence
if alert:
if alert['temp'] < 40:
tt = 'cold.'
elif alert['temp'] > 85:
tt = 'hot.'
date_a = alert['tm_stmp'].split(' ')[0]
ddate = datetime.strptime(date_a, '%Y-%m-%d')
date_alert = ddate.strftime("%A, %B %d")
speech_text = speech_text + ' Heads up: '+ date_alert + ' will be ' + tt
return statement(speech_text)


Expand All @@ -100,10 +138,10 @@ def dripoff():
@ask.intent('photo')
def photo():
""" Show image of grow """
pic_lst = ['/static/images/' + str(x) for x in os.listdir("static/images")]
pic_lst = ['/static/images/' + str(x) for x in os.listdir("/home/pi/kindbot/app/static/images")]
pic_lst.sort()
last_pic = pic_lst[-1]
pic_url = <your URL string> + last_pic
pic_url = 'https://kindbot.ngrok.io' + last_pic
speech_text = 'Here is your grow!'
return statement(speech_text).display_render(template='BodyTemplate7', title='kindbot', backButton='HIDDEN', token=None, background_image_url=pic_url, text=None, hintText=None)

Expand Down
1 change: 1 addition & 0 deletions app/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OWM_APIKEY = '06ba6107b199daf4e3ef605f2d860127'
8 changes: 5 additions & 3 deletions install.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ sudo apt-get install python3-pip python3-dev -y
sudo apt-get install libblas-dev liblapack-dev python-dev libatlas-base-dev gfortran python-setuptools -y
cd ~/
echo 'Installing TensorFlow now...'
wget https://ci.tensorflow.org/view/Nightly/job/nightly-pi-zero-python3/lastSuccessfulBuild/artifact/output-artifacts/tensorflow-1.6.0-cp34-none-any.whl
sudo pip3 install tensorflow-1.6.0-cp34-none-any.whl
wget https://ci.tensorflow.org/view/Nightly/job/nightly-pi-zero-python3/38/artifact/output-artifacts/tensorflow-1.4.0-cp34-none-any.whl
sudo pip3 install tensorflow-1.4.0-cp34-none-any.whl
echo 'DONE installing TensorFlow!'
echo

echo 'Installing darkflow'
sleep 10
cd /home/pi/
sudo pip3 install Cython
git clone https://github.com/thtrieu/darkflow.git
cd darkflow
cd /home/pi/darkflow
sed -i 's/self.offset = 16/self.offset = 20/g' /home/pi/darkflow/darkflow/utils/loader.py
python3 setup.py build_ext --inplace
sudo pip3 install .
Expand Down

0 comments on commit 53f8301

Please sign in to comment.