Connect to the volumio websocket server

Hi,

I want make test with the volumio’s websocket server.

I install volumio on raspberry pi B, the pi is in a local network on 192.168.xx.xx.

i want run a python script to connect to the volumio websocket server.

import socketio

# standard Python

sio = socketio.Client()

@sio.event

def connect():

    print("I'm connected!")

       

sio.connect('http://192.168.xx.xx:3000')

sio.wait()

when I run script, I have an error with connection.

i read WebSocket APIs - Volumio Documentation, but i didn’t found the information about connection.

could you help me?

you should do something like

from socketIO_client import SocketIO

def parseStatus(state):
    code to handle
  socketIO = SocketIO('localhost', 3000)
  socketIO.on('pushState', parseStatus)
  socketIO.emit('getState', '', parseStatus)


def main():
	socketIO.wait()
	sleep(0.3)
	
try:
    main()
except KeyboardInterrupt:
    print("Exiting...")
    pass

I try this code

import Socketio

def parseStatus(state):
    code to handle
  socketIO = Socketio('localhost', 3000)
  socketIO.on('pushState', parseStatus)
  socketIO.emit('getState', '', parseStatus)


def main():
	socketIO.wait()
	sleep(0.3)
	
try:
    main()
except KeyboardInterrupt:
    print("Exiting...")
    pass

i have an error socketIO about .wait()

an another question is how to connect to an another adresse than localhost?

I try my first scrip on my pi with adress localhost,

i have error

(websocket-env) volumio@volumio:~/websocket$ python essai_connection.py
Traceback (most recent call last):
File “essai_connection.py”, line 14, in
sio.connect(‘http://localhost:3000’)
File “/home/volumio/websocket/websocket-env/lib/python3.7/site-packages/socketio/client.py”, line 338, in connect
raise exceptions.ConnectionError(exc.args[0]) from None
socketio.exceptions.ConnectionError: Unexpected response from server
(websocket-env) volumio@volumio:~/websocket$

i believe I started with:
from socketIO_client import SocketIO

as I expect you’re programming the client side not the server?

hi

I succeeded to connect my voumio.

from socketIO_client import SocketIO
socketIO = SocketIO('localhost', 3000)
socketIO.emit('aaa')
socketIO.wait(seconds=1)

i uninstall the python-socketio lib and install socketIO-client lib.

thx you, now I can do my test.