parent
2458474a61
commit
5f7b64c4b3
|
@ -92,11 +92,11 @@ def flask_api():
|
||||||
def get_eth0_ip():
|
def get_eth0_ip():
|
||||||
try:
|
try:
|
||||||
# Get the IP address of the eth0 interface
|
# Get the IP address of the eth0 interface
|
||||||
eth0_ip = netifaces.ifaddresses('eth0')[netifaces.AF_INET][0]['addr']
|
eth0_ip = str(os.system("ip -4 -o addr show eth0 | awk '{print $4}' | cut -d '/' -f 1 "))
|
||||||
return str(eth0_ip)
|
return eth0_ip
|
||||||
except (KeyError, IndexError, OSError) as e:
|
except (KeyError, IndexError, OSError) as e:
|
||||||
print(f"Error getting eth0 IP: {e}")
|
print(f"Error getting eth0 IP: {e}")
|
||||||
return None
|
exit
|
||||||
|
|
||||||
def on_connect(client, userdata, flags, reason_code, properties):
|
def on_connect(client, userdata, flags, reason_code, properties):
|
||||||
if reason_code == 0:
|
if reason_code == 0:
|
||||||
|
@ -114,23 +114,31 @@ def connect_mqtt():
|
||||||
|
|
||||||
|
|
||||||
def mqtt_publisher(universe, artnet_receiver):
|
def mqtt_publisher(universe, artnet_receiver):
|
||||||
universe = universe-1
|
artnetUniverse = universe-1
|
||||||
mqtt_client = connect_mqtt()
|
mqtt_client = connect_mqtt()
|
||||||
|
artnetBindIp = "192.168.0.1"
|
||||||
|
artNet = Artnet.Artnet(BINDIP = artnetBindIp, DEBUG = False, SHORTNAME = "PiXelTubeMaster", LONGNAME = "PiXelTubeMaster", PORT = 6454, REFRESH=30, MAC=mac_address_array)
|
||||||
|
tuple_ip = (str(get_eth0_ip()), 6454)
|
||||||
|
artNet.art_pol_reply(tuple_ip)
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
artnetPacket = artnet_receiver.readPacket()
|
|
||||||
try:
|
try:
|
||||||
if artnetPacket is not None and artnetPacket.data is not None:
|
# Gets whatever the last Art-Net packet we received is
|
||||||
if artnetPacket.universe == universe:
|
artNetPacket = artNet.readPacket()
|
||||||
dmxPacket = artnetPacket.data
|
# Make sure we actually *have* a packet
|
||||||
if dmxPacket is not None:
|
if artNetPacket is not None and artNetPacket.data is not None:
|
||||||
for i in len(512):
|
# Checks to see if the current packet is for the specified DMX Universe
|
||||||
# # Create MQTT topic based on the universe and channel
|
if artNetPacket.universe == artnetUniverse:
|
||||||
# topic = f"{universe}/{channel}"
|
# Then print out the data from each channel
|
||||||
|
print("Received data: ", end="")
|
||||||
|
channel = 1
|
||||||
|
for value in artNetPacket.data:
|
||||||
|
# Create MQTT topic based on the universe and channel
|
||||||
|
topic = f"{str(artNetPacket.universe)}/{str(channel)}"
|
||||||
|
|
||||||
# # Publish the DMX value to the MQTT topic
|
# Publish the DMX value to the MQTT topic
|
||||||
# mqtt_client.publish(topic, value)
|
mqtt_client.publish(topic, str(value))
|
||||||
print(dmxPacket[i-1], end=" ")
|
channel + 1
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -141,7 +149,7 @@ def start_mqtt_publishers(universe_count):
|
||||||
print("universe count: "+str(used_universes))
|
print("universe count: "+str(used_universes))
|
||||||
universes_to_publish = list(range(1, used_universes + 1))
|
universes_to_publish = list(range(1, used_universes + 1))
|
||||||
|
|
||||||
artnet_receiver = Artnet.Artnet(BINDIP = get_eth0_ip(), DEBUG = True, SHORTNAME = "PiXelTubeMaster", LONGNAME = "PiXelTubeMaster - "+str(get_mac_address), REFRESH = 60)
|
artnet_receiver = Artnet.Artnet(BINDIP = get_eth0_ip(), DEBUG = True, SHORTNAME = "PiXelTubeMaster", LONGNAME = "PiXelTubeMaster - "+str(get_mac_address))
|
||||||
print(str(get_eth0_ip()))
|
print(str(get_eth0_ip()))
|
||||||
print(2)
|
print(2)
|
||||||
# Create and start a thread for each universe
|
# Create and start a thread for each universe
|
||||||
|
|
Loading…
Reference in New Issue