2024-02-13 13:08:23 +00:00
|
|
|
import time
|
|
|
|
import sys
|
|
|
|
import python_artnet as Artnet
|
|
|
|
import netifaces
|
|
|
|
|
|
|
|
def get_eth0_ip():
|
|
|
|
try:
|
|
|
|
# Get the IP address of the eth0 interface
|
|
|
|
eth0_ip = netifaces.ifaddresses('eth0')[netifaces.AF_INET][0]['addr']
|
2024-02-13 15:51:50 +00:00
|
|
|
return eth0_ip
|
2024-02-13 13:08:23 +00:00
|
|
|
except (KeyError, IndexError, OSError) as e:
|
|
|
|
print(f"Error getting eth0 IP: {e}")
|
|
|
|
return None
|
|
|
|
|
|
|
|
debug = True
|
|
|
|
|
|
|
|
# What DMX channels we want to listen to
|
|
|
|
dmxChannels = [1,2,3,4,5,6]
|
|
|
|
|
|
|
|
### ArtNet Config ###
|
2024-02-13 15:51:50 +00:00
|
|
|
print(str(get_eth0_ip()))
|
2024-02-13 15:39:21 +00:00
|
|
|
artnetBindIp = get_eth0_ip()
|
|
|
|
artnetUniverse = 0
|
2024-02-13 13:08:23 +00:00
|
|
|
|
|
|
|
### Art-Net Setup ###
|
|
|
|
# Sets debug in Art-Net module.
|
|
|
|
# Creates Artnet socket on the selected IP and Port
|
2024-02-13 15:56:23 +00:00
|
|
|
artNet = Artnet.Artnet(BINDIP = get_eth0_ip(), DEBUG = True, SHORTNAME = "PiXelTubeMaster", LONGNAME = "PiXelTubeMaster", REFRESH = 60)
|
2024-02-13 13:08:23 +00:00
|
|
|
|
2024-02-13 17:21:29 +00:00
|
|
|
# tuple_ip = tuple(int(el) for el in str(get_eth0_ip()).split("."))
|
|
|
|
|
2024-02-13 17:23:37 +00:00
|
|
|
tuple_ip = ("10.0.0.101", 6454)
|
2024-02-13 16:06:14 +00:00
|
|
|
|
2024-02-13 16:10:24 +00:00
|
|
|
print(tuple_ip)
|
|
|
|
|
2024-02-13 17:10:42 +00:00
|
|
|
artNet.art_pol_reply(tuple_ip)
|
2024-02-13 13:08:23 +00:00
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
# Gets whatever the last Art-Net packet we received is
|
2024-02-13 15:30:09 +00:00
|
|
|
artNetPacket = artNet.readPacket()
|
2024-02-13 13:08:23 +00:00
|
|
|
# Make sure we actually *have* a packet
|
|
|
|
if artNetPacket is not None and artNetPacket.data is not None:
|
|
|
|
# Checks to see if the current packet is for the specified DMX Universe
|
|
|
|
if artNetPacket.universe == artnetUniverse:
|
|
|
|
# Stores the packet data array
|
|
|
|
dmxPacket = artNetPacket.data
|
|
|
|
|
|
|
|
# Then print out the data from each channel
|
|
|
|
print("Received data: ", end="")
|
|
|
|
for i in dmxChannels:
|
|
|
|
# Lists in python start at 0, so to access a specific DMX channel you have to subtract one
|
|
|
|
print(dmxPacket[i-1], end=" ")
|
|
|
|
|
|
|
|
# Print a newline so things look nice :)
|
|
|
|
print("")
|
|
|
|
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
break
|
|
|
|
|
|
|
|
# Close the various connections cleanly so nothing explodes :)
|
|
|
|
artNet.close()
|
|
|
|
sys.exit()
|