Trace-Modus für den Tracker
This commit is contained in:
21
tracker.py
21
tracker.py
@@ -27,6 +27,9 @@ class Tracker():
|
||||
raise TypeError(f"Invalid tracker type: '{valtype}'. Only supported: {validtypes}")
|
||||
self.ttype = trackertype
|
||||
self.activated = False
|
||||
self.trace = False # Debugging
|
||||
self.trace_fh = None # File Handle der Tracedatei
|
||||
|
||||
self.races = set() # Liste der Regatten, eindeutige Namen
|
||||
self.courses = set() # Liste der Bahnen, eindeutige Namen
|
||||
|
||||
@@ -74,6 +77,12 @@ class Tracker():
|
||||
"""
|
||||
TODO raceid über userdata? dann topic prüfen?
|
||||
"""
|
||||
if self.trace:
|
||||
self.trace_fh.write(msg.topic)
|
||||
self.trace_fh.write("\n")
|
||||
self.trace_fh.write(msg.payload.decode())
|
||||
self.trace_fh.write("\n\n")
|
||||
self.trace_fh.flush()
|
||||
if msg.topic == "regattahero/orgstatus/thomas":
|
||||
# kommt alle 10s
|
||||
orgstatus = json.loads(msg.payload)
|
||||
@@ -127,6 +136,7 @@ class Tracker():
|
||||
|
||||
def mqtt_tracker(self, cfg, boat, appdata, boatdata):
|
||||
print("MQTT tracker enabled")
|
||||
self.trace = cfg['trace']
|
||||
client = mqtt.Client()
|
||||
client.on_connect = self.mqtt_on_connect
|
||||
client.on_message = self.mqtt_on_message
|
||||
@@ -137,9 +147,10 @@ class Tracker():
|
||||
print("MQTT connection refused. Check username and password.")
|
||||
return
|
||||
|
||||
tracefile = os.path.join(os.path.expanduser(cfg['logdir']), 'tracker.log')
|
||||
trace_fh = open(tracefile, 'w+')
|
||||
client.user_data_set({'trace': trace_fh})
|
||||
if cfg['trace']:
|
||||
# TODO Log Hinweis
|
||||
tracefile = os.path.join(os.path.expanduser(cfg['logdir']), 'tracker.log')
|
||||
self.trace_fh = open(tracefile, 'w+')
|
||||
|
||||
topic = "regattahero/tracker/" + cfg['orgname']
|
||||
payload = {
|
||||
@@ -176,7 +187,7 @@ class Tracker():
|
||||
time.sleep(1)
|
||||
if appdata.track.is_active():
|
||||
self.mqtt_publish(client, topic, payload, bv_lat, bv_lon, bv_sog)
|
||||
print("MQTT tracker shutdown")
|
||||
client.loop_stop()
|
||||
client.disconnect()
|
||||
trace_fh.close()
|
||||
if cfg['trace']:
|
||||
self.trace_fh.close()
|
||||
|
||||
Reference in New Issue
Block a user