]> OzVa Git service - doomsday-clock/commitdiff
Added binding to specific interface automatically
authorwill <greenwoodw50@gmail.com>
Mon, 19 Aug 2024 22:11:12 +0000 (23:11 +0100)
committerwill <greenwoodw50@gmail.com>
Mon, 19 Aug 2024 22:11:12 +0000 (23:11 +0100)
interface name is currently hard-coded as "wlo1" for testing reasons

clock.py

index 759fbe891d52d16d6f1366e9edfc896c2ebb7378..44cf4f4dfb19a73f451902398f7e8d997566d60a 100755 (executable)
--- a/clock.py
+++ b/clock.py
@@ -8,6 +8,9 @@ import time
 import sacn
 import sys
 import os
+import socket
+import struct
+import fcntl
 
 # fake GPIO dummy class for debuging
 class dummy():
@@ -123,7 +126,13 @@ class clock():
        def light(self):
                print("starting lighting service...")
 
-               sender = sacn.sACNsender()
+               sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+               packed_interface = struct.pack('256s', "wlo1".encode('utf_8'))
+               packed_address = fcntl.ioctl(sock.fileno(), 0x8915, packed_interface)[20:24]
+               ip = socket.inet_ntoa(packed_address)
+               print(f"bound to {ip}...")
+
+               sender = sacn.sACNsender(bind_address=ip, source_name="doomsday")
                sender.start()
                sender.activate_output(2)
                sender[2].multicast = True