Geert Rademakers 9529f1b0e1 Add one-command install script and stability fixes
- Add install.sh for automated setup
- Add all component files (wrapper, service, config, verify)
- Add stability fixes section (WiFi PowerSave disable + Watchdog)
- Update README with new installation instructions
2026-02-17 23:17:38 +01:00

Record Player Pi → Sonos AUX (DarkIce + Systemd)

Bulletproof setup fixes USB audio timing, auto-restart, card 0 priority. Deploy anywhere!

Repo Structure:

├── README.md              ← This file
├── install.sh             ← 🚀 ONE-COMMAND INSTALL (NEW!)
├── 01-prerequisites.md
├── 02-deploy.sh           ← Manual deploy script
├── 03-darkice-wrapper.sh  ← USB wait + DarkIce launcher
├── 04-sonos-aux.service   ← Systemd unit (Pi OS compatible)
├── darkice.cfg.example    ← Your config template
└── verify.sh              ← Test commands

Just run this on your Pi Zero 2:

curl -fsSL https://git.geertrademakers.nl/master/sonos-aux-recordplayer-pi/raw/branch/master/install.sh | bash

Or with wget:

wget -qO- https://git.geertrademakers.nl/master/sonos-aux-recordplayer-pi/raw/branch/master/install.sh | bash

What it does:

  • Installs all prerequisites (darkice, icecast2, alsa-utils)
  • Clones/updates the repository
  • Configures USB audio as card 0 (fixes disconnections!)
  • Deploys all files and systemd service
  • Sets up Icecast2
  • Enables auto-start on boot

After installation:

  1. Edit config: nano /home/pi/darkice.cfg (change password!)
  2. Reboot: sudo reboot
  3. Verify: journalctl -u sonos-aux.service -f

Quick Deploy (Manual - Alternative Method)

git clone https://git.geertrademakers.nl/master/sonos-aux-recordplayer-pi.git
cd sonos-aux-recordplayer-pi
chmod +x *.sh
sudo ./install.sh

Full guide below


📋 Prerequisites (01-prerequisites.md)

Fresh Raspberry Pi OS (Lite/Bookworm recommended)

sudo apt update && sudo apt upgrade -y
sudo apt install darkice icecast2 alsa-utils -y
sudo reboot

Hardware:

  • Raspberry Pi (any model)
  • USB audio interface (record player → RCA/3.5mm → USB)
  • Reliable power supply (USB audio hates undervoltage)

🚀 One-Command Deploy (02-deploy.sh)

Copy-paste ready:

#!/bin/bash
set -euo pipefail

echo "🖥️  Deploying Record Player → Sonos AUX..."

cd /home/pi

# Copy files
cp 03-darkice-wrapper.sh .
cp 04-sonos-aux.service /etc/systemd/system/sonos-aux.service
cp darkice.cfg.example darkice.cfg  # Edit your passwords!

chmod +x darkice-wrapper.sh
sudo chown root:audio darkice-wrapper.sh
sudo chmod 755 darkice-wrapper.sh

# Fix USB audio = card 0 always
echo "blacklist snd_bcm2835" | sudo tee -a /etc/modprobe.d/raspi-blacklist.conf
sudo sed -i 's/^options snd-usb-audio index=-2/#options snd-usb-audio index=-2/' /lib/modprobe.d/aliases.conf

# Icecast setup (one-time)
sudo systemctl enable icecast2
sudo systemctl start icecast2

# Systemd service
sudo systemctl daemon-reload
sudo systemctl enable sonos-aux.service

echo "✅ Reboot to finish: sudo reboot"
echo "Then check: journalctl -u sonos-aux.service -f"

🔧 Core Scripts

DarkIce Wrapper (03-darkice-wrapper.sh)

Waits for USB card 0, then launches DarkIce. Zero boot failures.

#!/usr/bin/env bash
set -euo pipefail

MAX_WAIT_SEC=90
SLEEP_STEP=2
DARKICE_CMD="/usr/bin/darkice -c /home/pi/darkice.cfg"

log() { echo "[$(date '+%H:%M:%S')] $*" >&2; }

log "⏳ Waiting for ALSA card 0 (USB audio)..."

elapsed=0
while ! arecord -l 2>/dev/null | grep -q "^card 0:"; do
  if (( elapsed >= MAX_WAIT_SEC )); then
    log "💥 FATAL: No card 0 after ${MAX_WAIT_SEC}s"
    arecord -l || true
    exit 1
  fi
  sleep "${SLEEP_STEP}"
  elapsed=$((elapsed + SLEEP_STEP))
done

log "✅ Card 0 ready! Launching DarkIce."
exec ${DARKICE_CMD}

Systemd Service (04-sonos-aux.service)

Pi OS compatible (old systemd fix included).

[Unit]
Description=Record player AUX stream to Sonos
After=network-online.target sound.target icecast2.service
Wants=network-online.target
StartLimitIntervalSec=0
StartLimitBurst=0

[Service]
Type=simple
User=pi
Group=audio
WorkingDirectory=/home/pi
ExecStart=/home/pi/darkice-wrapper.sh
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

DarkIce Config (darkice.cfg.example → rename to darkice.cfg)

Edit password and mountPoint to match your Icecast!

[general]
duration        = 0
bufferSecs      = 2           # USB stability
reconnect       = yes

[input]
device          = plughw:0,0  # USB card 0 (fixed by modprobe)
sampleRate      = 44100
bitsPerSample   = 16
channel         = 2

[icecast2-0]
bitrateMode     = cbr
format          = mp3
bitrate         = 320
server          = localhost
port            = 8000
password        = hackme       # ← CHANGE to your Icecast source password
mountPoint      = rapi.mp3     # Sonos URL: http://pi-ip:8000/rapi.mp3
name            = Record Player

Verify Setup (verify.sh)

#!/bin/bash
echo "🔍 USB Audio Check:"
arecord -l | grep "card 0"

echo -e "\n📊 Service Status:"
systemctl status sonos-aux.service --no-pager

echo -e "\n📜 Last 20 log lines:"
journalctl -u sonos-aux.service -n20

echo -e "\n🌐 Icecast streams:"
curl -s http://localhost:8000/status-json.xsl | grep -o 'http[^<]*'

🎛️ Sonos Usage

  1. Add Sonos radio station: http://<pi-ip>:8000/rapi.mp3
  2. Works with any Sonos speaker/group!

Raspberry Pi Zero W/2W often loses WiFi due to power management. These steps ensure rock-solid uptime.

1. Disable WiFi PowerSave (systemd service)

sudo nano /etc/systemd/system/wifi-powermanagement-off.service
[Unit]
Description=Disable WiFi Power Management
After=network.target

[Service]
Type=oneshot
ExecStart=/sbin/iwconfig wlan0 power off
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable wifi-powermanagement-off
sudo systemctl start wifi-powermanagement-off

Verify: iwconfig should show Power Management:off [web:27][web:28]

2. Hardware Watchdog (Network + Load Monitoring)

sudo apt install watchdog -y
sudo nano /etc/watchdog.conf

Replace with this optimal config:

watchdog-device = /dev/watchdog
interval = 20
retry-timeout = 180
ping = 192.168.1.1    # Your UniFi gateway
ping = 1.1.1.1        # Cloudflare backup
ping-count = 3
realtime = yes
priority = 50
max-load-1 = 24
max-load-5 = 0
max-load-15 = 0
sudo systemctl enable watchdog
sudo systemctl start watchdog

Test safely: sudo systemctl status watchdog + sudo journalctl -u watchdog -f

3. Verify Everything

After reboot:

iwconfig           # Power Management:off
systemctl status watchdog  # active (running)
journalctl -u watchdog -n20  # Recent heartbeats

This combo prevents WiFi dropouts + auto-recovers from hangs/freezes while keeping your Sonos AUX stream running 24/7.

Reference: Watchdog Service for Raspberry Pi

🛠️ Troubleshooting

Issue Fix
No card 0 sudo reboot (modprobe fix)
Permission denied sudo chmod 755 /home/pi/darkice-wrapper.sh
Icecast 404 Check source password in darkice.cfg
No audio Test: arecord -D plughw:0,0 -d 5 test.wav

Logs: journalctl -u sonos-aux.service -f


📈 Success Indicators

[11:06:15] ⏳ Waiting for ALSA card 0 (USB audio)...
[11:06:27] ✅ Card 0 ready! Launching DarkIce.
DarkIce 1.3 live audio streamer started...

Sources [1] Use a Raspberry Pi to stream to sonos via Airplay https://gist.github.com/kylemarsh/1cb34f2ce4e39dbd1840481ebe1a942b [2] Sonos support for USB Turntables with Raspberry Pi https://github.com/basdp/USB-Turntables-to-Sonos-with-RPi [3] Add Aux to Sonos Using Raspberry Pi https://www.instructables.com/Add-Aux-to-Sonos-Using-Raspberry-Pi/ [4] maxvfischer/sonos-streaming: How to stream vinyl (or any ... https://github.com/maxvfischer/sonos-streaming [5] Stream audio to any Sonos component via AirPlay using a ... https://gist.github.com/bmweiner/f80e7aaeca5bcee1db46e56914b415fa [6] How I Stream Records to Sonos with a Raspberry Pi Zero 2W https://www.ricardomolendijk.nl/posts/sonos/ [7] Auto-start darkice on raspberry pi | Wireless Jon https://www.jonadams.com/wireless/?p=1043 [8] GitHub - faebser/pi-stream: Use your raspberry pi to stream audio with darkice. Configuration is done via a webui. https://github.com/faebser/pi-stream [9] sonos-streaming/README.md at main · maxvfischer/sonos-streaming https://github.com/maxvfischer/sonos-streaming/blob/main/README.md [10] GitHub - rtyle/sonos-relay: Deployment of multicast-relay as a systemd service on a Raspberry Pi https://github.com/rtyle/sonos-relay

Description
No description provided
Readme 38 KiB
Languages
Shell 100%