From e8aa049e0ab5cf3dd6cf6a60caab425c18ebf9e6 Mon Sep 17 00:00:00 2001 From: Zach Glenwright Date: Fri, 24 Dec 2021 09:54:34 -0500 Subject: [PATCH] 12-24-21 - 0.5b - Added query parameter to HTTP URL - Fixed very beginning of script which listed wrong (the original) URL to the project - Added required query parameter (for the request in #9) to the HTTP server URLs (so the /NeewerLite-Python/ URLs need a doAction? before their action, like "/NeewerLite-Python/doAction?light=1&bri=0" - Changed version number from 0.5a to 0.5b --- NeewerLite-Python.py | 48 ++++++++++++++++++++++---------------------- ui_NeewerLightUI.py | 2 +- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/NeewerLite-Python.py b/NeewerLite-Python.py index f321ee8..4dd5397 100644 --- a/NeewerLite-Python.py +++ b/NeewerLite-Python.py @@ -2,7 +2,7 @@ ## NeewerLite-Python ## by Zach Glenwright ############################################################# -## > https://github.com/taburineagle/Neewer-PythonLite < +## > https://github.com/taburineagle/NeewerLite-Python/ < ############################################################# ## A cross-platform Python script using the bleak and ## PySide2 libraries to control Neewer brand lights via @@ -1137,10 +1137,10 @@ def do_GET(self): return else: # CHECK THE LENGTH OF THE URL REQUEST AND SEE IF IT'S TOO LONG - if len(self.path) > 150: + if len(self.path) > 159: # INCREASED LENGTH DUE TO ADDITION OF doAction IN THE URL # THE LAST REQUEST WAS WAY TOO LONG, SO QUICKLY RENDER AN ERROR PAGE AND RETURN FROM THE HTTP RENDERER writeHTMLSections(self, "header") - writeHTMLSections(self, "errorHelp", "The last request you provided was too long! The NeewerLite-Python HTTP server can only accept URL commands less than 132 characters long after /NeewerLite-Python/.") + writeHTMLSections(self, "errorHelp", "The last request you provided was too long! The NeewerLite-Python HTTP server can only accept URL commands less than 132 characters long after /NeewerLite-Python/doAction?.") writeHTMLSections(self, "footer") return @@ -1167,7 +1167,7 @@ def do_GET(self): self.send_error(403, "The IP of the device you're making the request from (" + clientIP + ") has to be in the list of accepted IP addresses in order to use the NeewerLite-Python HTTP Server, any outside addresses will generate this Forbidden error. To use this device with NeewerLite-Python, add its IP address (or range of IP addresses) to the list of acceptable IPs") return - acceptableURL = "/NeewerLite-Python/" + acceptableURL = "/NeewerLite-Python/doAction?" if not acceptableURL in self.path: # if we ask for something that's not the main directory, then redirect to the main error page self.send_response(302) @@ -1175,7 +1175,7 @@ def do_GET(self): self.end_headers() return - else: # if the URL contains "/NeewerLite-Python/" then it's a valid URL + else: # if the URL contains "/NeewerLite-Python/doAction?" then it's a valid URL writeHTMLSections(self, "header") # BREAK THE URL INTO USABLE PARAMTERS @@ -1217,7 +1217,7 @@ def do_GET(self): totalLights = len(availableLights) if totalLights == 0: # there are no lights available to you at the moment! - self.wfile.write(bytes("NeewerLite-Python is not currently set up with any Neewer lights. To discover new lights, click here.
", "utf-8")) + self.wfile.write(bytes("NeewerLite-Python is not currently set up with any Neewer lights. To discover new lights, click here.
", "utf-8")) else: self.wfile.write(bytes("List of available Neewer lights:
", "utf-8")) self.wfile.write(bytes("", "utf-8")) @@ -1266,39 +1266,39 @@ def writeHTMLSections(self, theSection, errorMsg = ""): self.wfile.write(bytes(errorMsg + "

", "utf-8")) self.wfile.write(bytes("Valid parameters to use -
", "utf-8")) self.wfile.write(bytes("list - list the current lights NeewerPython-Lite has available to it
", "utf-8")) - self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/list
", "utf-8")) + self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/doAction?list
", "utf-8")) self.wfile.write(bytes("discover - tell NeewerLite-Python to scan for new lights
", "utf-8")) - self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/discover
", "utf-8")) + self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/doAction?discover
", "utf-8")) self.wfile.write(bytes("link= - (value: index of light to link to) manually link to a specific light - you can specify multiple lights with semicolons (so link=1;2 would try to link to both lights 1 and 2)
", "utf-8")) - self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/link=1
", "utf-8")) + self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/doAction?link=1
", "utf-8")) self.wfile.write(bytes("light= - the MAC address (or current index of the light) you want to send a command to - you can specify multiple lights with semicolons (so light=1;2 would send a command to both lights 1 and 2)
", "utf-8")) - self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/light=11:22:33:44:55:66
", "utf-8")) + self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/doAction?light=11:22:33:44:55:66
", "utf-8")) self.wfile.write(bytes("mode= - the mode (value: HSI, CCT, and either ANM or SCENE) - the color mode to switch the light to
", "utf-8")) - self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/mode=CCT
", "utf-8")) + self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/doAction?mode=CCT
", "utf-8")) self.wfile.write(bytes("(CCT mode only) temp= or temperature= - (value: 3200 to 8500) the color temperature in CCT mode to set the light to
", "utf-8")) - self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/temp=5200
", "utf-8")) + self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/doAction?temp=5200
", "utf-8")) self.wfile.write(bytes("(HSI mode only) hue= - (value: 0 to 360) the hue value in HSI mode to set the light to
", "utf-8")) - self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/hue=240
", "utf-8")) + self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/doAction?hue=240
", "utf-8")) self.wfile.write(bytes("(HSI mode only) sat= or saturation= - (value: 0 to 100) the color saturation value in HSI mode to set the light to
", "utf-8")) - self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/sat=65
", "utf-8")) + self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/doAction?sat=65
", "utf-8")) self.wfile.write(bytes("(ANM/SCENE mode only) scene= - (value: 1 to 9) which animation (scene) to switch the light to
", "utf-8")) - self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/scene=3
", "utf-8")) + self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/doAction?scene=3
", "utf-8")) self.wfile.write(bytes("(CCT/HSI/ANM modes) bri=, brightness= or intensity= - (value: 0 to 100) how bright you want the light
", "utf-8")) - self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/brightness=80
", "utf-8")) + self.wfile.write(bytes("    Example: http://(server address)/NeewerLite-Python/doAction?brightness=80
", "utf-8")) self.wfile.write(bytes("

More examples -
", "utf-8")) self.wfile.write(bytes("  Set the light with MAC address 11:22:33:44:55:66 to CCT mode, with a color temperature of 5200 and brightness of 40
", "utf-8")) - self.wfile.write(bytes("    http://(server address)/NeewerLite-Python/light=11:22:33:44:55:66&mode=CCT&temp=5200&bri=40

", "utf-8")) + self.wfile.write(bytes("    http://(server address)/NeewerLite-Python/doAction?light=11:22:33:44:55:66&mode=CCT&temp=5200&bri=40

", "utf-8")) self.wfile.write(bytes("  Set the light with MAC address 11:22:33:44:55:66 to HSI mode, with a hue of 70, saturation of 50 and brightness of 10
", "utf-8")) - self.wfile.write(bytes("    http://(server address)/NeewerLite-Python/light=11:22:33:44:55:66&mode=HSI&hue=70&sat=50&bri=10

", "utf-8")) + self.wfile.write(bytes("    http://(server address)/NeewerLite-Python/doAction?light=11:22:33:44:55:66&mode=HSI&hue=70&sat=50&bri=10

", "utf-8")) self.wfile.write(bytes("  Set the first light available to SCENE mode, using the first animation and brightness of 55
", "utf-8")) - self.wfile.write(bytes("    http://(server address)/NeewerLite-Python/light=1&mode=SCENE&scene=1&bri=55
", "utf-8")) + self.wfile.write(bytes("    http://(server address)/NeewerLite-Python/doAction?light=1&mode=SCENE&scene=1&bri=55
", "utf-8")) elif theSection == "footer": footerLinks = "Shortcut links: " - footerLinks = footerLinks + "Scan for New Lights | " - footerLinks = footerLinks + "List Currently Available Lights" + footerLinks = footerLinks + "Scan for New Lights | " + footerLinks = footerLinks + "List Currently Available Lights" self.wfile.write(bytes("
" + footerLinks + "
", "utf-8")) - self.wfile.write(bytes("NeewerLite-Python 0.5a by Zach Glenwright
", "utf-8")) + self.wfile.write(bytes("NeewerLite-Python 0.5b by Zach Glenwright
", "utf-8")) self.wfile.write(bytes("", "utf-8")) def formatStringForConsole(theString, maxLength): @@ -1339,7 +1339,7 @@ def formatStringForConsole(theString, maxLength): sys.exit(0) if cmdReturn[0] == "LIST": - print("NeewerLite-Python 0.5a by Zach Glenwright") + print("NeewerLite-Python 0.5b by Zach Glenwright") print("Searching for nearby Neewer lights...") loop.run_until_complete(findDevices()) @@ -1457,7 +1457,7 @@ def formatStringForConsole(theString, maxLength): print(" If you have already installed the PySide2 library but are still getting this error message,") print(" Make sure you have the ui_NeewerLightUI.py script in the same directory as NeewerLite-Python.py") print(" If you don't know where that file is, redownload the NeewerLite-Python package from Github here:") - print(" https://github.com/taburineagle/NeewerLite-Python") + print(" https://github.com/taburineagle/NeewerLite-Python/") sys.exit(1) # quit out, we can't run the program without PySide2 or the GUI (for the GUI version, at least) else: # don't launch the GUI, send command to a light/lights and quit out diff --git a/ui_NeewerLightUI.py b/ui_NeewerLightUI.py index 6631deb..b10d022 100644 --- a/ui_NeewerLightUI.py +++ b/ui_NeewerLightUI.py @@ -304,7 +304,7 @@ def setupUi(self, MainWindow): # setupUi def retranslateUi(self, MainWindow): - MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"NeewerLite-Python 0.5a by Zach Glenwright", None)) + MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"NeewerLite-Python 0.5b by Zach Glenwright", None)) self.tryConnectButton.setText(QCoreApplication.translate("MainWindow", u"Connect", None)) self.TFL_CCT_Hue.setText(QCoreApplication.translate("MainWindow", u"Color Temperature", None)) self.TFV_CCT_Hue.setText(QCoreApplication.translate("MainWindow", u"5600K", None))