Package: siwat-light-control-protocol
Siwat's Light Control Protocol (SLCP)Set of Python Libraries to interact with LED Controller that uses Siwat's Light Control Protocol and Siwat's Remote Light Control ProtocolSLCP Client TypesSerial Line Topology ClientThe Serial Line client works by utilizing multiple microcontroller unit connected using a line topology. This allows the entire network to be controlled using only one serial port on the host machine. The wiring for this method required 2 serial port on the controller one for in and one for out. for further information, please refer to the protocol specification.Import and Initializationfrom siwat_light_control_protocol.siwat_light_control_protocol import siwat_light_control_protocol
SERIAL_PORT = "COM3" # Change if neccessary
LED_MAP = [60,30,60]
leds = slcp(SERIAL_PORT,LED_MAP)Serial Star Topology ClientThe Serial Star client works by connecting multiple controller to the same host computer directly to utilize multiple controller to create one continuous strand of light.Import and Initializationfrom siwat_light_control_protocol.siwat_light_control_protocol_multi_serial import siwat_light_control_protocol_multi_serial as slcp
SERIAL_PORTS = ["COM3","COM4","COM5"] # Change if neccessary
LED_MAP = [60,30,60]
leds = slcp(SERIAL_PORTS,LED_MAP)Remote ClientThe Serial remote client works on top of the MQTT protocol, by using JSON packet to transfer data between SLCP Remote Client and SLCP Server.Import and Initializationfrom siwat_remote_light_control_protocol_client.siwat_remote_light_control_protocol_client import siwat_remote_light_control_protocol_client as srlcp
MQTT_SERVER  =  "172.16.0.2"
MQTT_PORT  =  1883
MQTT_USE_AUTH  =  True
LIGHT_ADDRESS  =  "/ledstrip"
MQTT_USERNAME = "username"
MQTT_PASSWORD = "password"
leds = srlcp(mqtt_server=MQTT_SERVER, mqtt_port=MQTT_PORT, light_address=LIGHT_ADDRESS,mqtt_use_auth=MQTT_USE_AUTH, mqtt_username=MQTT_USERNAME,mqtt_password=MQTT_PASSWORD)NoteLights have to but put in Programming Mode (ProgramEffect)to allow programming from a remote client, this can be done by callingenter_programming_mode()mqtt_usernameandmqtt_passwordfield are not required ifmqtt_use_authisFalseSLCP Client Functionsshow()| Update the led with the programmed valueset_led_at(index,r,g,b)| Program an led at indexindexwith color r,g,bturn_off()| Turn off all of the ledsrainbow()| Activate the controller's built-in rainbow effect(Not available on Remote Client as it desync the state)fill_led_with_color(r,g,b)| Set all of the led to color r,g,bfill_segment_with_color(segment_start,segment_stop,r,g,b)| Set all of the light, starting from segment_start to segment_stop to r,g,benter_programming_mode()| Engage the Programming Functionality of the Controller(Only available on Remote Client)Note0<=r,g,b<=255SLCP ServerSLCP Server expose the control interface of the controller to MQTT. The sever can be started by executingpython -m siwat_remote_light_control_protocol_serverThis must be done in a directory withconfig.jsonin it.config.jsonis a configuration file with the following structure{
    "MQTT_SERVER": "",
    "MQTT_USE_AUTH": false,
    "MQTT_USERNAME": "",
    "MQTT_PASSWORD": "",
    "MQTT_BASE_TOPIC": "/ledstrip/fixture1",
    "FRAME_TIME": 0.1,
    "SERIAL_PORTS_MAP": [
	    "COM1"
    ],
    "LED_MAP": [
	    60
    ]
}NoteMQTT_BASE_TOPIC is the same as LIGHT_ADDRESSBasic MQTT Publish TopicsTOPIC | PAYLOAD | DescriptionMQTT_BASE_TOPIC/control/state|"on"/"off"| set the state of the ledMQTT_BASE_TOPIC/control/brightness| 0-255 | set the brightness of the ledMQTT_BASE_TOPIC/control/color| r,g,b | set the color of the light to r,g,b where 0<=r,g,b<=255MQTT_BASE_TOPIC/control/effect|effect_name| set the effect of the ledMQTT_BASE_TOPIC/control/exit| any | exit the programMQTT_BASE_TOPIC/control/requeststate| resend all reportBasic MQTT Information TopicsMQTT_BASE_TOPIC/report/state|"on"/"off"| current state of the ledMQTT_BASE_TOPIC/report/brightness| 0-255 | current brightness of the ledMQTT_BASE_TOPIC/report/color| r,g,b | current color of the led in term of r,g,b where 0<=r,g,b<=255MQTT_BASE_TOPIC/report/effect|effect_name| current effect of the ledMQTT_BASE_TOPIC/report/effectlist|effect1,effect2,effect3,...| comma-seperated list of effectsMQTT_BASE_TOPIC/report/num_leds|num_leds| integer representing how much led chips the server are conencted toMQTT Programming Interface TopicsMQTT_BASE_TOPIC/control/program| payload
Where payload is a json array containing the following object[index,[r,g,b]]For Example,[0,[255,255,255]]will set the led at index 0 to r,g,b = 255,255,255The payload that set the light at index 0,1,2 to red,green,blue respectively is then[
    [0,[255,0,0]]
    [1,[0,255,0]]
    [2,[0,0,255]]
]