rastabrew

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

commit 175058c73523b1b01242c9f4261e497813c22ee0
Author: rob <rob@tarina.org>
Date:   Mon, 22 Aug 2022 21:37:14 +0300

first

Diffstat:
Ainstall.sh | 46++++++++++++++++++++++++++++++++++++++++++++++
Arastabrew.py | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aride_on.py | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 177 insertions(+), 0 deletions(-)

diff --git a/install.sh b/install.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +echo "run with sudo ./install.sh" + +installfolder=" $(pwd)" +echo "$installfolder" + +cat <<EOF > /etc/systemd/system/rastabrew.service +[Unit] +Description=rastabrew +After=multi-user.target + +[Service] +Type=simple +ExecStart=/usr/bin/python3 $installfolder/rastabrew.py +User=pi +Restart=always +RestartSec=3 +StandardInput=tty-force +TTYPath=/dev/tty1 + +[Install] +WantedBy=multi-user.target +EOF +systemctl enable rastabrew +systemctl daemon-reload + +cat <<EOF > /etc/systemd/system/ride_on.service +[Unit] +Description=ride_on +After=multi-user.target + +[Service] +Type=simple +ExecStart=/usr/bin/python3 $installfolder/ride_on.py +User=pi +Restart=always +RestartSec=3 +StandardInput=tty-force +TTYPath=/dev/tty1 + +[Install] +WantedBy=multi-user.target +EOF +systemctl enable ride_on +systemctl daemon-reload diff --git a/rastabrew.py b/rastabrew.py @@ -0,0 +1,75 @@ +#!/bin/env python3 + +import os +import time +import RPi.GPIO as GPIO +from blessed import Terminal +import datetime +import web + + + +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 + +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: + if bubble1time == 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() + time.sleep(0.01) + print(term.clear) + print('Blub blub *.0 o ' + str(bubbles) + ' bubble counter') + if brewerishere: + print('Brewer is here') + #code.interact(local=locals()) + diff --git a/ride_on.py b/ride_on.py @@ -0,0 +1,56 @@ +#!/bin/env python3 + +import os +import time +from onewire import Onewire +import RPi.GPIO as GPIO +from blessed import Terminal +import datetime +import web + + +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 + +term = Terminal() + +with Onewire('u') as o: + devices = o.get() + print(devices) + humidity = o.sensor('26.CD0492010000').humidity + temp1 = o.sensor('26.CD0492010000').temperature + temp2 = o.sensor('28.2F1F7C060000').temperature + print('Humidity: ' + humidity + ' Temp: ' + temp1 + ' Temp2: ' + temp2) + +GPIO.setmode(GPIO.BCM) +GPIO.setup(17, GPIO.OUT) #LAMP RELAY +GPIO.setup(4, GPIO.IN) # PIR1 + +brewerishere = False + +while True: + if GPIO.input(4): + brewerishere = True + else: + brewerishere = False + 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') + time.sleep(10) + if brewerishere: + print('Brewer is here') + GPIO.output(17, GPIO.HIGH) + #code.interact(local=locals()) +