Skip to content

Instantly share code, notes, and snippets.

@AndrewTheTM
Created November 4, 2020 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewTheTM/c8a48d683348f38355fed1e400e28b45 to your computer and use it in GitHub Desktop.
Save AndrewTheTM/c8a48d683348f38355fed1e400e28b45 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 2 13:05:58 2020
@author: andrew.rohne
"""
import socket
def setLights(setting):
IP_LIST = [['192.168.10.10', 'blue'], ['192.168.10.12', 'blue'], ['192.168.10.13', 'normal']]
#IP_LIST = ['192.168.10.13']
#IP_LIST = ['192.168.10.10', '192.168.10.12']
UDP_PORT = 38899
for ipg in IP_LIST:
ip = ipg[0]
s = ipg[1]
if setting == 'video':
set_to = s
else:
set_to = setting
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.settimeout(1.0)
sock.connect((ip, UDP_PORT))
if set_to == "normal":
sock.send(b'{"method":"setPilot","id":527,"env":"pro","params":{"mac":"0x:a8:bb:50:ae:0a:4f", "w": 85}}')
elif set_to == "dim":
sock.send(b'{"method":"setPilot","id":527,"env":"pro","params":{"mac":"0x:a8:bb:50:ae:0a:4f", "w": 45}}')
elif set_to == "blue":
sock.send(b'{"method":"setPilot","id":527,"env":"pro","params":{"mac":"0x:a8:bb:50:ae:0a:4f", "r": 0, "g": 51, "b": 153, "dimming": 100}}')
elif set_to == "red":
sock.send(b'{"method":"setPilot","id":527,"env":"pro","params":{"mac":"0x:a8:bb:50:ae:0a:4f", "r": 250, "g": 0, "b": 0, "dimming": 80}}')
elif set_to == "purple":
sock.send(b'{"method":"setPilot","id":527,"env":"pro","params":{"mac":"0x:a8:bb:50:ae:0a:4f", "r": 85, "g": 2, "b": 110, "dimming": 100}}')
elif set_to == "pink":
sock.send(b'{"method":"setPilot","id":527,"env":"pro","params":{"mac":"0x:a8:bb:50:ae:0a:4f", "r": 245, "g": 66, "b": 233, "dimming": 100}}')
elif set_to == "green":
sock.send(b'{"method":"setPilot","id":527,"env":"pro","params":{"mac":"0x:a8:bb:50:ae:0a:4f", "r": 0, "g": 250, "b": 0, "dimming": 100}}')
elif set_to == "cyan":
sock.send(b'{"method":"setPilot","id":527,"env":"pro","params":{"mac":"0x:a8:bb:50:ae:0a:4f", "r": 66, "g": 245, "b": 233, "dimming": 100}}')
else:
return(0)
attempts = 0
while attempts < 3:
try:
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
print(data)
except socket.timeout:
attempts += 1
continue
break
sock.close()
setLights("normal")
#setLights("video")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment