rastabrew

git clone https://git.tarina.org/rastabrew
Log | Files | Refs

commit 3a725a96df6489c9ea5f1438fb4a52f6d8fa9a45
parent 4e0b33109f5b272a4495a5cc02d9417d83ff2577
Author: rob <rob@tarina.org>
Date:   Tue, 23 Aug 2022 11:07:33 +0300

postgresql ftw

Diffstat:
Mrastabrew.py | 37++++---------------------------------
Mride_on.py | 13+++----------
2 files changed, 7 insertions(+), 43 deletions(-)

diff --git a/rastabrew.py b/rastabrew.py @@ -5,53 +5,30 @@ import time import RPi.GPIO as GPIO from blessed import Terminal import datetime +import requests import web - - +import config basedir = os.path.dirname(os.path.realpath(__file__)) + '/' -mount_dir = '/root/rastabrew/servu-db' -db_remote = basedir+'servu-db/rastabrew.db' db_local = basedir+'rastabrew.db' -servu_dir = 'rob@tarina.org:/srv/www/rastabrew.tarina.org/rasta-db' #db = web.database(dbn='sqlite', db=basedir + 'rastabrew.db') db = web.database(dbn='sqlite', db=db_local) -db2 = web.database(dbn='sqlite', db=db_remote) -#servu-db-connected = False +db2 = web.database(dbn=config.dbn, host=config.host, user=config.user, port=config.port, db=config.db, pw=config.pw) term = Terminal() GPIO.setmode(GPIO.BCM) GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # RASTABREW -GPIO.setup(4, GPIO.IN) # PIR1 bubbles = 0 bubble1time = False brewerishere = False -def startsshfs(): - if not os.path.exists(db_remote): - try: - os.system("umount " + "/root/servu-db") - except: - print("noting to umount or not mounting db") - try: - os.system("sshfs -p 18888 "+servu_dir+" "+mount_dir) - except: - print('could not mount servu') - -startsshfs() - start_time = time.time() get_code_time = time.time() while True: run_time = time.time() - start_time update = time.time() - get_code_time - - if GPIO.input(4): - brewerishere = True - else: - brewerishere = False if GPIO.input(22): bubble1time = True else: @@ -59,13 +36,7 @@ while True: bubbles = bubbles + 1 bubble1time = False db.insert('bubblecounter', tid=datetime.datetime.now()) - if os.path.exists(db_remote): - try: - db2.insert('bubblecounter', tid=datetime.datetime.now()) - except: - print('no permissions to write') - else: - startsshfs() + db2.insert('bubblecounter', tid=datetime.datetime.now()) time.sleep(0.01) print(term.clear) print('Blub blub *.0 o ' + str(bubbles) + ' bubble counter') diff --git a/ride_on.py b/ride_on.py @@ -7,17 +7,14 @@ import RPi.GPIO as GPIO from blessed import Terminal import datetime import web +import config basedir = os.path.dirname(os.path.realpath(__file__)) + '/' -mount_dir = '/root/rastabrew/servu-db' -db_remote = basedir+'servu-db/rastabrew.db' db_local = basedir+'rastabrew.db' -servu_dir = 'rob@tarina.org:/srv/www/rastabrew.tarina.org/rasta-db' #db = web.database(dbn='sqlite', db=basedir + 'rastabrew.db') db = web.database(dbn='sqlite', db=db_local) -db2 = web.database(dbn='sqlite', db=db_remote) -#servu-db-connected = False +db2 = web.database(dbn=config.dbn, host=config.host, user=config.user, port=config.port, db=config.db, pw=config.pw) term = Terminal() @@ -49,11 +46,7 @@ while True: print(term.clear) print('Humidity: ' + humidity + ' Temp: ' + temp1 + ' Temp2: ' + temp2) db.insert('sensors', tid=datetime.datetime.now(), pir=brewerishere, humidity=humidity, temp1=temp1, temp2=temp2) - if os.path.exists(db_remote): - try: - db2.insert('sensors', tid=datetime.datetime.now(), pir=brewerishere, humidity=humidity, temp1=temp1, temp2=temp2) - except: - print('no servu') + db2.insert('sensors', tid=datetime.datetime.now(), pir=brewerishere, humidity=humidity, temp1=temp1, temp2=temp2) time.sleep(10) if brewerishere: print('Brewer is here')