snapcast icon indicating copy to clipboard operation
snapcast copied to clipboard

Multiple snapclients on same machine - names howto?

Open ztardik opened this issue 2 years ago • 2 comments

Discussed in https://github.com/badaix/snapcast/discussions/988

Originally posted by ztardik February 18, 2022 Hello, I'm trying to setup a multizone player/amp with snapcast. At the moment snapserver and 4 snapclients run on the same orangepi zero with 4 usb DACs. Everything works fine except the zone names don't get automatically assigned.

The snapclients start via system services, one for each zone:

# systemctl status snapclient_zone1.service

● snapclient_zone1.service - Snapcast client Zone 1 Loaded: loaded (/lib/systemd/system/snapclient_zone1.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2022-02-18 12:32:48 +06; 5min ago Docs: man:snapclient(1) Main PID: 1729 (snapclient) Tasks: 2 (limit: 905) Memory: 1.6M CPU: 1.529s CGroup: /system.slice/snapclient_zone1.service └─1729 /usr/bin/snapclient --logsink=system -h 127.0.0.1 --hostID Zona-1 -i 1 -s Zone1

Feb 18 12:33:36 orangepizero snapclient[1729]: Player name: alsa, device: hw:CARD=Zone1,DEV=0, description: CX31993 384Khz HIFI AUDIO, USB Audio Feb 18 12:33:37 orangepizero snapclient[1729]: Direct hardware device without any conversions, idx: 16, sharing mode: unspecified, parameters: Feb 18 12:33:37 orangepizero snapclient[1729]: Mixer mode: software, parameters: Feb 18 12:33:37 orangepizero snapclient[1729]: Sampleformat: 48000:16:2, stream: 48000:16:2 Feb 18 12:33:37 orangepizero snapclient[1729]: Using default buffer_time: 80 ms, default fragments: 4 Feb 18 12:33:37 orangepizero snapclient[1729]: PCM name: hw:CARD=Zone1,DEV=0, sample rate: 48000 Hz, channels: 2, buffer time: 80000 us, periods: 4, period time: 20000 us, period frames: 960 Feb 18 12:33:37 orangepizero snapclient[1729]: No chunks available Feb 18 12:33:37 orangepizero snapclient[1729]: Failed to get chunk Feb 18 12:33:37 orangepizero snapclient[1729]: diff to server [ms]: 0.089 Feb 18 12:33:42 orangepizero snapclient[1729]: No chunk received for 5000ms. Closing ALSA.

# cat /lib/systemd/system/snapclient_zone1.service

[Unit]
Description=Snapcast client Zone 1
Documentation=man:snapclient(1)
Wants=avahi-daemon.service
After=network-online.target time-sync.target sound.target avahi-daemon.service

[Service]
EnvironmentFile=-/etc/default/snapclient1
ExecStart=/usr/bin/snapclient --logsink=system $SNAPCLIENT_OPTS
User=snapclient
Group=snapclient
Restart=on-failure

[Install]
WantedBy=multi-user.target

# cat /etc/default/snapclient1

START_SNAPCLIENT=true
SNAPCLIENT_OPTS="-h 127.0.0.1 --hostID 'Zona-1' -i 1 -s Zone1"

The "-s" parameter is set in udev rules: # cat /etc/udev/rules.d/20-alsa-usb-cards.rules

SUBSYSTEM=="sound", KERNELS=="3-1.1",  ATTR{id}="Zone1"
SUBSYSTEM=="sound", KERNELS=="3-1.2",  ATTR{id}="Zone2"
SUBSYSTEM=="sound", KERNELS=="3-1.3",  ATTR{id}="Zone3"
SUBSYSTEM=="sound", KERNELS=="3-1.4",  ATTR{id}="Zone4"

Snapserver response when clients connect:

[Info] (Server) Hello from Zona-1, host: orangepizero, v0.26.0, ClientName: Snapclient, OS: Debian GNU/Linux 11 (bullseye), Arch: armv7l, Protocol version: 2 [Info] (Server) Hello from Zona-2#2, host: orangepizero, v0.26.0, ClientName: Snapclient, OS: Debian GNU/Linux 11 (bullseye), Arch: armv7l, Protocol version: 2 Info] (Server) Hello from Zona-3#3, host: orangepizero, v0.26.0, ClientName: Snapclient, OS: Debian GNU/Linux 11 (bullseye), Arch: armv7l, Protocol version: 2 [Info] (Server) Hello from Zona-4#4, host: orangepizero, v0.26.0, ClientName: Snapclient, OS: Debian GNU/Linux 11 (bullseye), Arch: armv7l, Protocol version: 2

So, the question is, how can I get the server to refer to clients as set in "--hostID", without adding "#2, #3 ..." ? I know that I can rename them in web interface but it would be much nicer if they'll just use the configured name. I've tried with chname as suggested a few years ago, it works nice in CLI, but for some reason I can't get it run in init script.

TLDRL; How to get the client names from "--hostID" to show up like "Kitchen" and "Bedroom", instead of "Kitchen#2" and "Bedroom#4"?

ztardik avatar Feb 19 '22 08:02 ztardik

You currently cannot specify the name as shown in the GUI on the command line. I think there is an open feature request for this. hostID is just a unique id for the host and instance will be appended to the hostID, and reported as client id to the server. The server stores a configuration for each client (identified by hostID#instance) that is also holding the visible name of the client. If it's not configured, the host name will be used (every client reports some meta data, among other things the host name). The feature request has not been implemented yet, because it's not clear if the client CLI name parameter should override the name which is configured on the server.

badaix avatar Feb 20 '22 19:02 badaix

Thanks @badaix , This is exactly what was going on with the #number thing. After removing the -i (instance) configuration the snapserver log shows only the hostID name as configured. I didn't find that in documentation.

[Info] (Server) Hello from Zona-4, host: orangepizero, v0.26.0, ClientName: Snapclient, OS: Debian GNU/Linux 11 (bullseye), Arch: armv7l, Protocol version: 2

The feature request has not been implemented yet, because it's not clear if the client CLI name parameter should override the name which is configured on the server.

The hostID is never configured by default, so one can assume the user deliberately wants to change the default name. I think it's safe to assume the hostID is the preferred name if configured.

ztardik avatar Feb 21 '22 11:02 ztardik