Skip to content

Commit

Permalink
Merge pull request #7 from rytai/feature/allow_broadcast
Browse files Browse the repository at this point in the history
Allow broadcast in subnet
  • Loading branch information
cpvalente authored May 20, 2021
2 parents 07e1094 + 8160308 commit a738c20
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 5 additions & 4 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
import random

# THESE ARE MOST LIKELY THE VALUES YOU WILL BE NEEDING
target_ip = '192.168.1.10' # typically in 2.x or 10.x range
universe = 0 # see docs
packet_size = 100 # it is not necessary to send whole universe
target_ip = '255.255.255.255' # typically in 2.x or 10.x range
universe = 0 # see docs
packet_size = 100 # it is not necessary to send whole universe

# CREATING A STUPID ARTNET OBJECT
# SETUP NEEDS A FEW ELEMENTS
# TARGET_IP = DEFAULT 127.0.0.1
# UNIVERSE = DEFAULT 0
# PACKET_SIZE = DEFAULT 512
# FRAME_RATE = DEFAULT 30
a = StupidArtnet(target_ip, universe, packet_size)
# ISBROADCAST = DEFAULT FALSE
a = StupidArtnet(target_ip, universe, packet_size, 30, True, True)

# MORE ADVANCED CAN BE SET WITH SETTERS IF NEEDED
# NET = DEFAULT 0
Expand Down
5 changes: 4 additions & 1 deletion lib/StupidArtnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class StupidArtnet():

UDP_PORT = 6454

def __init__(self, targetIP='127.0.0.1', universe=0, packet_size=512, fps=30, receiver_needs_even_packet_size=True):
def __init__(self, targetIP='127.0.0.1', universe=0, packet_size=512, fps=30, receiver_needs_even_packet_size=True, broadcast=False):
"""Class Initialization."""
# Instance variables
self.TARGET_IP = targetIP
Expand All @@ -38,6 +38,9 @@ def __init__(self, targetIP='127.0.0.1', universe=0, packet_size=512, fps=30, re
# UDP SOCKET
self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

if broadcast:
self.s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

# Timer
self.fps = fps

Expand Down

0 comments on commit a738c20

Please sign in to comment.