How to optimize Sonos for best performance

Sonos technical support is great and if ever you have an issue, I highly recommend giving them a call. However, here’s what you can do yourself to achieve best performance from your Sonos system.

This is useful if ever one of your Sonos devices struggles to stream content from the Internet or is very laggy to control using the app.

The Sonos system can give you diagnostics via your web browser. To do this, you will need to find the IP address of any one of your Sonos devices (except Sonos Bridges). You can do this by checking your wireless router’s connection table. Once you have found a device IP, you can check diagnostics by visiting this URL in your web browser:

http://<device ip>:1400/support/review

For example:

http://172.20.0.246:1400/support/review

This lists all of your Sonos devices and all of your controller devices. There’s some interesting info under each one but the best view is the “Network Matrix”. Below is a screenshot.

Sonos Local Diagnostics Network Matrix

Sonos Local Diagnostics Network Matrix

There’s a few things to note here:

The Root Bridge

In the left column, one device will say “Root Bridge”. Sonos support inform me that this device is best set as the one which is most central to the premises and is hardwired to the network. This can be any Sonos device, it doesn’t necessarily have to be a Sonos Bridge. To change the Root Bridge, follow these steps:

  1. In your web browser, go to http://<device ip>:1400/advconfig.htm and “disable” the “FirstZP”. <device ip> in this case is the IP address of your current Root Bridge. It doesn’t appear that this page reflects the current state so it’ll likely already have “disabled” selected. Just press the “Submit” button.
  2. In your web browser, go to http://<new device ip>:1400/advconfig.htm and “enable” the “FirstZP”. <new device ip> in this case is the IP address of your desired Root Bridge.
  3. In your web browser, go to http://<new device ip>:1400/reboot to reboot system system. <new device ip> in this case is the IP address of your desired Root Bridge.

The Colours

The colours in the leftmost column indicate the level of noise and interference directly affecting that Sonos device. The colours go Red, Orange, Yellow and Green to signify a scale of really bad to really good respectively. The colours on the main cells of the table indicate which Sonos device is connecting to which other device in order to form the Sonos mesh network. In the screenshot above, you’ll see that Master Bedroom is connecting to Back Bedroom with a very good connection.

You’ll also see that the noise and interference surrounding living room, master bedroom and bathroom is very bad. The most common solution to this, so I’m told, is to change the wifi channel. This assumes you’ve already set the best device as the root bridge.

You can change the wifi channel in the Sonos desktop controller application by going to Manage->Settings->Advanced.

Sonos Controller Application Wifi Channel Selection

Sonos Controller Application Wifi Channel Selection

In my case, changing the channel from 1 to 11 improved things massively:

Sonos Local Diagnostics Network Matrix

Sonos Local Diagnostics Network Matrix

 

Raspberry Pi Project – A 1960s wallbox interfaced with Sonos

The inspiration for this project came from @nivnov pointing me to http://wallbox.weebly.com/. I had somewhat of a different take on the circuitry and software than it’s author, Steve Devlin. The pulse train of my Wallbox was also different. This is all explained below.

The Wallbox

A wallbox is a device dating from circa 1950s USA. It was placed on tables in diners to increase revenue from Jukeboxes. It contains no music, nor does it have a speaker. It could be considered a remote control for the diner’s main Jukebox.

I opted for a Seeburg Wall-O-Matic 100 Type 3W100. Wallboxes will be heavily mechanical with very basic circuitry. They will function such that a key combination will be output as a train of electrical pulses caused by an arm rotating over a set of electrical contacts.

Seeburg Wall-O-Matic 100

Seeburg Wall-O-Matic 100

Powering the Wallbox

The wallbox would have, traditionally, been powered from the jukebox. To use it standalone for this project, an AC-AC transformer was required. My Wallbox required 25VAC at a maximum of 3 amps. I used a Torodial transformer, mounted with its mounting washers, in a die-cast aluminium box. It kicks out a lot of heat so the box acts as a decent enough heatsink.

The wall boxes are traditionally unearthed. This seemed like a bad idea so I attached an earth to it via one of the unit’s screws.

 

Wallbox Transformer

Wallbox Transformer

 

Interfacing with the RasPi

Steve’s circuit is floating and I managed to fairly impressively melt a RasPi by inadvertently forcing 25vAC through it via the gnd. In the end, I opted for a circuit that isolated the Pi from the Wallbox. A diagram is below:

Raspberry Pi Wallbox Interfacing Circuit

Raspberry Pi Wallbox Interfacing Circuit

For the uninitiated, an Opto-isolatorWikipedia: In electronics, an opto-isolator, also called an optocoupler, photocoupler, or optical isolator, is a component that transfers electrical signals between two isolated circuits by using light.[1] Opto-... is an LED and a light activated transistor bundled into a single chip – it’s like a relay. In my case a DIPWikipedia: In microelectronics, a dual in-line package (DIP or DIL[1]), or dual in-line pin package (DIPP)[2] is an electronic component package with a rectangular housing and two parallel rows of electrical con.... The left of the circuit connects to the Wallbox’s 25vAC and Signal terminals; the right connects to the RasPi. I also hooked up 4 LEDs to the Pi to provide some kind of debug output in the event of software errors.

Raspberry Pi Seeburg Wallbox

Raspberry Pi Seeburg Wallbox

Decoding Pulses

As I eluded to above, the key combination is electrically pulsed by a rotating arm. Steve had the good fortune of having an oscilloscope to hand; I sadly didn’t. Rather, I started on the code that would decode the pulses and, initially, used it as a timer. It was clear, after filtering jitter, that the pulse train had a clear time gap in it. In Steve’s case, this gap represented a break between the letters and numbers. In my case, it represented the 20s in a base 20 numbering system.

The pulse train is sequential to represent A1 through to K0. If X represents the number of pulses before the gap and Y represents the number of pulses after the gap, X increments from 1 to 20 whilst Y stays at 1. Y then increments and X resets back to 1. The cycle repeats through to X=20, Y=4 for K0.

The maths was thus:

  • Decrement both the pre and post gap counts as 0 is represented by 1 pulse
  • The letter is (2 * post-gap-count) + (1 if pre-gap-count is > 10)
  • If letter was worked out to be > ‘H’, add 1 as the wallbox doesn’t have an I
  • The number is the pre-gap-count modulus 10 (i.e. pre-gap-count % 10)

Handling kernel level interrupts came with some problems of its own. Most notably, having to think sort-of-thread-safe when writing the code. The interrupt can… well… interrupt code processing at any time. If this is part way through a calculation, things get funky. This code is what I came up with.

Interfacing with Sonos

The Sonos “API” is a UPNP bastardization and is, frankly, horrible. PHP being my strongest language, I thought this the best way to tackle it (hence the C code’s interface with an external programme). I forked a pretty crappy Sonos class on GitHub and set about fixing/improving it. I’ve added multicast Sonos device detection and, most importantly for my requirements, Spotify support. The resulting code is on my GitHub account. Also here’s my usage of the class.

Track Cards

The Wallbox can handle 100 tracks. I had to get these into a parsable list for the Sonos code but also to print up some cards to go in the Jukebox. The Spotify API is also shocking. The best course of action I found was to use the Spotify play button generator to make an HTML page with the playlist data and then parse it with some throw-away code. Here’s the throw-away code. Don’t judge me…

Being a budding designer in my spare time, I knocked up some track card templates in Microsoft Paint. These are below:

Jukebox card template

Jukebox card template

Jukebox card template

Jukebox card template

I then used some more throw-away code to populate these with the track info. That throw-away code is here. Again, don’t judge!

Populated jukebox card

Populated jukebox card

I may have stumbled across a loophole in the StaplesWikipedia: Staples, Inc. is an American multinational office supply retailing corporation, with over 1,500 stores in North America. Headquartered in Framingham, Massachusetts, Staples also does business extensiv... pricing system as they printed these on cards and individually cut them all out for not a lot of money.

The Finished Article

I mounted it on the wall and put the pi, circuitry, transformer, etc. on the other side of the wall to keep things clean. Picture below.

Mounted wall box

Mounted wall box

Here’s a video:

How to detect Sonos devices on your network

How to detect Sonos devices on your network

A potential project requires me to detect Sonos devices on a network and find their IP addresses. Since Sonos only has 2 Mac Address OUIs an ARP scanner seemed the best way to do this. As such, I rightfully reinvented the wheel and wrote a slightly glorified ARP scanner with detection for Sonos OUIs. Sadly, PHP wasn’t quite suitable for this due to it’s lack of AF_PACKET sockets so it’s in C.

It’ll run on Linux and scan a network when given an interface name. Tweaks more than welcome as GitHub Pull Requests.

Code’s on my GitHub at https://github.com/phil-lavin/sonos-detector.