siwat-light-control-protocol


Namesiwat-light-control-protocol JSON
Version 3.18 PyPI version JSON
download
home_pagehttps://github.com/SiwatINC/siwat-light-control-protocol
Summary
upload_time2022-12-18 15:05:35
maintainer
docs_urlNone
authorSiwat Sirichai
requires_python
licenseApache 2.0
keywords light mqtt serial raspberry-pi-pico
VCS
bugtrack_url
requirements pyserial setuptools
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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_protocol.png)

## **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.<br/>
**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.<br/>
**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.<br/>
**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]]
    ]

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/SiwatINC/siwat-light-control-protocol",
    "name": "siwat-light-control-protocol",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "light mqtt serial raspberry-pi-pico",
    "author": "Siwat Sirichai",
    "author_email": "siwat@siwatinc.com",
    "download_url": "https://files.pythonhosted.org/packages/1b/59/df014809d4e2145060d27dfe5deb6cd4e09035c4cfab51409dfe345441eb/siwat_light_control_protocol-3.18.tar.gz",
    "platform": null,
    "description": "# Siwat's Light Control Protocol (SLCP)\r\n Set of Python Libraries to interact with LED Controller that uses Siwat's Light Control Protocol and Siwat's Remote Light Control Protocol\r\n \r\n ![](slcp_protocol.png)\r\n\r\n## **SLCP Client Types**\r\n\r\n\r\n### Serial Line Topology Client\r\n\r\nThe 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.<br/>\r\n**Import and Initialization**\r\n\r\n    from siwat_light_control_protocol.siwat_light_control_protocol import siwat_light_control_protocol\r\n    SERIAL_PORT = \"COM3\" # Change if neccessary\r\n    LED_MAP = [60,30,60]\r\n    leds = slcp(SERIAL_PORT,LED_MAP)\r\n    \r\n### Serial Star Topology Client\r\nThe 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.<br/>\r\n**Import and Initialization**\r\n\r\n    from siwat_light_control_protocol.siwat_light_control_protocol_multi_serial import siwat_light_control_protocol_multi_serial as slcp\r\n    SERIAL_PORTS = [\"COM3\",\"COM4\",\"COM5\"] # Change if neccessary\r\n    LED_MAP = [60,30,60]\r\n    leds = slcp(SERIAL_PORTS,LED_MAP)\r\n\r\n### Remote Client\r\nThe Serial remote client works on top of the MQTT protocol, by using JSON packet to transfer data between SLCP Remote Client and SLCP Server.<br/>\r\n**Import and Initialization**\r\n\r\n    from siwat_remote_light_control_protocol_client.siwat_remote_light_control_protocol_client import siwat_remote_light_control_protocol_client as srlcp\r\n    MQTT_SERVER  =  \"172.16.0.2\"\r\n    MQTT_PORT  =  1883\r\n    MQTT_USE_AUTH  =  True\r\n    LIGHT_ADDRESS  =  \"/ledstrip\"\r\n    MQTT_USERNAME = \"username\"\r\n    MQTT_PASSWORD = \"password\"\r\n    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)\r\n**Note**\r\n\r\n 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()**\r\n 2. *mqtt_username* and *mqtt_password* field are not required if *mqtt_use_auth* is *False*\r\n\r\n## **SLCP Client Functions**\r\n\r\n 1. **show()** | Update the led with the programmed value\r\n 2. **set_led_at(index,r,g,b)** | Program an led at index ***index*** with color r,g,b\r\n 3. **turn_off()** | Turn off all of the leds\r\n 4. **rainbow()** | Activate the controller's built-in rainbow effect **(Not available on Remote Client as it desync the state)**\r\n 5. **fill_led_with_color(r,g,b)** | Set all of the led to color r,g,b\r\n 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\r\n 7. **enter_programming_mode()** | Engage the Programming Functionality of the Controller **(Only available on Remote Client)**\r\n\r\n**Note**\r\n - 0<=r,g,b<=255\r\n\r\n## **SLCP Server**\r\nSLCP Server expose the control interface of the controller to MQTT. The sever can be started by executing\r\n\r\n    python -m siwat_remote_light_control_protocol_server\r\nThis must be done in a directory with ***config.json*** in it.\r\n***config.json*** is a configuration file with the following structure\r\n\r\n    {\r\n\t    \"MQTT_SERVER\": \"\",\r\n\t    \"MQTT_USE_AUTH\": false,\r\n\t    \"MQTT_USERNAME\": \"\",\r\n\t    \"MQTT_PASSWORD\": \"\",\r\n\t    \"MQTT_BASE_TOPIC\": \"/ledstrip/fixture1\",\r\n\t    \"FRAME_TIME\": 0.1,\r\n\t    \"SERIAL_PORTS_MAP\": [\r\n\t\t    \"COM1\"\r\n        ],\r\n\t    \"LED_MAP\": [\r\n\t\t    60\r\n\t    ]\r\n    }\r\n**Note**\r\nMQTT_BASE_TOPIC is the same as LIGHT_ADDRESS\r\n\r\n### Basic MQTT Publish Topics\r\nTOPIC | PAYLOAD | Description\r\n - **MQTT_BASE_TOPIC/control/state** | *\"on\"*/*\"off\"* | set the state of the led\r\n - **MQTT_BASE_TOPIC/control/brightness** | 0-255 | set the brightness of the led\r\n - **MQTT_BASE_TOPIC/control/color** | r,g,b | set the color of the light to r,g,b where 0<=r,g,b<=255\r\n - **MQTT_BASE_TOPIC/control/effect** | *effect_name* | set the effect of the led\r\n- **MQTT_BASE_TOPIC/control/exit** | any | exit the program\r\n- **MQTT_BASE_TOPIC/control/requeststate** | resend all report\r\n\r\n### Basic MQTT Information Topics\r\n - **MQTT_BASE_TOPIC/report/state** | *\"on\"*/*\"off\"* | current state of the led\r\n - **MQTT_BASE_TOPIC/report/brightness** | 0-255 | current brightness of the led\r\n - **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\r\n - **MQTT_BASE_TOPIC/report/effect** | *effect_name* | current effect of the led\r\n - **MQTT_BASE_TOPIC/report/effectlist** | *effect1,effect2,effect3,...* | comma-seperated list of effects\r\n - **MQTT_BASE_TOPIC/report/num_leds** | *num_leds* | integer representing how much led chips the server are conencted to\r\n\r\n### MQTT Programming Interface Topics\r\n**MQTT_BASE_TOPIC/control/program** | payload\r\nWhere payload is a json array containing the following object\r\n\r\n    [index,[r,g,b]]\r\n\r\nFor Example, *[0,[255,255,255]]* will set the led at index 0 to r,g,b = 255,255,255\r\n\r\nThe payload that set the light at index 0,1,2 to red,green,blue respectively is then\r\n\r\n    [\r\n        [0,[255,0,0]]\r\n        [1,[0,255,0]]\r\n        [2,[0,0,255]]\r\n    ]\r\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "",
    "version": "3.18",
    "split_keywords": [
        "light",
        "mqtt",
        "serial",
        "raspberry-pi-pico"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "f16d3333e94774d4caf9d4850915ef37",
                "sha256": "92594d8770e743746ae1cd29a26631c83ce2dec8d6c998385b4699cffa6f0c60"
            },
            "downloads": -1,
            "filename": "siwat_light_control_protocol-3.18.tar.gz",
            "has_sig": false,
            "md5_digest": "f16d3333e94774d4caf9d4850915ef37",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 14491,
            "upload_time": "2022-12-18T15:05:35",
            "upload_time_iso_8601": "2022-12-18T15:05:35.853312Z",
            "url": "https://files.pythonhosted.org/packages/1b/59/df014809d4e2145060d27dfe5deb6cd4e09035c4cfab51409dfe345441eb/siwat_light_control_protocol-3.18.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-18 15:05:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "SiwatINC",
    "github_project": "siwat-light-control-protocol",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "pyserial",
            "specs": []
        },
        {
            "name": "setuptools",
            "specs": []
        }
    ],
    "lcname": "siwat-light-control-protocol"
}
        
Elapsed time: 0.02909s