Page 1 of 1

QLC+, API, websockets and Python3

Posted: Sat Jun 01, 2024 2:08 pm
by raggy
Hello everybody,

i'll excuse in advance but im digging trough Google and the forum for a week now and slowly turn insane on this topic.

Maybe i dont understand some things, ask the wrong questions or miss some trivial things.
Please bear with me, i'm something on beginner-advanced level in python.

Situation:

Roughly half a year ago i built an interactive device with an RPi 3B, an RFID scanner and some audio files running on python together with VLC-lib.
Basically each RFID tag was connected to a certain audio file, which was played then.

It worked fine and was kinda sucessfull, so i though to turn it up a bit.

Plan:
Trigger some lighting scenes with it too.

So i got the RPi5 (RPi OS Bookworm), RPi QLC+ version and a DMX interface.... in stand alone conditions everything is cool.

But now i tried to extend my python script and make it to communicate with QLC+.

As far as i understood, the fastest way is to connect the API via websocket and there the problems began:
No matter what i try, the shell keeps nagging with various errors which i dont really understand even when i try some code snippets from the forum.

Could someone explain it to me like i'm a complete dummy please?

Basically i tried something like that:

Code: Select all

import websockets

websockets.connect('ws://QLC-IP:9999/qlcplusWS') # Web interface is up and running smoothly

if a_certain_condition_is_met = true:
   websockets.send("start a particular scene") # Shell tells me, there is no "send" in websockets-lib so maybe i do something wrong or use the wrong documentation

Anyone an idea?

Re: QLC+, API, websockets and Python3

Posted: Mon Jun 03, 2024 10:10 am
by Yestalgia
I'm guessing you've had a play with the web api test page? https://www.qlcplus.org/Test_Web_API.html

Don't forget to launch QLC+ with the -w flag to enable the web interface.

In your example you use `QLC-IP`, if QLC+ is local then it should be the loopback address (127.0.0.1), if it is running on a different machine make sure they're on the same network.

Re: QLC+, API, websockets and Python3

Posted: Mon Jun 03, 2024 10:17 am
by raggy
Yestalgia wrote: Mon Jun 03, 2024 10:10 am I'm guessing you've had a play with the web api test page? https://www.qlcplus.org/Test_Web_API.html

done that

Don't forget to launch QLC+ with the -w flag to enable the web interface.

done that too... Used --web but it's running

In your example you use `QLC-IP`, if QLC+ is local then it should be the loopback address (127.0.0.1), if it is running on a different machine make sure they're on the same network.

Like I said: at the moment it's more a python problem rather than a qlc problem

Re: QLC+, API, websockets and Python3

Posted: Mon Jun 03, 2024 11:03 am
by GGGss
In your project, I would ease down a bit with the overlay of the .API and use the available Python libraries to send out OSL2, OSC or even Artnet (not advised in this setup) messages to QLC+ and let your imagination grow what QLC+ need to do when it gets its 'call for x/y/z calls'.
Using this method, you only have to handle your external inputs, and QLC+ will do the rest. It works (!)

Re: QLC+, API, websockets and Python3

Posted: Tue Jun 04, 2024 9:13 am
by raggy
Or you just abstract this one and tinker a bit around: viewtopic.php?t=17089 (by waxcam)

In the end everything you need is this:

Code: Select all


import asyncio
import websockets
from websocket import create_connection, WebSocketException

TARGET_WS_URL = "ws://127.0.0.1:9999/qlcplusWS"
ws = create_connection(TARGET_WS_URL)

ws.send("key|value") #key ID from virtual concole, value 0-255