summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack the Ripper <jack@x4.2.localnet.cc>2015-11-15 10:50:45 +0100
committerYves Fischer <yvesf-git@xapek.org>2017-01-03 21:14:50 +0100
commite3494d280fd6e2db591ea40c4365cdf18524fbdc (patch)
tree2811407c3c2049d462f47df8020da53e12affe35
parent8d6ccf54a7c1e763e016a82bdce31a19ed94a444 (diff)
downloadusv_tools-e3494d280fd6e2db591ea40c4365cdf18524fbdc.tar.gz
usv_tools-e3494d280fd6e2db591ea40c4365cdf18524fbdc.zip
- workaround for timeout error
- improved logging - disabled apscheduler in support of a simple sleep()
-rwxr-xr-x.gitignore1
-rwxr-xr-xusv_driver.py3
-rwxr-xr-xusv_scheduler.py33
3 files changed, 30 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index 354491d..7821041 100755
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
*.py[cod]
*~
+log/*
# C extensions
*.so
diff --git a/usv_driver.py b/usv_driver.py
index c8ba8bc..5cb1167 100755
--- a/usv_driver.py
+++ b/usv_driver.py
@@ -7,7 +7,8 @@ import re
class Usv(object):
def __init__(self, device, baudrate, json_file):
self._serial_port = serial.Serial(device,
- baudrate=baudrate)
+ baudrate=baudrate,
+ timeout=10)
# force a clean prompt
self._serial_port.write(b"\r")
diff --git a/usv_scheduler.py b/usv_scheduler.py
index 1dccc5f..09bcf2b 100755
--- a/usv_scheduler.py
+++ b/usv_scheduler.py
@@ -1,5 +1,7 @@
#!/usr/bin/env python3
+from time import sleep
+
from apscheduler.schedulers.background import BlockingScheduler
from usv_driver import Usv
from influxdb import InfluxDBClient
@@ -10,7 +12,6 @@ import logging
INTERVAL=14 # execution takes about 6s
-logging.basicConfig(level=logging.INFO)
parser = argparse.ArgumentParser()
parser.add_argument('--host', help='Database host', default='localhost')
@@ -21,16 +22,26 @@ parser.add_argument('--baud', help='Serial baudrate', default='600')
parser.add_argument('--param', help='Parameter JSON file', default='./usv_param.json')
args = parser.parse_args(sys.argv[1:])
-scheduler = BlockingScheduler(timezone="Europe/Berlin")
+#scheduler = BlockingScheduler(timezone="Europe/Berlin")
db_client = InfluxDBClient(host=args.host,
port=args.port,
database=args.db)
+logging.basicConfig(level=logging.ERROR, filename='log/usv_scheduler.log')
+
usv = Usv(args.serial, int(args.baud), args.param)
+usv_lock = False
-@scheduler.scheduled_job('interval', seconds=INTERVAL)
+#@scheduler.scheduled_job('interval', seconds=INTERVAL)
def timed_job():
+ global usv_lock
+
+ if usv_lock:
+ logging.info("JOB CURRENTLY LOCKED")
+ return
+
+ usv_lock = True
parameters = usv.get_parameters()
data = []
for name in parameters:
@@ -42,8 +53,18 @@ def timed_job():
},
'fields': {'value': parameters[name]}
});
- logging.info("insert: %s: %s" % (name, parameters[name]))
+ print("insert: %s" % ",".join("%s=%s" % \
+ (name,parameters[name]) for name in parameters))
- db_client.write_points(data)
+ try:
+ db_client.write_points(data)
+ except Exception as e:
+ logging.error("%s" % e)
+
+ usv_lock = False
+
+while True:
+ timed_job()
+ sleep(24)
-scheduler.start()
+#scheduler.start()