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