Created
June 22, 2015 14:34
-
-
Save borsna/deda0423efc728dc448e to your computer and use it in GitHub Desktop.
communicating with mi lights (network controllable led lights)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import sys | |
import time | |
import random | |
#docs: | |
# http://www.limitlessled.com/dev/ | |
host = '10.10.10.255' #broadcast ip for my subnet | |
port = 8899 | |
#group hex dec | |
#all 0x42 66 | |
#grp1 0x45 69 | |
#grp2 0x47 71 | |
#grp3 0x49 73 | |
#grp4 0x4B 75 | |
GROUP = 66 | |
try: | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
s.connect((host, port)) | |
except socket.error: | |
print ('Failed to create socket') | |
sys.exit() | |
def main() : | |
brightness(GROUP, 27) #full brightness | |
#random color | |
for x in range(0, 10) : | |
rand = random.randint(0, 255) | |
color(GROUP, rand) | |
print("Nr. %d, Color %d" % (x, rand)) | |
time.sleep(0.1) | |
def mi_send(group, mode, value) : | |
try : | |
s.send(bytearray([group])) | |
time.sleep(0.1) | |
s.send(bytearray([mode, value, 85])) | |
except socket.error as e: | |
print ('Error Code : ' + str(e[0]) + ' Message ' + e[1]) | |
sys.exit() | |
def brightness(group, brightness) : | |
"""set brightness 2-27""" | |
mi_send(group, 78, brightness) | |
def color(group, color) : | |
"""set color 0-255""" | |
mi_send(group, 64, color) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment