diff options
author | Jack the Ripper <jack@x4.2.localnet.cc> | 2015-10-24 18:49:10 +0200 |
---|---|---|
committer | Jack the Ripper <jack@x4.2.localnet.cc> | 2015-10-24 18:49:10 +0200 |
commit | 8d6ccf54a7c1e763e016a82bdce31a19ed94a444 (patch) | |
tree | 0fd0b375aaa16cd4f438f6977c63a83cb409041b /usv_scheduler.py | |
parent | fd78184a68c60008b98b4a525565b7ab56f26b45 (diff) | |
download | usv_tools-8d6ccf54a7c1e763e016a82bdce31a19ed94a444.tar.gz usv_tools-8d6ccf54a7c1e763e016a82bdce31a19ed94a444.zip |
first working versionN,
Diffstat (limited to 'usv_scheduler.py')
-rwxr-xr-x | usv_scheduler.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/usv_scheduler.py b/usv_scheduler.py new file mode 100755 index 0000000..1dccc5f --- /dev/null +++ b/usv_scheduler.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 + +from apscheduler.schedulers.background import BlockingScheduler +from usv_driver import Usv +from influxdb import InfluxDBClient + +import sys +import argparse +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') +parser.add_argument('--port', help='Database port', default='8086') +parser.add_argument('--db', help='Database name', default='test') +parser.add_argument('--serial', help='Serial port', default='/dev/ttyU0') +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") + +db_client = InfluxDBClient(host=args.host, + port=args.port, + database=args.db) + +usv = Usv(args.serial, int(args.baud), args.param) + +@scheduler.scheduled_job('interval', seconds=INTERVAL) +def timed_job(): + parameters = usv.get_parameters() + data = [] + for name in parameters: + data.append({ + 'measurement': 'usv_parameters', + 'tags': { + 'name': name, + 'id': 'LI????VA', + }, + 'fields': {'value': parameters[name]} + }); + logging.info("insert: %s: %s" % (name, parameters[name])) + + db_client.write_points(data) + +scheduler.start() |