Compare commits
1 Commits
dbee6b8287
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 50987bec90 |
@@ -147,7 +147,12 @@ class Controller:
|
||||
self.mqtt_client.publish_sensor_value(uuid, "temp_delta", temp_delta / 1000.0)
|
||||
self.mqtt_client.publish_sensor_value(uuid, "max_interval", max_interval)
|
||||
self.mqtt_client.publish_sensor_value(uuid, "batt_interval", batt_interval)
|
||||
elif msg_type == "ping":
|
||||
self.logger.debug(f"[{uuid}] Ping frame received (seq={seq_counter})")
|
||||
else:
|
||||
if msg_type == "ping":
|
||||
self.logger.debug(f"[{uuid}] Ping frame received before MQTT sync (seq={seq_counter})")
|
||||
return
|
||||
self.logger.info(f"[{uuid}] Wert geparkt ({msg_type}, warte auf MQTT Sync)...")
|
||||
|
||||
def handle_mqtt_sync(self, uuid, retained_lost_packets):
|
||||
|
||||
@@ -38,14 +38,17 @@ class UDPListener:
|
||||
# Header (12 Bytes): 1B Version, 1B Type, 8s Device-ID, 1H Sequence Counter
|
||||
# Payload Temp: 1i (4 Bytes Signed Int) -> Gesamtlänge 16
|
||||
# Payload Batt: 1H (2 Bytes Unsigned Short) -> Gesamtlänge 14
|
||||
# Payload Ping: leer -> Gesamtlänge 12 (nur Header)
|
||||
|
||||
FORMAT_TEMP = "!BB8sHi"
|
||||
FORMAT_BATT = "!BB8sHH"
|
||||
FORMAT_CONFIG = "!BB8sHHHHH"
|
||||
FORMAT_PING = "!BB8sH"
|
||||
|
||||
SIZE_TEMP = struct.calcsize(FORMAT_TEMP) # 16 Bytes
|
||||
SIZE_BATT = struct.calcsize(FORMAT_BATT) # 14 Bytes
|
||||
SIZE_CONFIG = struct.calcsize(FORMAT_CONFIG) # 12 Bytes
|
||||
SIZE_PING = struct.calcsize(FORMAT_PING) # 12 Bytes
|
||||
|
||||
|
||||
|
||||
@@ -114,6 +117,24 @@ class UDPListener:
|
||||
ip_address=addr[0] # Die IPv6-Adresse des nRF52
|
||||
)
|
||||
|
||||
elif payload_type == 0xFF: # PAYLOAD_TYPE_PING
|
||||
if len(data) != SIZE_PING:
|
||||
self.logger.warning(f"Ungültige Größe für Ping-Paket: {len(data)} statt {SIZE_PING}")
|
||||
continue
|
||||
|
||||
version, p_type, device_id_raw, seq = struct.unpack(FORMAT_PING, data)
|
||||
|
||||
if version != 1:
|
||||
continue
|
||||
|
||||
self.controller.process_udp_packet(
|
||||
msg_type="ping",
|
||||
seq_counter=seq,
|
||||
value=None,
|
||||
uuid=device_id_raw.hex(),
|
||||
ip_address=addr[0] # Die IPv6-Adresse des nRF52
|
||||
)
|
||||
|
||||
else:
|
||||
self.logger.warning(f"Unbekannter Payload-Typ 0x{payload_type:02x} von {addr[0]}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user