Page 1 of 1

QLCplus control by Python

Posted: Sat Mar 05, 2022 12:48 pm
by Keith
Hello again, first off as those here already know, QLCplus is one great program, thank you Massimo! Also thanks to him I have QLC running on the pi desktop.
My programming strength is Python but weak on the Linux so please excuse.
For this project I would like my Python script to send commands to QLC. From what I have read the way to do this is through OSC. Assuming that is correct I attempted to load OSC on the pi, but when I import osc Python says the package doesn't exist. If I tell Linux to load osc again
$ sudo -H pip3 install python-osc
It says that it is already installed in Python 3.
I have searched for information on this and seemingly there are various OSC packages out there so I'm not even sure this is the proper one, or even, if this is the best approach to controlling QLC from Python.
Thanks for any help, once I get back to Python I shouldn't have to ask so many questions.

Re: QLCplus control by Python

Posted: Sun Mar 06, 2022 7:55 pm
by mcallegari
There are web API. Much simpler than creating OSC packets
https://www.qlcplus.org/Test_Web_API.html

Re: QLCplus control by Python

Posted: Mon Mar 07, 2022 12:56 pm
by Keith
Thank you Massimo, I have downloaded the API and will proceed on that path. For my simple application the API should do everything I need.

Re: QLCplus control by Python

Posted: Wed Feb 01, 2023 11:01 pm
by bob60
Hello,

I'm looking for a way to launch QLC+ scenes from an external program.
The QLC+ Web API Test page works fine, but I couldn't transpose the javascript to a text command line .
I'm mostly interested in the websocket connection and the getFunctionsList and setFunctionStatus functions.

Does anyone have a piece of python code to share?

Thank you very much

Re: QLCplus control by Python

Posted: Fri Feb 03, 2023 1:49 pm
by sbenejam
I made some weeks ago some tests with python against QLC+ API. I hope it's helpful.

Code: Select all

import asyncio
import websockets
async def test():
     async with websockets.connect('ws://10.32.234.136:9999/qlcplusWS')
as websocket:
         await websocket.send("QLC+API|" + "getWidgetsList")
         response = await websocket.recv()
         widgets=[]
         # ~ print(text.split('|'))
         llista=iter(response.split('|')[2:])
         for i in llista:
             # ~ print(i, next(llista))
             widget=[i, next(llista)]
             widgets.append(widget)
         # ~ print(widgets)
         for i in widgets:
             await websocket.send("QLC+API|" + "getWidgetType" + '|' + i[0])
             response = await websocket.recv()
             print (i[0], response.split('|')[2])
asyncio.get_event_loop().run_until_complete(test())

Re: QLCplus control by Python

Posted: Sat Feb 11, 2023 3:45 pm
by bob60
Thank you very much Santiago !

Your code works for me.
I realize the gap between my knowledge of python and the required mastery in arrays management, but I think I can adapt it for my needs.

I'll keep you informed
Robert