Advertisement
Guest User

exampleReceiver.py

a guest
Feb 14th, 2024
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. import time
  2. import sys
  3. import python_artnet as Artnet
  4. import os
  5.  
  6. def get_eth0_ip():
  7.     try:
  8.         # Get the IP address of the eth0 interface
  9.         eth0_ip = str(os.system("ip -4 -o addr show eth0 | awk '{print $4}' | cut -d '/' -f 1 "))
  10.         return eth0_ip
  11.     except (KeyError, IndexError, OSError) as e:
  12.         print(f"Error getting eth0 IP: {e}")
  13.         exit
  14.  
  15. ### ArtNet Config ###
  16. artnetBindIp = get_eth0_ip()
  17.  
  18. ### Art-Net Setup ###
  19. # Sets debug in Art-Net module.
  20. # Creates Artnet socket on the selected IP and Port
  21. artNet = Artnet.Artnet(BINDIP = artnetBindIp, DEBUG = False, SHORTNAME = "PiXelTubeMaster", LONGNAME = "PiXelTubeMaster", PORT = 6454)
  22. tuple_ip = (str(get_eth0_ip()), 6454)
  23. artNet.art_pol_reply(tuple_ip)
  24. while True:
  25.     try:
  26.         # Gets whatever the last Art-Net packet we received is
  27.         artNetPacket = artNet.readPacket()
  28.         # Make sure we actually *have* a packet
  29.         if artNetPacket is not None and artNetPacket.data is not None:
  30.             print("Universe: "+str(artNetPacket.universe))
  31.             # Stores the packet data array
  32.             dmxPacket = artNetPacket.data
  33.        
  34.     except KeyboardInterrupt:
  35.         break
  36.  
  37. # Close the various connections cleanly so nothing explodes :)
  38. artNet.close()
  39. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement