Skip to content

Commit

Permalink
multiple device detection already works
Browse files Browse the repository at this point in the history
  • Loading branch information
markusressel committed Feb 11, 2018
1 parent 7a76daf commit 6ea5eda
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions sunix_ledstrip_controller_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,33 @@ def discover_controllers(self) -> [Controller]:
cs.settimeout(1)
received_messages = []
try:
# TODO: allow multiple controller detection
while True:
data, address = cs.recvfrom(4096)
# print("Received message: \"%s\"" % data)
# print("Address: " + address[0])

received_messages.append(data.decode())

except socket.timeout:
if len(received_messages) <= 0:
return discovered_controllers

for message in received_messages:
# parse received message
data = str.split(message, ",")

# check validity
if len(data) == 3:
# extract data
ip = data[0]
hw_id = data[1]
model = data[2]

# create a Controller object representation
controller = Controller(self, ip, Controller.DEFAULT_PORT, hw_id, model)
print(controller)

discovered_controllers.append(controller)
try:
# parse received message
data = str.split(message, ",")

# check validity
if len(data) == 3:
# extract data
ip = data[0]
hw_id = data[1]
model = data[2]

# create a Controller object representation
controller = Controller(self, ip, Controller.DEFAULT_PORT, hw_id, model)
print(controller)

discovered_controllers.append(controller)
except:
print("Error parsing discovery message: %s" % message)

return discovered_controllers

Expand Down

0 comments on commit 6ea5eda

Please sign in to comment.