linux  RPi

Internet-Radio & 🔵🦷-Box

RPi + Altes Radio = Internet Radio (mit Bewegungsmelder) und Bluetooth-Box

Module Installieren

sudo apt install mpd mpc alsa-utils bluez-tools bluez-alsa-utils

Default Sound-Karte

sudo tee /etc/asound.conf >/dev/null <<'EOF'
pcm.!default {
  type asym
  playback.pcm {
    type plug
    slave.pcm "output"
  }
  capture.pcm {
    type plug
    slave.pcm "input"
  }
}

pcm.output {
  type hw
  card 1
}

ctl.!default {
  type hw
  card 1
}
EOF

Berechtigungen

sudo chmod -R 775 /var/lib/mpd/playlists
sudo chown -R root:staff /usr/local
sudo chmod -R 775 /usr/local

sudo nano /etc/group
sudo usermod -aG audio mani
sudo usermod -aG gpio mani
sudo usermod -aG staff mani
sudo usermod -aG audio www-data
sudo usermod -aG gpio www-data
#reboot!

lighttpd & https

Python-Script + Webseite installieren

mnt-bb8
# m~radio.de nach /var/www/html kopieren
# python-scripte nach /usr/local/bin/ kopieren
umntt

Radio - Audioausgabe

sudo nano /etc/mpd.conf
#strg+w: output
    audio_output {
            type            "alsa"
            name            "My ALSA Device"
    ##      device          "hw:1,0"        # optional <- muss das noch?
            mixer_type      "software"      # optional
    ##      mixer_type      "hardware"      # optional
    ##      mixer_device    "default"       # optional
    ##      mixer_control   "PCM"           # optional
    ##      mixer_index     "0"             # optional
    }

sudo systemctl enable mpd.service
sudo systemctl start mpd.service
sudo systemctl status mpd.service

 Radio - Test

tee /var/lib/mpd/playlists/radio.m3u >/dev/null <<'EOF'
http://mp3channels.webradio.antenne.de:80/antenne
EOF
mpc load radio
mpc play

Radio - Dienst

sudo tee /etc/systemd/system/radio.service >/dev/null <<'EOF'
[Unit]
Description=radio
After=syslog.target
After=network.target

[Service]
User=www-data
Restart=always
WorkingDirectory=/tmp
ExecStart=python /usr/local/bin/Radio.py
EOF

[Install]
WantedBy=multi-user.target

sudo chmod 755 /etc/systemd/system/radio.service

sudo systemctl enable radio.service
sudo systemctl start radio.service
sudo systemctl status radio.service

Radio - Troubleshooting

GPIO.add_event_detect(motionDetector, GPIO.RISING, callback=motionDetected) 
   RuntimeError: Failed to add edge detection

sudo apt remove python3-rpi.gpio
sudo apt install python3-rpi-lgpio

Sound Änderungen müssen auf korrekter Soundkarte ausgeführt werden

Ist aber ggf. Hinfällig mit dem globalen setzen der Soundkarte.

cat /proc/asound/cards 

amixer -c 1 sset PCM 10%

Grundlautstärke regeln

alsamixer

Bluetooth - Settings

sudo tee /etc/bluetooth/main.conf >/dev/null <<'EOF'
[General]
Class = 0x200414
DiscoverableTimeout = 0

[Policy]
AutoEnable=true
EOF

Bluetooth - Dienst

sudo tee /etc/systemd/system/bt-box-agent.service >/dev/null <<'EOF'
[Unit]
Description=Bluetooth Agent
Requires=bluetooth.service
After=bluetooth.service

[Service]
ExecStartPre=/usr/bin/bluetoothctl discoverable on
ExecStartPre=/bin/hciconfig %I piscan
ExecStartPre=/bin/hciconfig %I sspmode 1
ExecStart=/usr/bin/bt-agent --capability=NoInputNoOutput
RestartSec=5
Restart=always
KillSignal=SIGUSR1

[Install]
WantedBy=multi-user.target
EOF

sudo chmod 755 /etc/systemd/system/bt-box-agent.service

sudo systemctl enable bt-box-agent.service
sudo systemctl start bt-box-agent.service
sudo systemctl status bt-box-agent.service

mpc Befehle

mpc clear
mpc load 
mpc play
mpc play 
mpc volume 80
mpc next
mpc prev
mpc current
mpc pause
mpc stop
mpc toggle

amixer notes

cat /proc/asound/cards 

amixer scontrols

amixer sset PCM 100%
amixer sset PCM 40%

# increase by 3%
amixer -q sset PCM 3%+

# decrease by 3%
amixer -q sset PCM 3%-

# mute/unmute
amixer -q sset PCM toggle

Linksammlung

https://www.blog.berrybase.de/blog/2020/10/12/bau-dir-deinen-eigenen-bluetooth-lautsprecher-mit-dem-raspberry-pi/
https://github.com/nicokaiser/rpi-audio-receiver.git