LightwallController/Minimal: Unterschied zwischen den Versionen

Aus C3MAWiki
(Beschreibung der Minimal-Version des LightwallControllers)
 
 
(4 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 23: Zeile 23:
* Lightwallcontroller Firmware  
* Lightwallcontroller Firmware  
** [https://github.com/tobima/LightwallController/releases/tag/v1.0min Minimale Version der Firmware]
** [https://github.com/tobima/LightwallController/releases/tag/v1.0min Minimale Version der Firmware]
== Firmware ==
[[Datei:LightwallcontrollerMinimal.zip]]
== Hardware-Dokumentation ==
<gallery>
Datei:DMX_Shield1.jpg|Orginal geäztes DMX-Shield
Datei:DMX_Shield2.jpg|Fliegender Nachbau
Datei:DMX-Shield_12V_Power.jpg|Splipeater mit 12V-Anschluss
Datei:12V_DMXpowered.jpg|Gehäuseseite mit RJ45-DMX und 12V-Eingang
Datei:USB-UART_USB-Power.jpg|Gehäuseseite USB-UART und USB für Spannungsversorgung
</gallery>
== Mqtt ==
=== Anwendung ===
Status auslesen
mosquitto_sub -v -h 10.23.43.191 -t "/room/lighttiles/#"
Eine Lampe ändern
mosquitto_pub -h 10.23.43.191 -t "/room/lighttiles/5/command" -m "00FF00"
mosquitto_pub -h 10.23.43.191 -t "/room/lighttiles/6/command" -m "off"
=== Controller Umsetzung ===
<code>
import mosquitto, os, socket, time, re
from threading import Thread
#File: /usr/local/sbin/lighttile2mqtt.py
TCP_IP = '127.0.0.1'
TCP_PORT = 2002
BUFFER_SIZE = 1024
reLightColor = re.compile("[0-9A-F]{6}")
# Prometheus
#mqttBroker="10.23.42.31"
# BigBrother
mqttBroker="10.23.43.191"
mypid = os.getpid()
client = mosquitto.Mosquitto("RoomLights"+str(mypid))
pollerState = True
oldStates = None
t = None
def processState(ls):
lightnr=1
global oldStates
for light in ls:
if oldStates is None or light != oldStates[lightnr - 1]:
if light == "000000":
    light = "off"
client.publish("/room/lighttiles/%s/state" % lightnr, light, 0, True)
lightnr+=1
oldStates = ls
# Light ist das licht 1-6
# State ist h oder l
def switchLight(light, state):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
if state == "off":
    state = "000000"
s.send("rgb write %s %s %s %s\r\n" % (light-1, int(state[:2],16), int(state[2:4],16), int(state[4:],16)))
time.sleep(0.1)
data = s.recv(BUFFER_SIZE)
s.close()
processState(getStates())
def getStates():
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((TCP_IP, TCP_PORT))
        s.send("\r\n")
        time.sleep(0.1)
        data = s.recv(BUFFER_SIZE)
       
        s.send("dmx show\r\n")
        time.sleep(0.1)
        data = s.recv(BUFFER_SIZE).replace("\r", "").split("\n")[2]
   
if len(data) < 36:
    s.send("rgb write 5 0 0 0\r\n")
            time.sleep(0.1)
    data = s.recv(BUFFER_SIZE)
    s.send("dmx show\r\n")
    time.sleep(0.1)
    data = s.recv(BUFFER_SIZE).replace("\r", "").split("\n")[2]
   
s.close()   
   
        return (data[:6], data[6:12], data[12:18], data[18:24], data[24:30], data[30:])
               
def on_connect(rc):
    print("Connected with result code "+str(rc))
    client.subscribe("/room/lighttiles/+/command")
    processState(getStates())
def on_message(userdata, msg):
topic = msg.topic.strip("/").split("/")
lightNr = int(topic[2])
message = str(msg.payload)
if lightNr >= 1 and lightNr <= 6 and (message == "off" or reLightColor.match(message)):
switchLight(lightNr, message)
def on_disconnect(userdata):
#print "Disconnect"
pass
client.on_connect = on_connect
client.on_message = on_message
#client.on_disconnect = on_disconnect
client.will_set('/room/lighttiles/daemon/state', 'offline', 0, True)
   
while True:
print "Connect..."
client.connect(mqttBroker, 1883, 60, True)
    client.publish('/room/lighttiles/daemon/state', 'online', 0, True)
while client.loop() == 0:
pass
print "Reconnecting..."
time.sleep(60)
</code>

Aktuelle Version vom 23. Januar 2015, 21:38 Uhr


Diese Variante des LightwallController nutzt/ stellt folgende Schnittstellen bereit:

  • USB-UART
  • DMX

Es muss außerdem der Microkontroller mit 5V über USB versorgt werden. Der Fullcircle-DMX RJ45 Stecker benötigt dessweiteren 12V.

Schnittstellen

  • 2xUSB
    • USB-UART (Steuerung des Mikrocontrollers)
    • Spannungsversorgung des Mikrocontrollers
  • 12V
  • RJ45 DMX-Fullcircle Ausgang

Komponenten

Dieses Projekt greift auf folgende Komponenten zurück:

Firmware

Datei:LightwallcontrollerMinimal.zip

Hardware-Dokumentation

Mqtt

Anwendung

Status auslesen

mosquitto_sub -v -h 10.23.43.191 -t "/room/lighttiles/#"

Eine Lampe ändern

mosquitto_pub -h 10.23.43.191 -t "/room/lighttiles/5/command" -m "00FF00"
mosquitto_pub -h 10.23.43.191 -t "/room/lighttiles/6/command" -m "off"

Controller Umsetzung

import mosquitto, os, socket, time, re from threading import Thread


  1. File: /usr/local/sbin/lighttile2mqtt.py

TCP_IP = '127.0.0.1' TCP_PORT = 2002 BUFFER_SIZE = 1024

reLightColor = re.compile("[0-9A-F]{6}")


  1. Prometheus
  2. mqttBroker="10.23.42.31"
  3. BigBrother

mqttBroker="10.23.43.191"

mypid = os.getpid()


client = mosquitto.Mosquitto("RoomLights"+str(mypid))

pollerState = True oldStates = None t = None

def processState(ls): lightnr=1 global oldStates

for light in ls: if oldStates is None or light != oldStates[lightnr - 1]: if light == "000000": light = "off" client.publish("/room/lighttiles/%s/state" % lightnr, light, 0, True) lightnr+=1 oldStates = ls

  1. Light ist das licht 1-6
  2. State ist h oder l

def switchLight(light, state): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((TCP_IP, TCP_PORT))

if state == "off": state = "000000"

s.send("rgb write %s %s %s %s\r\n" % (light-1, int(state[:2],16), int(state[2:4],16), int(state[4:],16)))

time.sleep(0.1)

data = s.recv(BUFFER_SIZE) s.close()

processState(getStates())

def getStates():

       s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
       s.connect((TCP_IP, TCP_PORT))
       s.send("\r\n")
       time.sleep(0.1)
       data = s.recv(BUFFER_SIZE)
       
       s.send("dmx show\r\n")
       time.sleep(0.1)
       data = s.recv(BUFFER_SIZE).replace("\r", "").split("\n")[2]
   

if len(data) < 36: s.send("rgb write 5 0 0 0\r\n")

           time.sleep(0.1)

data = s.recv(BUFFER_SIZE) s.send("dmx show\r\n") time.sleep(0.1) data = s.recv(BUFFER_SIZE).replace("\r", "").split("\n")[2]

s.close()

       return (data[:6], data[6:12], data[12:18], data[18:24], data[24:30], data[30:])
               

def on_connect(rc):

   print("Connected with result code "+str(rc))
   client.subscribe("/room/lighttiles/+/command")
   processState(getStates())

def on_message(userdata, msg):

topic = msg.topic.strip("/").split("/")

lightNr = int(topic[2]) message = str(msg.payload)

if lightNr >= 1 and lightNr <= 6 and (message == "off" or reLightColor.match(message)): switchLight(lightNr, message)

def on_disconnect(userdata): #print "Disconnect" pass

client.on_connect = on_connect client.on_message = on_message

  1. client.on_disconnect = on_disconnect

client.will_set('/room/lighttiles/daemon/state', 'offline', 0, True)

while True: print "Connect..." client.connect(mqttBroker, 1883, 60, True)

   	client.publish('/room/lighttiles/daemon/state', 'online', 0, True)

while client.loop() == 0: pass print "Reconnecting..." time.sleep(60)