Tracker weiter verbessert
This commit is contained in:
parent
f47379b6d3
commit
f6f515ea14
|
@ -139,10 +139,13 @@ class RaceTracker(Page):
|
||||||
elif buttonid == 4:
|
elif buttonid == 4:
|
||||||
if self.mode == 'C':
|
if self.mode == 'C':
|
||||||
# Set / Select regatta
|
# Set / Select regatta
|
||||||
|
# TODO Nur möglich wenn nicht in einer anderen Wettfahrt gerade aktiv
|
||||||
if self.menupos > 0:
|
if self.menupos > 0:
|
||||||
self.raceid = self.races[self.menupos - 1] # Nullbasiert
|
self.raceid = self.races[self.menupos - 1] # Nullbasiert
|
||||||
|
last_id = self.app.track.hero_raceid
|
||||||
self.app.track.hero_raceid = self.raceid
|
self.app.track.hero_raceid = self.raceid
|
||||||
print(f"Selected race '{self.raceid}'")
|
self.app.track.hero_mqtt_subscribe(self.raceid, last_id)
|
||||||
|
self.log.info(f"Selected race '{self.raceid}'")
|
||||||
return True
|
return True
|
||||||
elif buttonid == 5:
|
elif buttonid == 5:
|
||||||
if self.mode == 'N':
|
if self.mode == 'N':
|
||||||
|
|
32
tracker.py
32
tracker.py
|
@ -212,12 +212,21 @@ class Tracker():
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def hero_mqtt_subscribe(self, raceid, lastid=None):
|
||||||
|
topicbase = f"regattahero/racestatus/{self.hero_orgid}"
|
||||||
|
if lastid is not None:
|
||||||
|
topic = '/'.join((topicbase, lastid))
|
||||||
|
self.client.unsubscribe(topic)
|
||||||
|
self.log.info(f"Sent unsubscribe for '{topic}'")
|
||||||
|
topic = '/'.join((topicbase, raceid))
|
||||||
|
self.client.subscribe(topic)
|
||||||
|
self.log.info(f"Sent subscribe for '{topic}'")
|
||||||
|
|
||||||
def hero_giveup(self):
|
def hero_giveup(self):
|
||||||
# TODO nach Aufgabe noch ein paar Pakete senden bis dier
|
# TODO nach Aufgabe noch ein paar Pakete senden bis dier
|
||||||
# Tracker dann abgestellt wird.
|
# Tracker dann abgestellt wird.
|
||||||
self.hero_givenup = True
|
self.hero_givenup = True
|
||||||
|
|
||||||
|
|
||||||
def hero_play_audio(self, event, lang='de'):
|
def hero_play_audio(self, event, lang='de'):
|
||||||
"""
|
"""
|
||||||
Ein Event ist mit einer Audiodatei gekoppelt. Das Event trägt
|
Ein Event ist mit einer Audiodatei gekoppelt. Das Event trägt
|
||||||
|
@ -347,9 +356,8 @@ class Tracker():
|
||||||
def mqtt_on_connect(self, client, userdata, flags, rc):
|
def mqtt_on_connect(self, client, userdata, flags, rc):
|
||||||
self.mqtt_connected = False
|
self.mqtt_connected = False
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
self.log.info(f"MQTT connected, subscribing to topics")
|
self.log.info("MQTT connected, subscribing to organisation topic")
|
||||||
client.subscribe("regattahero/orgstatus/thomas")
|
client.subscribe(f"regattahero/orgstatus/{self.hero_orgid}")
|
||||||
client.subscribe("regattahero/racestatus/thomas/#")
|
|
||||||
self.mqtt_connected = True
|
self.mqtt_connected = True
|
||||||
elif rc == 1:
|
elif rc == 1:
|
||||||
self.log.error("MQTT connection refused, unacceptable protocol version")
|
self.log.error("MQTT connection refused, unacceptable protocol version")
|
||||||
|
@ -366,6 +374,7 @@ class Tracker():
|
||||||
|
|
||||||
def mqtt_on_message(self, client, userdata, msg):
|
def mqtt_on_message(self, client, userdata, msg):
|
||||||
"""
|
"""
|
||||||
|
Meldungen vom Server empfangen
|
||||||
TODO raceid über userdata? dann topic prüfen?
|
TODO raceid über userdata? dann topic prüfen?
|
||||||
"""
|
"""
|
||||||
if self.trace:
|
if self.trace:
|
||||||
|
@ -374,7 +383,7 @@ class Tracker():
|
||||||
self.trace_fh.write(msg.payload.decode())
|
self.trace_fh.write(msg.payload.decode())
|
||||||
self.trace_fh.write("\n\n")
|
self.trace_fh.write("\n\n")
|
||||||
self.trace_fh.flush()
|
self.trace_fh.flush()
|
||||||
if msg.topic == "regattahero/orgstatus/thomas":
|
if msg.topic == f"regattahero/orgstatus/{self.hero_orgid}":
|
||||||
# kommt alle 10s
|
# kommt alle 10s
|
||||||
self.hero_orgstatus = json.loads(msg.payload)
|
self.hero_orgstatus = json.loads(msg.payload)
|
||||||
|
|
||||||
|
@ -393,7 +402,7 @@ class Tracker():
|
||||||
if self.hero_orgstatus['message']:
|
if self.hero_orgstatus['message']:
|
||||||
# TODO Alarm-Funktion nutzen?
|
# TODO Alarm-Funktion nutzen?
|
||||||
pass
|
pass
|
||||||
elif msg.topic.startswith("regattahero/racestatus/thomas"):
|
elif msg.topic.startswith(f"regattahero/racestatus/{self.hero_orgid}"):
|
||||||
# kommt alle 1s
|
# kommt alle 1s
|
||||||
# dem Topic angehängt ist noch die raceid
|
# dem Topic angehängt ist noch die raceid
|
||||||
payload = json.loads(msg.payload)
|
payload = json.loads(msg.payload)
|
||||||
|
@ -452,17 +461,6 @@ class Tracker():
|
||||||
def mqtt_tracker(self, cfg, boat, appdata, boatdata):
|
def mqtt_tracker(self, cfg, boat, appdata, boatdata):
|
||||||
self.log.info("MQTT tracker enabled")
|
self.log.info("MQTT tracker enabled")
|
||||||
self.appdata = appdata
|
self.appdata = appdata
|
||||||
"""
|
|
||||||
self.boatid = boat['uuid']
|
|
||||||
self.sailno = boat['sailno']
|
|
||||||
self.boatname = boat['name']
|
|
||||||
self.boatclass = boat['class']
|
|
||||||
self.handicap = boat['handicap']
|
|
||||||
self.club = boat['club']
|
|
||||||
self.team = boat['team']
|
|
||||||
self.trace = cfg['trace']
|
|
||||||
self.hero_orgid = cfg['username']
|
|
||||||
"""
|
|
||||||
self.client.username_pw_set(username=cfg['mqtt_user'], password=cfg['mqtt_pass'])
|
self.client.username_pw_set(username=cfg['mqtt_user'], password=cfg['mqtt_pass'])
|
||||||
try:
|
try:
|
||||||
self.client.connect(cfg['mqtt_host'], cfg['mqtt_port'], 60)
|
self.client.connect(cfg['mqtt_host'], cfg['mqtt_port'], 60)
|
||||||
|
|
Loading…
Reference in New Issue