1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
#!/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
|