diff --git a/obp60v.conf-sample b/obp60v.conf-sample index 076c5a0..e43205a 100644 --- a/obp60v.conf-sample +++ b/obp60v.conf-sample @@ -45,6 +45,7 @@ mqtt_user = demo mqtt_pass = 123456 orgname = demo passcode = 123456 +trace = false [boat] name = MY boat diff --git a/obp60v.py b/obp60v.py index 1f311b0..5af1357 100755 --- a/obp60v.py +++ b/obp60v.py @@ -750,6 +750,7 @@ if __name__ == "__main__": cfg['tracker']['orgname'] = config.get('tracker', 'orgname') cfg['tracker']['passcode'] = config.get('tracker', 'passcode') cfg['tracker']['logdir'] = cfg['logdir'] + cfg['tracker']['trace'] = config.getboolean('tracker', 'trace') # Boat data cfg['boat']['name'] = config.get('boat', 'name') diff --git a/tracker.py b/tracker.py index ecd0258..adc1613 100644 --- a/tracker.py +++ b/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()