QLCplus control by Python

All the topics related to QLC+ on the Raspberry Pi
Post Reply
Keith
Posts: 8
Joined: Sun Feb 27, 2022 6:00 pm
Real Name: 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.
User avatar
mcallegari
Posts: 4482
Joined: Sun Apr 12, 2015 9:09 am
Location: Italy
Real Name: Massimo Callegari
Contact:

There are web API. Much simpler than creating OSC packets
https://www.qlcplus.org/Test_Web_API.html
Keith
Posts: 8
Joined: Sun Feb 27, 2022 6:00 pm
Real Name: 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.
bob60
Posts: 6
Joined: Tue Feb 01, 2022 8:40 pm
Real Name: Robert

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
User avatar
sbenejam
Posts: 550
Joined: Sun Apr 12, 2015 6:28 pm
Real Name: Santiago Benejam Torres
Contact:

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())
bob60
Posts: 6
Joined: Tue Feb 01, 2022 8:40 pm
Real Name: Robert

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
Post Reply