Heute, 19:34 - preAlpha dreamWifiLight (Mi-Light like Philips Hue über Boblight steuern) (Newan)
import sys
import socket
import colorsys
import time
UDP_IP = "192.168.178.116" #this is the IP of the wifi bridge, or 255.255.255.255 for UDP broadcast
UDP_PORT = 8899
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.sendto("\x40\x00\x55", (UDP_IP, UDP_PORT))
def popen():
spidev = file('/usr/dreamWifiLight/aufruf.log', "wb")
while True:
#try:
eingabe = sys.stdin.readline()
if len(eingabe)>0:
# get rgb from Boblight
r,g,b,x = eingabe.split(' ')
r = float(r)
g = float(g)
b = float(b)
# calc the color for the LED
h, l, s = colorsys.rgb_to_hls(r,g,b)
#calculate brightness
l = max(2,int((l * 27)))
spidev.write("Boblight: " + eingabe)
spidev.write("RGB: " + str(r*255) + ":" + str(g*255) + ":" + str(b*255))
spidev.write("lightness: " + str(l))
spidev.write("hue: " + str(h))
#spidev.write("LimitlessLED: " + str(hex(h)) + "\n")
spidev.flush()
if(h==0 and s==0): # h==0 and s==0 greyscale black, gray or white -> not red red == h=0 and light 50%
#so we send white with brightness
MESSAGE1 = "\xC2\x00\x55"
MESSAGE2 = "\x4E" + chr(l) + "\x55"
else:
# normal color, calc it
h = abs(int(round((h) * 255))-170) # 170 is the offset for IWY
# todo send all h_old to h_new to make it smooth ??
MESSAGE1 = "\x40" + chr(h) + "\x55"
MESSAGE2 = "\x4E" + chr(l) + "\x55"
sock.sendto(MESSAGE1, (UDP_IP, UDP_PORT))
sock.sendto(MESSAGE2, (UDP_IP, UDP_PORT))
else:
break
#except:
# break
# start boblight read, but we wait 2 seconds to start
import time
time.sleep(3)
popen()
Changelog:
- Herrausgefunden wie ich die Lampe auf Weiß umstelle
- Weiß wird gesenden
- Brightness eingebaut, aber noch alles was zu dunkel
- Moonlamp farben stimmen zu 80%, fehlt noch Rot zu korrigieren
Kleines Update, ich weiß das das bei weiten noch nicht die Lösung ist aber ich wollte euch teilhaben lassen an dem was ich so werkle....
Edit: Anbei noch eine boblight.conf, die mit sedubaord und diesem script zusamen funktioniert [zum Beitrag]
import sys
import socket
import colorsys
import time
UDP_IP = "192.168.178.116" #this is the IP of the wifi bridge, or 255.255.255.255 for UDP broadcast
UDP_PORT = 8899
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.sendto("\x40\x00\x55", (UDP_IP, UDP_PORT))
def popen():
spidev = file('/usr/dreamWifiLight/aufruf.log', "wb")
while True:
#try:
eingabe = sys.stdin.readline()
if len(eingabe)>0:
# get rgb from Boblight
r,g,b,x = eingabe.split(' ')
r = float(r)
g = float(g)
b = float(b)
# calc the color for the LED
h, l, s = colorsys.rgb_to_hls(r,g,b)
#calculate brightness
l = max(2,int((l * 27)))
spidev.write("Boblight: " + eingabe)
spidev.write("RGB: " + str(r*255) + ":" + str(g*255) + ":" + str(b*255))
spidev.write("lightness: " + str(l))
spidev.write("hue: " + str(h))
#spidev.write("LimitlessLED: " + str(hex(h)) + "\n")
spidev.flush()
if(h==0 and s==0): # h==0 and s==0 greyscale black, gray or white -> not red red == h=0 and light 50%
#so we send white with brightness
MESSAGE1 = "\xC2\x00\x55"
MESSAGE2 = "\x4E" + chr(l) + "\x55"
else:
# normal color, calc it
h = abs(int(round((h) * 255))-170) # 170 is the offset for IWY
# todo send all h_old to h_new to make it smooth ??
MESSAGE1 = "\x40" + chr(h) + "\x55"
MESSAGE2 = "\x4E" + chr(l) + "\x55"
sock.sendto(MESSAGE1, (UDP_IP, UDP_PORT))
sock.sendto(MESSAGE2, (UDP_IP, UDP_PORT))
else:
break
#except:
# break
# start boblight read, but we wait 2 seconds to start
import time
time.sleep(3)
popen()
Changelog:
- Herrausgefunden wie ich die Lampe auf Weiß umstelle
- Weiß wird gesenden
- Brightness eingebaut, aber noch alles was zu dunkel
- Moonlamp farben stimmen zu 80%, fehlt noch Rot zu korrigieren
Kleines Update, ich weiß das das bei weiten noch nicht die Lösung ist aber ich wollte euch teilhaben lassen an dem was ich so werkle....
Edit: Anbei noch eine boblight.conf, die mit sedubaord und diesem script zusamen funktioniert [zum Beitrag]