API web socket with python help?

Hello all. Im not sure where I should ask this, but maybe someone can point me in the right direction.

Im trying to develop a python application that will pull information from the API with socket.io so I can send that data out a serial port to a custom display.

Does anyone have working on the latest Volumio release, a bit of python code snippet that runs on the Volumio host, that can access the API socket.io? I am OK with the serial part so far, I can talk to my display out the GPIO UART, but I seemingly struggle with python and socket.io. Possibly the python is too old? I cant get modules to load, or unsure of what socket IO module will work with python that comes installed by default on Volumio. Ive googled my brains out but most information is scattered or old and doesn’t work. Im new to python. Im just looking for a bit of how to on getting the development environment working and help with a piece of working code as simple as getting the status of the player.

Im also open to ideas on how to do this other ways besides python. I only need to get the status (play, pause), track and artist name.


By latest, you mean Volumio V2.x? I have successfully used Python to drive a display and IR, but recently ported to nodejs - a new language to me.
To talk to Volumio via socketio, you need to install socketio client v2.x at least from memory. Versions are problem so some experimentation will be required.

If you want a simple way to get the status make an os call to mpd - “mpc status” Try it from the command line first to see the info. that you will have to parse. I used this method before moving to socket.io.
volumio@volumio2:~$ mpc status
Radio Paradise (flac) - playlist: radioparadise.com: Aimee Mann - High On Sunday 51
[playing] #1/1 107:15/0:00 (0%)
volume: n/a repeat: off random: off single: off consume: off

You will have to poll say once a second.

Here are the Python snippets…

import os

Readlines into list and strip linefeeds from each item.

def execCommand(self,cmd):
		self.data = []
		self.p = os.popen(cmd)
		self.data = self.p.readlines()				# get lines of command into a list
		if len(self.data) >= 1:
			for self.i in range(len(self.data)):
				self.data[self.i] = self.data[self.i].rstrip('\n')
			self.data = ['No Data']				# return no data
		return self.data
# Execute MPC comnmand
def execMpcCommand(self,cmd):
	return self.execCommand(Mpc + " " + cmd)

Hi thank you for the reply. After I posted this I believe you might be right, that it might be easier to do it this way. I also found that there is a volumio command I can run that gets the status as well, probably similar to mpd as you mentioned. I was hoping for the server to emit events to me,. but polling every few seconds will be OK. I will try to learn how to do this :slight_smile: Thanks