Skip to main content

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 Protocol

SLCP Client Types

Serial Line Topology Client

The 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 Initialization

from 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 Client

The 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 Initialization

from 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 Client

The 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 Initialization

from 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)

Note

  1. Lights have to but put in Programming Mode (Program Effect) to allow programming from a remote client, this can be done by calling enter_programming_mode()
  2. mqtt_username and mqtt_password field are not required if mqtt_use_auth is False

SLCP Client Functions

  1. show() | Update the led with the programmed value
  2. set_led_at(index,r,g,b) | Program an led at index index with color r,g,b
  3. turn_off() | Turn off all of the leds
  4. rainbow() | Activate the controller's built-in rainbow effect (Not available on Remote Client as it desync the state)
  5. fill_led_with_color(r,g,b) | Set all of the led to color r,g,b
  6. fill_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,b
  7. enter_programming_mode() | Engage the Programming Functionality of the Controller (Only available on Remote Client)

Note

  • 0<=r,g,b<=255

SLCP Server

SLCP Server expose the control interface of the controller to MQTT. The sever can be started by executing

python -m siwat_remote_light_control_protocol_server

This must be done in a directory with config.json in it. config.json is 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
    ]
}

Note MQTT_BASE_TOPIC is the same as LIGHT_ADDRESS

Basic MQTT Publish Topics

TOPIC | PAYLOAD | Description

  • MQTT_BASE_TOPIC/control/state | "on"/"off" | set the state of the led
  • MQTT_BASE_TOPIC/control/brightness | 0-255 | set the brightness of the led
  • MQTT_BASE_TOPIC/control/color | r,g,b | set the color of the light to r,g,b where 0<=r,g,b<=255
  • MQTT_BASE_TOPIC/control/effect | effect_name | set the effect of the led
  • MQTT_BASE_TOPIC/control/exit | any | exit the program
  • MQTT_BASE_TOPIC/control/requeststate | resend all report

Basic MQTT Information Topics

  • MQTT_BASE_TOPIC/report/state | "on"/"off" | current state of the led
  • MQTT_BASE_TOPIC/report/brightness | 0-255 | current brightness of the led
  • MQTT_BASE_TOPIC/report/color | r,g,b | current color of the led in term of r,g,b where 0<=r,g,b<=255
  • MQTT_BASE_TOPIC/report/effect | effect_name | current effect of the led
  • MQTT_BASE_TOPIC/report/effectlist | effect1,effect2,effect3,... | comma-seperated list of effects
  • MQTT_BASE_TOPIC/report/num_leds | num_leds | integer representing how much led chips the server are conencted to

MQTT Programming Interface Topics

MQTT_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,255

The 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]]
]

Metadata

Release files for siwat-light-control-protocol 3.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for siwat-light-control-protocol 3.18
File Size Uploaded
siwat_light_control_protocol-3.18.tar.gz 14.5 kB Details

Release files / siwat_light_control_protocol-3.18.tar.gz

Download URL siwat_light_control_protocol-3.18.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
92594d8770e743746ae1cd29a26631c83ce2dec8d6c998385b4699cffa6f0c60
BLAKE2b-256 checksum
How to use checksums
1b59df014809d4e2145060d27dfe5deb6cd4e09035c4cfab51409dfe345441eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6

Release history Release notifications | RSS feed

This release

3.18 This release

1 release file

3.17

1 release file

3.16

1 release file

3.15

1 release file

3.14

1 release file

3.13

1 release file

3.12

1 release file

3.11

1 release file

3.10

1 release file

3.9

1 release file

3.8

1 release file

3.7

1 release file

3.6

1 release file

3.5

1 release file

3.4

1 release file

3.3

1 release file

3.2

1 release file

3.1

1 release file

3.0

1 release file

2.20

1 release file

2.19

1 release file

2.18

1 release file

2.17

1 release file

2.16

1 release file

2.15

1 release file

2.14

1 release file

2.13

1 release file

2.12

1 release file

2.11

1 release file

2.10

1 release file

2.9

1 release file

2.8

1 release file

2.7

1 release file

2.6

1 release file

2.5

1 release file

2.4

1 release file

2.3

1 release file

2.2

1 release file

2.1

1 release file

2.0

1 release file

1.7

1 release file

1.6

1 release file

1.5

1 release file

1.4

1 release file

1.3

1 release file

1.2

1 release file

1.1

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page