Python Websockets to control QLC

Ask a generic question about the usage of QLC+, not related to a particular operating system
Post Reply
waxcam
Posts: 4
Joined: Wed Dec 06, 2023 3:33 pm
Real Name: Joe Long

Hi I'm new to the forum I hope this is in the right place. I was wondering if anyone could throw some light on this (see what I did there) I have a small podcast and have built quiz buttons that are controlled through esp33 wifi and Python, what I'm trying to do is have the lights change to the teams colours when their quiz button is pressed, I have set up the scenes on the virtual desk and they all work when I press the the button in QLC+ also I can get them to change on the web app and the Web test app by putting in the button ID and 255 for on and 0 for off. The problem I have is finding the right command to change the value of the button with Python using websockets. I can't find documentation to do this anywhere. I only mess with coding so It will be my fault, I have tried searching but I'm still turning up blank. I thought I would reach out and ask if anyone else has had any luck.

This is the code I have so far its taken from the forum and modified to try and change the value to from 0 to 255.
It basically checks and prints the value of button 0 then tries to change the value and rechecks and prints it again.

import asyncio
import websockets

async def test():
async with websockets.connect('ws://192.168.1.164:9999/qlcplusWS') as websocket:
await websocket.send("QLC+API|" + "getWidgetsList")
response = await websocket.recv()
widgets = []
llista = iter(response.split('|')[2:])
for i in llista:
widget = [i, next(llista)]
widgets.append(widget)

for i in widgets:
await websocket.send("QLC+API|" + "getWidgetType" + '|' + i[0])
response = await websocket.recv()
print("Button ID: ",i[0], response.split('|')[2])

await websocket.send("QLC+API|" + "getWidgetStatus" + '|' + i[0])
response = await websocket.recv()
print("Current Button value:", response)

await websocket.send("QLC+API|WidgetSetValue|0|BUTTON|255")
response = await websocket.recv()
print("Set Button to 255:", response)

await websocket.send("QLC+API|" + "getWidgetStatus" + '|' + i[0])
response = await websocket.recv()
print("New value:", response)

asyncio.get_event_loop().run_until_complete(test())


This is the line I'm struggling with websocket.send("QLC+API|WidgetSetValue|0|BUTTON|255") I'm not sure what should be in the widgetsetvalue

this is the result I'm getting the value stays at 0

Button ID: 0 Button
Current Button value: QLC+API|getWidgetStatus|0
Set Button to 255: QLC+API|WidgetSetValue|
New value: QLC+API|getWidgetStatus|0




hoping someone can help thanks Joe
User avatar
sbenejam
Posts: 550
Joined: Sun Apr 12, 2015 6:28 pm
Real Name: Santiago Benejam Torres
Contact:

A button in the Virtual Console needs a function or scene assigned to stay on. A button in Black Out or Stop all functions don't. Can you share your workspace project?
waxcam
Posts: 4
Joined: Wed Dec 06, 2023 3:33 pm
Real Name: Joe Long



I have linked a video to try and explain what's going on
I have attached the file I use in QLC
the Python 3 code I used in the video is below
It will need asyncio and websockets libarys to run

import asyncio
import websockets

async def test():
async with websockets.connect('ws://192.168.1.223:9999/qlcplusWS')as websocket:
await websocket.send("QLC+API|" + "getWidgetsList")
response = await websocket.recv()
widgets = []
llista = iter(response.split('|')[2:])
for i in llista:
widget = [i, next(llista)]
widgets.append(widget)

for i in widgets:
await websocket.send("QLC+API|" + "getWidgetType" + '|' + i[0])
response = await websocket.recv()
print("Button ID: ",i[0], response.split('|')[2])

await websocket.send("QLC+API|" + "getWidgetStatus" + '|' + i[0])
response = await websocket.recv()
print("Current Button value:", response)

await websocket.send("QLC+API|"+ i[0]+ "|BUTTON|255")
response = await websocket.recv()
print("Set Button to 255:", response)

await websocket.send("QLC+API|" + "getWidgetStatus" + '|' + i[0])
response = await websocket.recv()
print("New value:", response)

asyncio.get_event_loop().run_until_complete(test())

this is the line I think I need to work out await websocket.send("QLC+API|"+ i[0]+ "|BUTTON|255")
I have tried lots of different ways including "Basic widget value set" from the web test page

await websocket.send("QLC+API|" +"Basic widget value set|"+ i[0]+ "|BUTTON|255")

Thanks Joe
Attachments
test_for_API.qxw
(9.86 KiB) Downloaded 138 times
waxcam
Posts: 4
Joined: Wed Dec 06, 2023 3:33 pm
Real Name: Joe Long

await websocket.send("0|255") I worked it out this is the line thats requires the 0 is the id the 255 is on well pleased I hope this helps someone !
Post Reply