From bab27964f2d2fc1891da4989cca03b90cd6d4159 Mon Sep 17 00:00:00 2001 From: penfold42 Date: Sun, 5 Jun 2016 03:27:47 +1000 Subject: [PATCH] added multicast reception in the udp effect (#675) * Removed -HUP so the default -TERM signal is sent instead. - hyperiond only listens for TERM and INT. HUP is often used to get an exe to reread its config Changed pgrep to add '-x' so it wont partial match on the exe name. - I have multiple instances with multiple hyperiond-instance1 names - this ensures the service script only kills the right process * reversing errant change to hyperion.systemd.sh * cleaned up a couple of compiler warnings * moved bitpair_to_byte initialiser to (hopefully) work with older GCC * compiler warning in udp driver removed some tabs in ws2812b.cpp * formatting - spaces to tabs * moved rpi_281x to tag sk6812-v1.0 * moving to my fork of rpi_281x * removed dos line endings * Found some more "dos" line ending files * Added multicast support to the udp listener "effect" * the default udp.json will listen to unicast on port 2391 (as it used to) the new udp-mcast.json will listen on multicast 239.255.28.01:2801 Former-commit-id: 5c76fabd3da141094f5434ed869420ad6e581fd8 --- effects/udp-mcast.json | 9 +++++++++ effects/udp.json | 16 ++++++++-------- effects/udp.py | 24 ++++++++++++++++++++---- 3 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 effects/udp-mcast.json diff --git a/effects/udp-mcast.json b/effects/udp-mcast.json new file mode 100644 index 0000000..eb492ff --- /dev/null +++ b/effects/udp-mcast.json @@ -0,0 +1,9 @@ +{ + "name" : "UDP multicast listener", + "script" : "udp.py", + "args" : + { + "ListenPort" : 2801, + "ListenIP" : "239.255.28.01" + } +} diff --git a/effects/udp.json b/effects/udp.json index 29df097..0fc6e6e 100644 --- a/effects/udp.json +++ b/effects/udp.json @@ -1,8 +1,8 @@ -{ - "name" : "UDP listener", - "script" : "udp.py", - "args" : - { - "udpPort" : 2391 - } -} +{ + "name" : "UDP listener", + "script" : "udp.py", + "args" : + { + "ListenPort" : 2391 + } +} diff --git a/effects/udp.py b/effects/udp.py index f8317a2..6f39b1d 100644 --- a/effects/udp.py +++ b/effects/udp.py @@ -3,17 +3,33 @@ import time import colorsys import socket import errno +import struct # Get the parameters -udpPort = int(hyperion.args.get('udpPort', 2812)) +ListenPort = int(hyperion.args.get('ListenPort', 2801)) +ListenIP = hyperion.args.get('ListenIP', "") +octets = ListenIP.split('.'); -UDPSock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) +UDPSock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM, socket.IPPROTO_UDP) UDPSock.setblocking(False) -listen_addr = ("",udpPort) -print "udp.py: bind socket port:",udpPort +listen_addr = (ListenIP,ListenPort) UDPSock.bind(listen_addr) +if ListenIP == "": + print "udp.py: Listening on *.*.*.*:"+str(ListenPort) +else: + print "udp.py: Listening on "+ListenIP+":"+str(ListenPort) + +if len(octets) == 4 and int(octets[0]) >= 224 and int(octets[0]) < 240: + print "ListenIP is a multicast address\n" + # Multicast handling + try: + mreq = struct.pack("4sl", socket.inet_aton(ListenIP), socket.INADDR_ANY) + UDPSock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) + except socket.error: + print "ERROR enabling multicast\n" + hyperion.setColor(hyperion.ledCount * bytearray((int(0), int(0), int(0))) ) # Start the write data loop