commit fcbc41d9f3098929815fcf0445138a4d1f2f73cd
parent f3ff5bbb64765a9670a06c07800acf88536fe54d
Author: rob <rob@tarina.org>
Date: Fri, 26 Aug 2022 10:28:24 +0300
starta givarna i -20 nice
Diffstat:
3 files changed, 19 insertions(+), 32 deletions(-)
diff --git a/install.sh b/install.sh
@@ -12,7 +12,7 @@ After=multi-user.target
[Service]
Type=simple
-ExecStart=/usr/bin/python3 $installfolder/rastabrew.py
+ExecStart=$installfolder/startgivarna.sh
User=pi
Restart=always
RestartSec=3
diff --git a/ride_on.py b/ride_on.py
@@ -17,12 +17,6 @@ db_local = basedir+'rastabrew.db'
db = web.database(dbn='sqlite', db=db_local)
db2 = web.database(dbn=config.dbn, host=config.host, user=config.user, port=config.port, db=config.db, pw=config.pw)
-os.system('pkill -9 brew1')
-os.system('pkill -9 brew2')
-time.sleep(1)
-os.system(basedir + 'brew1 &')
-os.system(basedir + 'brew2 &')
-
term = Terminal()
with Onewire('u') as o:
@@ -33,14 +27,6 @@ with Onewire('u') as o:
temp2 = o.sensor('28.2F1F7C060000').temperature
print('Humidity: ' + humidity + ' Temp: ' + temp1 + ' Temp2: ' + temp2)
-def save_givarna(brew1, brew2, lastsave):
- b1, b2 = lastsave
- totbubs = int(brew1) - b1, int(brew2) - b2
- f = open(basedir+'totbubs', 'wb')
- pickle.dump(totbubs,f)
- f.close()
- return totbubs
-
def read_givarna():
brew1 = 0
brew2 = 0
@@ -91,36 +77,33 @@ brew2_old = 0
brew1_name = "rastabrew-1"
brew2_name = "rastabrew-2"
-def load_givare(n):
- try:
- f = open(basedir+'totbubs'+str(n), 'rb')
- totbubs = pickle.load(f)
- f.close()
- except:
- totbubs = 0
+def load_givare(viken):
+ totbubs = db.select('last', where="id=1", what=viken)[0]
return totbubs
-def save_givare(addbubs, n):
- totbubs = load_givare(n)
- totbubs = totbubs + addbubs
- f = open(basedir+'totbubs'+str(n), 'wb')
- pickle.dump(totbubs,f)
- f.close()
+def save_givare(addbubs, viken):
+ totbubs = load_givare(viken)
+ if viken == 'brew1':
+ totbubs = totbubs.brew1 + addbubs
+ db.update('last', where="id=1", tid=datetime.datetime.now(), brew1=totbubs)
+ if viken == 'brew2':
+ totbubs = totbubs.brew2 + addbubs
+ db.update('last', where="id=1", tid=datetime.datetime.now(), brew2=totbubs)
return totbubs
brew1_old, brew2_old = read_givarna()
-totbubs1 = load_givare(1)
-totbubs2 = load_givare(2)
+totbubs1 = load_givare('brew1').brew1
+totbubs2 = load_givare('brew2').brew2
while True:
brew1, brew2 = read_givarna()
if brew1_old < brew1:
addbubs = brew1 - brew1_old
- totbubs1 = save_givare(addbubs, 1)
+ totbubs1 = save_givare(addbubs,'brew1')
brew1_old = brew1
if brew2_old < brew2:
addbubs = brew2 - brew2_old
- totbubs2 = save_givare(addbubs, 2)
+ totbubs2 = save_givare(addbubs,'brew2')
brew2_old = brew2
with Onewire('u') as o:
devices = o.get()
diff --git a/startgivarna.sh b/startgivarna.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+sudo nice -n -20 ./brew1 &
+sudo nice -n -20 ./brew2 &