2024-02-13 13:08:23 +00:00
|
|
|
import time
|
|
|
|
import sys
|
|
|
|
import python_artnet as Artnet
|
2024-02-13 17:43:38 +00:00
|
|
|
import os
|
2024-02-13 13:08:23 +00:00
|
|
|
|
2024-02-13 17:54:06 +00:00
|
|
|
def get_eth0_ip():
|
2024-02-13 17:56:50 +00:00
|
|
|
try:
|
|
|
|
# Get the IP address of the eth0 interface
|
2024-02-13 19:46:25 +00:00
|
|
|
eth0_ip = str(os.system("ip -4 -o addr show wlan0 | awk '{print $4}' | cut -d '/' -f 1 "))
|
2024-02-13 17:56:50 +00:00
|
|
|
return eth0_ip
|
|
|
|
except (KeyError, IndexError, OSError) as e:
|
|
|
|
print(f"Error getting eth0 IP: {e}")
|
|
|
|
exit
|
|
|
|
|
|
|
|
# def get_eth0_ip():
|
|
|
|
# return "10.0.0.150"
|
2024-02-13 13:08:23 +00:00
|
|
|
|
|
|
|
debug = True
|
|
|
|
|
|
|
|
# What DMX channels we want to listen to
|
2024-02-13 19:37:29 +00:00
|
|
|
dmxChannels = 512
|
2024-02-13 13:08:23 +00:00
|
|
|
|
|
|
|
### ArtNet Config ###
|
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 17:43:38 +00:00
|
|
|
artNet = Artnet.Artnet(BINDIP = artnetBindIp, SYSIP=artnetBindIp, DEBUG = True, SHORTNAME = "PiXelTubeMaster", LONGNAME = "PiXelTubeMaster", PORT = 6454)
|
2024-02-13 13:08:23 +00:00
|
|
|
|
2024-02-13 17:28:22 +00:00
|
|
|
tuple_ip = (str(get_eth0_ip()), 6454)
|
2024-02-13 13:08:23 +00:00
|
|
|
while True:
|
|
|
|
try:
|
2024-02-13 19:39:38 +00:00
|
|
|
artNet.art_pol_reply(tuple_ip)
|
2024-02-13 13:08:23 +00:00
|
|
|
# Gets whatever the last Art-Net packet we received is
|
2024-02-13 15:30:09 +00:00
|
|
|
artNetPacket = artNet.readPacket()
|
2024-02-13 17:33:36 +00:00
|
|
|
print("Packet: "+str(artNetPacket))
|
|
|
|
print("Universe: "+str(artNetPacket.universe))
|
|
|
|
print("Data: "+str(artNetPacket.data))
|
2024-02-13 17:33:05 +00:00
|
|
|
print(" ")
|
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="")
|
2024-02-13 19:37:29 +00:00
|
|
|
for i in len(dmxChannels):
|
2024-02-13 13:08:23 +00:00
|
|
|
# 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()
|