diff options
author | Marc Lasch <mlasch@mailbox.org> | 2017-05-01 21:32:07 +0200 |
---|---|---|
committer | Marc Lasch <mlasch@mailbox.org> | 2017-05-01 21:32:07 +0200 |
commit | bbe8426cc28a24d083cb34bac319896c61087e51 (patch) | |
tree | ceb5fb74eb5daf161e4124b9e52280f7473d05f4 | |
parent | 112f478b2fc9f5365a5e2111cde1decfb0ceff0d (diff) | |
download | usv_tools-develop.tar.gz usv_tools-develop.zip |
Deleted some old filesdevelop
-rwxr-xr-x | usv_driver.py | 78 | ||||
-rw-r--r-- | usv_param.json | 11 | ||||
-rwxr-xr-x | usv_scheduler.py | 112 |
3 files changed, 0 insertions, 201 deletions
diff --git a/usv_driver.py b/usv_driver.py deleted file mode 100755 index 4ff52ea..0000000 --- a/usv_driver.py +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env python3 - -import serial -import json -import re - -class Usv(object): - def __init__(self, device, baudrate, json_file): - self._serial_port = serial.Serial(device, - baudrate=baudrate, -<<<<<<< HEAD - timeout=0.8) -======= - timeout=10) ->>>>>>> e3494d280fd6e2db591ea40c4365cdf18524fbdc - - # force a clean prompt - #self._serial_port.write(b"\r") - self._read_until_prompt("\r") - #print("cleaned prompt") - with open(json_file) as fhandle: - self.json_params = json.load(fhandle) - - - def _read_until_prompt(self, outbuf): - # match on "\n=>" - self._serial_port.write(outbuf.encode()) - - inbuf = self._serial_port.read(100) - sbuf = inbuf.decode("utf-8") - - #prompt = False - #inbuf = [] - #while not prompt: - # pending = self._serial_port.read(1) - # if len(pending) == 0: - # self._serial_port.write(b"\r") - # else: - # inbuf.append(pending) - # print(pending) - #if len(sbuf) > 2: - # if sbuf[-3] == "\n" and \ - # sbuf[-2] == "=" and sbuf[-1] == ">": - # return sbuf - # else: - # sbuf = self._read_until_prompt(outbuf) - - return sbuf - - def get_parameters(self): - # [{'name': 'acvoltsin', 'index': 1}, - results = {} - - for parameter in self.json_params: - outbuf = "d %s\r" % parameter['num'] - inbuf = self._read_until_prompt(outbuf) - - regex = parameter['regex'] - match = re.search(regex, inbuf, re.MULTILINE) - - if match: - name = parameter['name'] - value = float(match.group(1)) - - results.setdefault(name, value) - #print("MATCH: %s: %f" % (name,value)) - - return results - - - -if __name__ == "__main__": - import pprint - - usv = Usv("/dev/ttyU0", 600, "usv_param.json") - parameters = usv.get_parameters() - pprint.pprint(parameters) - diff --git a/usv_param.json b/usv_param.json deleted file mode 100644 index 39e5698..0000000 --- a/usv_param.json +++ /dev/null @@ -1,11 +0,0 @@ -[{"name": "acvoltsin", "num": 1, "regex": "01\\ V\\ In\\ +([0-9]+[.]?[0-9]*)"}, -{"name": "acvoltsout", "num": 2, "regex": "02\\ V\\ Out\\ +([0-9]+[.]?[0-9]*)"}, -{"name": "vaout", "num": 5, "regex": "05\\ VA\\ Out\\ +([0-9]+[.]?[0-9]*)"}, -{"name": "vbattery", "num": 7, "regex": "07\\ V\\ Batt\\ +([0-9]+[.]?[0-9]*)"}, -{"name": "frequency", "num": 8, "regex": "08\\ Freq\\ ([0-9]+[.]?[0-9]*)\\ Hz"}, -{"name": "fullload", "num": 16, "regex": "16\\ FullLoad%\\ ([0-9]+[.]?[0-9]*)"}, -{"name": "watts", "num": 17, "regex": "17\\ Watts\\ +([0-9]+[.]?[0-9]*)"}, -{"name": "powerfactor", "num": 18, "regex": "18\\ PF\\ +([0-9]+[.]?[0-9]*)\\ ----"}, -{"name": "crestfactor", "num": 19, "regex": "19\\ CrestF\\ +([0-9]+[.]?[0-9]*)"}, -{"name": "powerout", "num": 20, "regex": "20\\ #PwrOut\\ +([0-9]+[.]?[0-9]*)"}, -{"name": "inverterminutes", "num": 23, "regex": "23\\ InvMin\\ +([0-9]+[.]?[0-9]*)"}] diff --git a/usv_scheduler.py b/usv_scheduler.py deleted file mode 100755 index ff99818..0000000 --- a/usv_scheduler.py +++ /dev/null @@ -1,112 +0,0 @@ -#!/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 -from pyinflux.client import Line - -import sys -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') -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:]) - -<<<<<<< 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' }, - {'value': parameters[name]}) - data.append(line) - logging.info("insert: {}".format(",".join( - "{}={}".format(name,parameters[name]) for name in parameters))) - - try: - post_data = '\n'.join(map(str, data)) - logging.info("urlopen begin: {}".format(post_data)) - with urlopen(args.url, post_data.encode('utf-8')) as fh: - logging.info(fh.read().decode('utf-8')) - logging.info("urlopen done") - - except Exception as e: - logging.error("Errr while trying to insert", e) - -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 |