Some Bits: Nelson's log

7 posts about sonos

Streaming Linux audio to a Sonos S1

My new Linux desktop has a neat trick: I can route the sound I’m hearing to my Sonos S1 speakers. It’s always annoyed me I couldn’t do that easily before.

The magic plumbing is PulseAudio, the Linux subsystem that handles media streams. (Or actually PipeWire, the replacement.) Basically it lets you pipe music (and video) around from program to program.

There’s a third party Sonos controller app for Linux called Noson. It has the ability to tell the Sonos unit to play audio from a network stream. It will then create a network stream for you that is listening to PulseAudio on your Linux box.

Once this is going the Sonos shows it is playing a track named “pulse.flac?acr=hostname:1400”. I don’t think hostname has to actually resolve for it to work.

The other trick is to get the audio going out to PulseAudio. For me the source I want to play is Plexamp. By default Plexamp is playing out my speakers. I used pavucontrol to re-route it, choosing “noson” instead of my usual sound card / speakers for the output. I think I could also have just set this in Plexamp: right now it’s being told to play to “System default” but I can choose where it goes inside the app.

The one downside to this setup is latency. Sonos wants to buffer a stream before playing it so anything I play is delayed about 10 seconds. Not awful but a little annoying.

I’m doing all this to get Plexamp to drive the speakers in my house. Plexamp is really cool, working off my music library and doing all sorts of advanced DJ and mood / genre matching tricks.

(As with anything these days, I figured all this out thanks to AI. Here’s a link to the conversation.)

Pipewire

Need to learn more about this! Here’s what qpwgraph shows me, you can also edit this like patch bays. coppwr is another tool that shows a similar view with more low level detail

Fixing Samba for Sonos v1 (Ubuntu 22.04, 22.10)

To make Samba in Ubuntu 22.04 jammy and 22.10 kinetic work with Sonos v1, add these lines to the global config:

server min protocol = NT1
unix extensions = no

On Sonos the login works fine with a blank username and blank password (assuming your music volume is a guest volume). I think username guest, password blank also works.

That first line has been necessary for awhile because Sonos v1 has an ancient SMBv1 client baked into it and the company won’t update it. The second line about unix extensions is new; it wasn’t necessary in the Samba included in Ubuntu 20.04. I don’t know what changed. Ubuntu 20.04 uses 2:4.13.17~dfsg-0ubuntu1.20.04.1; Ubuntu 22.04 installs 2:4.15.9+dfsg-0ubuntu0.3.

I think the “unix extensions = no” setting is reasonably safe. The docs suggest it does something to make Unix SMB clients happier; I don’t have any of those.

I’ve been low-key chasing a problem for months. It’s been super frustrating. So much so I even considered creating an alternate server. I don’t know if the problem is a change in Samba itself or if it’s specific to the Ubuntu build. I build Samba 4.17.3 from source on Ubuntu 22.10 and had this problem, so that suggests a change of behavior in the sources.

The unix extensions config options seems to have to be in [global]; it didn’t work to put it in the share definition. Here’s the full share definition I am using:

[musicshare]
follow symlinks = yes
wide links = yes
path = /home/nelson/Music
read only = yes
printable = no
guest ok = yes

The stuff in there about symlinks and wide links might not work with unix extensions turned off.

A Sonos v1 SMB server

Summary: do you need a SMB server to serve your local library of music files to your v1 Sonos? Barry de Graaff has a solution, sonossmb. It’s a small Node implementation of SMB that works with Sonos. It works! It does take a bit of hacking to install though.

About sonossmb

I used Samba for years to serve music to the Sonos. The problem is the v1 systems are unsupported and have an ancient insecure SMBv1 client baked into them. And starting with Ubuntu 22 (which has Samba 4.17) it no longer works with Sonos, even with the special v1 config directives. No idea what’s wrong. That got me speculating that a simple stripped down anonymous-only SMBv1 server for Sonos might be a nice product. Which is what de Graaff created!

His server is based on Adobe’s Node SMB server, a project I never heard of and looks abandoned. He tells me it mostly works with Sonos just fine. He just made one tiny change to upcase the share’s name. The packaging and installation is a little trickier. He’s got some good docs and a script but it’s still something you might need to understand Linux pretty well to get running. More on that in a bit.

One problem I ran into; Ubuntu 22 ships Node 18. And that gives an error related to SSL ciphers I think because Node dropped support for old insecure SSL clients. The workaround of export NODE_OPTIONS=--openssl-legacy-provider worked for me.

Note that the share has a name like \\192.168.0.2\PUBLIC and you must log in with the username “guest”, no password. Empty username doesn’t work.

It’d be nice if Samba could be fixed. That SSL thing makes me wonder if that’s what broke on Ubuntu 22, that they too dropped some old SSL stuff that the Sonos ancient client needs. There’s some discussion on the Samba list. One happy thing is one of the Samba developers himself has a Sonos so someone in the know may work on the problem.

Packaging, Snap.

Barry’s server works but I can’t quite use it as-is on my LAN. I really need a full Samba server too. But I only have a single Linux box. And SMB doesn’t work well other than on a single port, 445. Some clients do work on other ports but I haven’t tested it with Sonos and am pessimistic. Maybe I need to just add a second IP address to my server and bind the special Sonos server there, but yuck.

All the drama of getting the thing installed makes me think a Snap container / image is the perfect way to run this server. There’s a snap for the web server Caddy so a daemon that accesses local files and serves them on the network is possible in Snap. But I’ve never built a Snap and have no idea how hard it’d be. I guess Docker would work too but Snap seems to be the choice for consumers on Ubuntu systems so I think starting there makes sense. I may give a go at building a Snap, we’ll see.

adobe/node-smb-server patch

Here’s the patch Barry sent me to upcase filenames:

diff -Naur node-smb-server-master/lib/smb/cmd/tree_connect_andx.js sonos-smb/lib/smb/cmd/tree_connect_andx.js
--- node-smb-server-master/lib/smb/cmd/tree_connect_andx.js	2021-06-22 17:20:12.000000000 +0200
+++ sonos-smb/lib/smb/cmd/tree_connect_andx.js	2022-12-09 08:21:10.674527000 +0100
@@ -10,6 +10,10 @@
  *  governing permissions and limitations under the License.
  */
 
+/* As required by original License I hereby notify you that I have made changes to this file.
+ * Copyright (C) 2022 Barry de Graaff
+ * */
+
 'use strict';
 
 var put = require('put');
@@ -76,7 +80,7 @@
 
   logger.debug('[%s] flags: %s, password: %s, service: %s, path: %s', SMB.COMMAND_TO_STRING[commandId].toUpperCase(), msg.flags.toString(2), msg.password.toString('hex'), msg.service, msg.path);
 
-  var shareName = msg.path.substring(msg.path.lastIndexOf('\\') + 1);
+  var shareName = msg.path.substring(msg.path.lastIndexOf('\\') + 1).toUpperCase();
   var shareLevelPassword = utils.bufferEquals(msg.password, Buffer.from([ 0x00 ])) ? null : msg.password;
   if (_.indexOf(server.getShareNames(), shareName) === -1) {
     result = {

Sonos server alternatives

I’m pulling my hair out trying to get Sonos to connect to my new SMB server. The various dark arts needed to enable SMB1 for Sonos’ ancient file sharing implementation aren’t working and there’s no debugs. Is there some way to share my local music files other than SMB? There’s no way to plug a USB drive into a Sonos directly :-(

One alternative is Plex. It has music capabilities. I’m finding it a little flaky and until I fiddle further it’s only finding files that it has metadata for, not the weird MP3 files that fell off the back of a truck.

Another alternative is Airsonic, another Plex-like media server. It has explicit Sonos support via the Sonic Music API (SMAPI), a new-to-me thing.

A third alternative is Bonob. I know nothing about it, just found it as a SMAPI server. I’ve seen it mentioned in concert with Navidrome.

SMAPI is an interesting back door into Sonos serving! A whole documented API. You can add a service of your own via bare bones HTML interface at http://192.168.0.50:1400/customsd.htm (IP address is of a Sonos player on my LAN). I wonder what the API schema is like; I suspect it is oriented to music with tidy metadata and not “giant pile of MP3 files in carefully curated directories”.

There’s some small or abandoned GitHub projects that are SMAPI servers: YouTube, a NodeJS server, a C# server. This NPR One service looks active.

You know what would be really nice? A stripped down SMB1 anonymous server solely for Sonos clients. Samba is so complicated, something that works with Sonos’ ancient client might work better. Alternately some folks use a Raspberry PI as a NAS/SMB gateway.

Ubuntu 20 vs Sonos: SMBv1

After I upgraded to Ubuntu 20.04 my music library stopped working on my Sonos. Turns out this is a Samba problem. Somewhere along the line Samba disabled SMBv1 by default; apparently it’s insecure and old. However some clients like Sonos only support SMBv1, so the result sucks.

The fix is easy. Add this to your smb.conf and restart Samba

server min protocol = NT1

I also have these lines lurking around for other obsolete clients, but I’m not sure they even work any more. They aren’t necessary for Sonos.

ntlm auth = yes
nltm auth = ntlmv1-permitted

Sonos sure could do a nicer job of error handling. The only error you get is “it failed” with a link to some irrelevant docs about Windows stack size. I figured out the real problem in this Reddit thread.

Apparently this is also a problem with Synology servers, which recently switched to SMBv2 or above only.

I don’t know if there’s a security risk in exposing SMBv1 this way. It’s all behind my firewall so I’m kind of hoping the Maginot line keeps me safe. Also it’s a freakin guest read only fileshare, why is there any login protocol at all? Ugh.

It’d be nice if Sonos upgraded to a newer SMB client, but apparently they’re not in a hurry to. And now given the major platform switch plus their emphasis on streaming services over local music, I’m a little afraid SMB may never be updated on Sonos.

Sonos hacking

I love my Sonos devices, they are reliable and sound great. I’m also curious how they work, and I do wish there were better diagnostics for media files that refuse to play.

Turns out the Sonos has an admin web interface on port 1400. A URL like http://192.168.0.20:1400/support/review brings up a bunch of debug data; substitute the IP address for one of your Sonos devices. It loads slowly. Also appears to be centralized, no need to find the right device first.

I also found my way to SoCo, an open source hacker interface to the Sonos. Command line control over playing, queuing, etc. Neat stuff and seems to work.

What I haven’t found is any way to get an error message why a track won’t play :-(

I thought the Network Matrix was interesting. Screenshot below. STP presumably refers to spanning tree. Sonos’ core magic is the way music plays completely correctly, synchronized, in an unmanaged wireless network. Presumably this is the status of the magic that makes that work.

Screen Shot 2014-09-26 at 10.58.02 AM

Sonos id3v2 tags

Over on the Sonos forums I asked about which ID3v2 tags the Sonos uses. I got a great reply that seems to be correct, reproducing it here. It’s from Rick Parsons aka “renowden”.

TIT2 [Title/songname/content description] - commonly called Track

On the Sonos this is called “Track” and is available in an index and on the controller screen when the track is playing.

TPE2 [Band/orchestra/accompaniment] - commonly called Album Artist

On the Sonos this is called “Artist” as an index but does not appear on the display at all when a track is playing.

TPE1 [Lead performers(s)/soloist(s)] - commonly called Artist.

On the Sonos this is called “Contributing Artist” as an index. It shown on the display as “Artist” when a track is playing. In theory multiple artists can be put in this field (separated by a “/” but some tag editors show it as a “;”). In practice the Sonos sometimes shows only the last one on the list. I haven’t been able to determine why.

TALB [Album/movie/show title] - commonly called Album

On the Sonos this is used as an index. It also shows on the display when a track is playing.

TRCK [Track number/position in set]

This is not displayed anywhere but is used to determine the track order in albums.

TCOM [Composer(s)]

This is used as an index but does not show on the display during playback.

TCON [Content type] - commonly called Genre.

This is used as an index but does not show on the display during playback.

COMM [Comments] {iTunNORM}

This is written by iTunes and is discussed at length elsewhere. In summary it can, in the right conditions, be used to level the volume of playback.

There is another tag written by Windows media Player which performs a similar function to iTunNORM but I haven’t discovered what it is.