Skip to content

Instantly share code, notes, and snippets.

@Bouni
Created October 1, 2019 16:55
Show Gist options
  • Save Bouni/2b660831ef4936454a65a1dec1dcffce to your computer and use it in GitHub Desktop.
Save Bouni/2b660831ef4936454a65a1dec1dcffce to your computer and use it in GitHub Desktop.
Luxtronik Broadcast detection
import struct
import socket
import time
def searchHeatpumps(own_ip, brdcast):
"""Multicast shout out for luxtronik heatpumps."""
for p in (4444, 47808):
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
server.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
server.bind(("", p))
server.settimeout(2)
# send wired brodcast packet
data = "2000;111;1;\u0000".encode()
server.sendto(data, (brdcast, p))
while True:
try:
res, con = server.recvfrom(1024)
# if we receive what we just sent, continue
if con[0] == own_ip:
continue
# if the response starts with the magic nonsense
if res.startswith(b"2500;111"):
res = res.split(b";")
return (con[0], int(res[2]))
# if not, continue
else:
continue
# if the timout triggers, go on an use the other broadcast port
except socket.timeout:
break
IP = "192.168.178.15"
BROADCAST = "192.168.178.255"
print(searchHeatpumps(IP, BROADCAST))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment