-
Notifications
You must be signed in to change notification settings - Fork 11
(3) The HTTP Server Daemon
Prerequisites needed for the HTTP Server Daemon: Bleak
The NeewerLite-Python HTTP daemon allows a computer running NeewerLite-Python to control Neewer lights using any web browser (or device that can send HTTP commands, like a Stream Deck, etc.) on the local network. By sending URLs to the HTTP daemon, you can control single or multiple lights, change modes, detect new lights and list the currently available lights available to NeewerLite-Python. Unlike the command-line interface, the HTTP daemon is persistent, meaning it maintains a list of available lights and continues to keep them linked until you quit out of the program (similar to how the GUI works), so it allows for much quicker access to the lights than the CLI, but like the CLI, does not need the PySide2 library, as it doesn't need to show a GUI, so it's a good option for smaller headless systems like a Raspberry Pi running a non-GUI setup.
To use the NeewerLite-Python HTTP daemon, use the --http
parameter when you launch the program. For example:
python3 ./NeewerLite-Python.py --http
Once the HTTP server is running, it will accept commands from local machines in your network, such as those that start with the IP addresses 192.168.*.*, 10.0.0.*, 172.20.*.* and the local loopback IP 127.0.0.1 (so you can test the server on the machine running the server.) By default, NeewerLite-Python is hard-coded to only accept commands coming from those local addresses for security purposes (so people outside of your network can't control your lights), but you can modify the source code to allow outside connections if necessary.
Sending commands to the HTTP daemon using a web browser is simple, it needs the IP address of the machine you're currently running the daemon on, the path /NeewerLite-Python/doAction?
, and a command very similar to the CLI interface. For example:
http://127.0.0.1:8080/NeewerLite-Python/doAction?list
Will show the currently available lights NeewerLite-Python can control. If no lights are available to control yet, the web browser will report that, and provide a link to search for lights near by. URL commands issued to the HTTP daemon all take the same structure, and multiple commands issued together (such as setting HSI mode, with a specific hue, brightness, etc.) are joined together in the URL using an ampersand (&) character. For example:
http://127.0.0.1:8080/NeewerLite-Python/doAction?light=11:22:33:44:55:66&mode=HSI&hue=240&bri=50
Will send 11:22:33:44:55:66 (only if it's already been discovered by NeewerLite-Python) a command to go into HSI mode, with a hue of 240º and brightness set to 50%.
Also, keep in mind, if you try to send any other command to the HTTP daemon, like asking for an index.html file or something similar in the root directory (as you would in an Apache installation, for example), NeewerLite-Python will automatically re-direct you to the /NeewerLite-Python/doAction? path and show an error message.
HTTP commands you can send the daemon:
discover
- tell NeewerLite-Python to scan/re-scan for lights
http://127.0.0.1:8080/NeewerLite-Python/doAction?discover
list
- list the lights currently available to NeewerLite-Python to control, by ID number, custom name (if a preferences file exists), light type, MAC address and the last value sent to the light
http://127.0.0.1:8080/NeewerLite-Python/doAction?list
on
/ off
- turn the light on or off - please note, if you accidentally put both parameters in the URL, ON will be triggered
http://127.0.0.1:8080/NeewerLite-Python/doAction?light=11:22:33:44:55:66&on
http://127.0.0.1:8080/NeewerLite-Python/doAction?light=11:22:33:44:55:66&off
link=
- try to link to a specific light, either specified by the ID number of the light (like 1, 2, etc.), or by MAC address - you can specify multiple lights to link by using a semicolon (;) in between each light
http://127.0.0.1:8080/NeewerLite-Python/doAction?link=2
http://127.0.0.1:8080/NeewerLite-Python/doAction?link=11:22:33:44:55:66
http://127.0.0.1:8080/NeewerLite-Python/doAction?link=1;2
light=
- the light you want to control, either specified by the ID number of the light, or the MAC address, similar to the above - also similar to the above, you can specify multiple lights to control by using a semicolon (;) in between each light
http://127.0.0.1:8080/NeewerLite-Python/doAction?light=2
http://127.0.0.1:8080/NeewerLite-Python/doAction?light=11:22:33:44:55:66
http://127.0.0.1/NeewerLite-Python/doAction?light=1;2
The rest of the options basically follow the same characteristics as the CLI interface, but without the "--" prefix between each command.
CCT mode-specific parameters:
temp=
or temperature=
- the color temperature to set the current light to (from 3200K-8500K, if your light supports the higher temperatures)
bri=
or brightness=
or intensity=
- how bright to set the light (from 0-100%)
HSI mode-specific parameters:
hue=
- the color hue to set the light to (from 0-360º)
sat=
or saturation=
- the saturation (color intensity) to set the light to (from 0-100%)
bri=
or brightness=
or intensity=
- how bright to set the light (from 0-100%)
ANM/SCENE mode-specific parameters:
scene=
or animation=
- Which animation to use (from 1-9)
bri=
or brightness=
or intensity=
- how bright to set the light (from 0-100%)
Examples: - Note: these 3 examples are the same as the examples on the CLI page:
http://127.0.0.1:8080/NeewerLite-Python/doAction?light=11:22:33:44:55:66&mode=CCT&temp=5200&bri=50
- set light 11:22:33:44:55:66 to CCT mode, with a color temperature of 5200K, and set the brightness to 50%
http://127.0.0.1:8080/NeewerLite-Python/doAction?light=11:22:33:44:55:66&mode=HSI&hue=240&sat=100&brightness=100
- set light 11:22:33:44:55:66 to HSI mode, with the hue set to 240º (blue), with saturation and brightness set to 100%
http://127.0.0.1:8080/NeewerLite-Python/doAction?light=11:22:33:44:55:66&mode=HSI
- set light 11:22:33:44:55:66 to HSI mode, with the default HSI parameters (* listed below)
Multiple light control examples:
http://127.0.0.1:8080/NeewerLite-Python/doAction?light=1;3;4&mode=HSI&hue=240&sat=100&brightness=100
- set lights with IDs 1, 3 and 4 to HSI mode, with the hue set to 240º (blue), with saturation and brightness set to 100% - to send to lights 3 and 4, NeewerLite-Python will need to have lights found in that range. If you ask for a light ID that's not in the currently available range, the HTTP daemon will just skip over that light.
Alternatively,
http://127.0.0.1:8080/NeewerLite-Python/doAction?light=11:22:33:44:55:66;3;4&mode=HSI&hue=240&sat=100&brightness=100
- set the light with MAC address 11:22:33:44:55:66, along with lights 3 and 4, to HSI mode, with the hue set to 240º (blue), with saturation and brightness set to 100%
* - Default mode parameters (if only the mode
parameter is used, or one of the values are left out):
CCT
mode - Default color temperature: 5600K / Default brightness: 100%
HSI
mode - Default hue: 240º / Default saturation: 100% / Default brightness: 100%
ANM
or SCENE
mode - Default animation : 1 (Police Sirens) / Default brightness: 100%