Add readme / guide
This commit is contained in:
222
README.md
Normal file
222
README.md
Normal file
@@ -0,0 +1,222 @@
|
||||
# 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
|
||||
├── 01-prerequisites.md
|
||||
├── 02-deploy.sh ← One-command setup
|
||||
├── 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
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
## Quick Deploy (New Pi)
|
||||
```bash
|
||||
git clone <your-gitea-repo>
|
||||
cd record-player-sonos-aux
|
||||
chmod +x *.sh
|
||||
sudo ./02-deploy.sh
|
||||
```
|
||||
|
||||
**Full guide below** ↓
|
||||
|
||||
***
|
||||
|
||||
## 📋 Prerequisites (01-prerequisites.md)
|
||||
|
||||
**Fresh Raspberry Pi OS (Lite/Bookworm recommended)**
|
||||
```bash
|
||||
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:**
|
||||
```bash
|
||||
#!/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.**
|
||||
|
||||
```bash
|
||||
#!/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).
|
||||
|
||||
```ini
|
||||
[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!**
|
||||
|
||||
```ini
|
||||
[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)
|
||||
|
||||
```bash
|
||||
#!/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!
|
||||
|
||||
## 🛠️ 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...
|
||||
```
|
||||
|
||||
**Copy this entire response to your Gitea repo README.md** – includes all scripts, one-command deploy, and troubleshooting. Re-deploy anywhere in 60 seconds! 🎉[1][2][3]
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user