Dummy Waage - initial value from last one
This commit is contained in:
parent
ba036ac413
commit
2649fb579b
|
|
@ -10,7 +10,7 @@ scales:
|
||||||
scale_uuid: "46335715-8454-483b-a17b-571619c5015e"
|
scale_uuid: "46335715-8454-483b-a17b-571619c5015e"
|
||||||
interface_type: dummy
|
interface_type: dummy
|
||||||
sms_alert_phonenumbers:
|
sms_alert_phonenumbers:
|
||||||
- "+41765006124"
|
- "+41765006123"
|
||||||
read_scale_interval_sec: 300
|
read_scale_interval_sec: 300
|
||||||
number_of_samples: 5
|
number_of_samples: 5
|
||||||
swarm_alarm_threshold_gram: 500
|
swarm_alarm_threshold_gram: 500
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ import time
|
||||||
import yaml
|
import yaml
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
import glob
|
||||||
|
import re
|
||||||
|
|
||||||
# Root Path
|
# Root Path
|
||||||
APP_ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
APP_ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
|
@ -31,6 +33,27 @@ with open("%s/bin/beielimon-config.yaml" % (APP_ROOT), 'r') as stream:
|
||||||
# Constants
|
# Constants
|
||||||
INVALID_VALUE = -999
|
INVALID_VALUE = -999
|
||||||
|
|
||||||
|
# Wegen der Dummy-Waage moechten wir den letzten Messwert holen koennen
|
||||||
|
def GetLastStoredValue(scale_uuid):
|
||||||
|
files = glob.glob("%s/data/weight-%s-????????.log" % (APP_ROOT,scale_uuid))
|
||||||
|
if len(files) > 0:
|
||||||
|
with open(sorted(files)[-1], "r") as f:
|
||||||
|
for line in f: pass
|
||||||
|
result = line
|
||||||
|
|
||||||
|
|
||||||
|
# Beispiel: 2017-11-07 08:23,0
|
||||||
|
m = re.match("(\d{4})-(\d{2})-(\d{2}) (\d\d:\d\d),(\d+)", result)
|
||||||
|
if m:
|
||||||
|
return int("%s" % (m.group(5)))
|
||||||
|
else:
|
||||||
|
return INVALID_VALUE
|
||||||
|
|
||||||
|
else:
|
||||||
|
return INVALID_VALUE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Scale(object):
|
class Scale(object):
|
||||||
def __init__(self, scale_config):
|
def __init__(self, scale_config):
|
||||||
self.last_values = []
|
self.last_values = []
|
||||||
|
|
@ -110,8 +133,14 @@ class ScaleUSB_PCE(Scale):
|
||||||
class ScaleDummy(Scale):
|
class ScaleDummy(Scale):
|
||||||
def __init__(self,scale_config):
|
def __init__(self,scale_config):
|
||||||
Scale.__init__(self, scale_config)
|
Scale.__init__(self, scale_config)
|
||||||
|
# Wir versuchen, den letzten Wert wieder zu holen
|
||||||
|
last_value = GetLastStoredValue(self.scale_config['scale_uuid'])
|
||||||
|
if last_value != INVALID_VALUE:
|
||||||
|
self.last_values = [ last_value ]
|
||||||
|
else:
|
||||||
self.last_values = [ random.randint(500,1000) ]
|
self.last_values = [ random.randint(500,1000) ]
|
||||||
|
|
||||||
|
|
||||||
def Read(self):
|
def Read(self):
|
||||||
# Gewichts- Zu/Abnahme ist Random, manchmal gibt es einen
|
# Gewichts- Zu/Abnahme ist Random, manchmal gibt es einen
|
||||||
# Zufaelligen Schwarmalarm
|
# Zufaelligen Schwarmalarm
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
iface wlan0 inet static
|
iface wlan0 inet static
|
||||||
address 192.168.255.1
|
address 192.168.255.1
|
||||||
netmask 255.255.255.0
|
netmask 255.255.255.0
|
||||||
|
wireless-power off
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ Type=simple
|
||||||
User=beieli
|
User=beieli
|
||||||
Group=beieli
|
Group=beieli
|
||||||
WorkingDirectory=/home/beieli/bin
|
WorkingDirectory=/home/beieli/bin
|
||||||
ExecStartPre=/bin/sleep 60
|
|
||||||
ExecStart=/home/beieli/bin/beielimon.py
|
ExecStart=/home/beieli/bin/beielimon.py
|
||||||
Restart=always
|
Restart=always
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ ExecStart=/usr/bin/python /home/beieli/root-bin/fakedns.py
|
||||||
ExecStop=/usr/bin/pkill -f '/usr/bin/python /home/beieli/root-bin/fakedns.py'
|
ExecStop=/usr/bin/pkill -f '/usr/bin/python /home/beieli/root-bin/fakedns.py'
|
||||||
WorkingDirectory=/home/beieli/root-bin
|
WorkingDirectory=/home/beieli/root-bin
|
||||||
Restart=always
|
Restart=always
|
||||||
|
StandardOutput=/var/log/fakedns
|
||||||
|
StandardError=/var/log/fakedns
|
||||||
User=root
|
User=root
|
||||||
Group=root
|
Group=root
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue