Python access to websocket API

I’ve been searching around both this site and the source code of Volumio2, but didn’t find enough info.
Are there any examples for accesing the websocket API for Volumio2 from Python?
I’m specifically looking for info on the API endpoint (/api ?), port and other details.

/Joakim

You can use socket.io for python pypi.python.org/pypi/socketIO-client

and use websockets APIs as per docs:
volumio.github.io/docs/API/WebSocket_APIs.html

Hello,
I have a Raspberry PIB +touchscreen and try to build a Ruby/TK interface using the API (because web UI doesn’t work on RPI1)

Here is a code I built to see how the API works. I think you can easily translate it to Python.

Also look into Volumio2-UI/app/services to see the availables commands.

require 'socket.io-client-simple'
socket = SocketIO::Client::Simple.connect 'http://volumio:3000'

socket.on :disconnect do
  puts "disconnected!!"
end

socket.on :error do |err|
  p err
end

socket.on :pushState do |data|
    puts data
end

socket.on :getBrowseFilters do |data|
    puts data
end

socket.on :pushBrowseLibrary do |data|
  puts Time.now
    # puts data
end


puts "please input and press Enter key"
loop do

  puts "====================="
  puts "getBrowseSources"
  puts "getBrowseFilters"
  puts "getState"
  puts "getTrackInfo"
  puts "getSeek"
  puts "getMultiroom"
  puts "getMultiRoomDevices"
  puts "getQueue"
  puts "listPlaylist"
  puts "search"
  puts "play"
  puts "stop"
  puts "prev"
  puts "next"
  puts "shuffle"
  puts "browseLibrary"
  puts "====================="

  msg = STDIN.gets.strip
  next if msg.empty?

  vals = msg.split "|"

  code = vals[0]
  h = eval(vals[1]) if vals[1]
  #h = {"uri"=>"music-library"}

  if h
    puts h
    puts Time.now
    socket.emit code, h
  else
    puts Time.now
    socket.emit code
  end

end

I tried that version of the library and got a “400” error when trying to connect to volumio.

What did work for me is socketIO-client-2:
pypi.python.org/pypi/socketIO-client-2

Worked flawlessly for me on RPi B.

Thanks for the info - I’ll try again with a clean install of volumio.

If your problems persist, feel free to contact me, then I’ll send you the code I’ve used.

I’m using socketIO_client on Odroid C1, works perfectly. Here’s the script:
https://gist.github.com/ivesdebruycker/4b08bdd5415609ce95e597c1d28e9b9e