diff options
author | Marc Lasch <mlasch@mailbox.org> | 2017-04-16 17:20:38 +0200 |
---|---|---|
committer | Marc Lasch <mlasch@mailbox.org> | 2017-04-16 17:20:38 +0200 |
commit | 80d80c305eb3f1227ebd88bdfb2840deb9b43682 (patch) | |
tree | 54843260ba7522a375f3e2a5fd36a9e45fd0bb68 /usv_scheduler.py | |
parent | d50ca49bb9dcf5640487df2044b62d63432b6764 (diff) | |
parent | e3494d280fd6e2db591ea40c4365cdf18524fbdc (diff) | |
download | usv_tools-80d80c305eb3f1227ebd88bdfb2840deb9b43682.tar.gz usv_tools-80d80c305eb3f1227ebd88bdfb2840deb9b43682.zip |
Diffstat (limited to 'usv_scheduler.py')
-rwxr-xr-x | usv_scheduler.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/usv_scheduler.py b/usv_scheduler.py index 95accaf..ff99818 100755 --- a/usv_scheduler.py +++ b/usv_scheduler.py @@ -1,4 +1,10 @@ #!/usr/bin/env python3 +<<<<<<< HEAD +======= + +from time import sleep + +>>>>>>> e3494d280fd6e2db591ea40c4365cdf18524fbdc from apscheduler.schedulers.background import BlockingScheduler from usv_driver import Usv from urllib.request import urlopen @@ -9,7 +15,12 @@ import argparse import logging from time import sleep +<<<<<<< HEAD INTERVAL=24 # execution takes about 6s +======= +INTERVAL=14 # execution takes about 6s + +>>>>>>> e3494d280fd6e2db591ea40c4365cdf18524fbdc parser = argparse.ArgumentParser() parser.add_argument('--url', help='URL') @@ -18,16 +29,40 @@ 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:]) +<<<<<<< HEAD logging.basicConfig(level=logging.DEBUG, filename='log/usv_scheduler.log', format='%(asctime)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S') +======= +#scheduler = BlockingScheduler(timezone="Europe/Berlin") + +db_client = InfluxDBClient(host=args.host, + port=args.port, + database=args.db) +>>>>>>> e3494d280fd6e2db591ea40c4365cdf18524fbdc + +logging.basicConfig(level=logging.ERROR, filename='log/usv_scheduler.log') usv = Usv(args.serial, int(args.baud), args.param) +<<<<<<< HEAD +======= +usv_lock = False + +#@scheduler.scheduled_job('interval', seconds=INTERVAL) +>>>>>>> e3494d280fd6e2db591ea40c4365cdf18524fbdc 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: +<<<<<<< HEAD line = Line('usv_parameters', {'name': name, 'id': 'LI????VA' }, @@ -50,3 +85,28 @@ while True: timed_job() sleep(INTERVAL) +======= + data.append({ + 'measurement': 'usv_parameters', + 'tags': { + 'name': name, + 'id': 'LI????VA', + }, + 'fields': {'value': parameters[name]} + }); + print("insert: %s" % ",".join("%s=%s" % \ + (name,parameters[name]) for name in parameters)) + + 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() +>>>>>>> e3494d280fd6e2db591ea40c4365cdf18524fbdc |