update script, daemon, services, added sound, small improvements

This commit is contained in:
Lurkars 2022-02-08 20:09:26 +01:00
parent 5fdc7d636b
commit c769724146
14 changed files with 671 additions and 433 deletions

406
README.md
View File

@ -1,29 +1,30 @@
# luniebox # luniebox
lunibox is a RFID jukebox based on a Raspberry Pi. It is similar to the [Phoniebox](https://www.phoniebox.de) \[[https://github.com/MiczFlor/RPi-Jukebox-RFID](GitHub)\] and an upgrade of the [TonUINO (de)](https://www.voss.earth/tonuino/) which both are DIY versions of the popular Toniebox©. The main focus for now is to play Spotify© content and playing local files (also supports Spotify© download for offline use). Other sources will be integrated later. lunibox is a RFID jukebox based on a Raspberry Pi. It is similar to the [Phoniebox](https://www.phoniebox.de) \[[GitHub](https://github.com/MiczFlor/RPi-Jukebox-RFID)\] and an upgrade of the [TonUINO (de)](https://www.voss.earth/tonuino/) which both are DIY versions of the popular Toniebox©. The main focus for now is to play Spotify© content and playing local files (also supports Spotify© download for offline use). Other sources will be integrated later.
## Prerequisites ## Prerequisites
You need to be familiar with ssh (Putty on Windows). For the usage of Spotify© a premium account is required. You need to be familiar with ssh (Putty on Windows). For the usage of Spotify© a premium account is required.
### Hardware ### Hardware
- Raspberry Pi (tested with Raspberry Pi 3 Model B, Zero W, Zero 2 W) \[starting at ~14€\] - Raspberry Pi (tested with Raspberry Pi 3 Model B, Zero 2 W) \[starting at ~14€\]
- power supply (5V ~2.5A) \[starting at ~6€\] - power supply (5V ~2.5A) \[starting at ~6€\]
- Micro SD card (at least 4GB) \[starting at ~4€\] - Micro SD card (at least 4GB) \[starting at ~4€\]
- RC522 RFID Reader connected to [TODO] \[starting at ~1.50€\] - RC522 RFID Reader \[starting at ~1.50€\]
- RFID (MiFare) cards or chips \[starting at ~2€\] - RFID (MiFare) cards or chips \[starting at ~2€\]
- a Audio Card: - a Audio Card:
- Pimoroni Audio Amp SHIM (3W Mono Amp) \[starting at ~11€\] with passive speaker \[starting at ~5€\] - Pimoroni Audio Amp SHIM (3W Mono Amp) \[starting at ~11€\] with passive speaker \[starting at ~5€\]
- Pimoroni Audio DAC SHIM \[starting at ~14€\] with active speaker - Pimoroni Audio DAC SHIM \[starting at ~14€\] with active speaker
- Adafruit Speaker Bonnet for Raspberry Pi - Adafruit Speaker Bonnet for Raspberry Pi
- ...something else (use custom setup!) - ...something else (use custom setup!)
- (optional) MPU9250 9-axis sensor [TODO] \[starting at ~1.50€\] - (optional) 2x Push Buttons for volume control \[starting at ~1€\]
- (optional) MPU9250 9-axis sensor \[starting at ~1.50€\]
- (optional) Waveshare UPS HAT + 2x 18650 18650 Li battery \[starting at ~30€\] - (optional) Waveshare UPS HAT + 2x 18650 18650 Li battery \[starting at ~30€\]
- some wires or dupont connectors \[starting at ~2€\] - some wires or dupont connectors \[starting at ~2€\]
- case for all above - case for all above
- depending on hardware: soldering equipment - depending on hardware: soldering equipment
A minimal setup (Raspberry Zero 2 W, power supply, Micro SD, RC522, Cards, Audio Amp) should be about ~40€ plus case materials. A minimal setup (Raspberry Zero 2 W, power supply, Micro SD, RC522, Cards, Audio Amp, Speaker, Buttons) should be about ~45€ plus case materials.
### Software ### Software
- latest Raspberry Pi OS blank installation on Micro SD card (Instructions: [raspberrypi.com/software/](https://www.raspberrypi.com/software/)) - latest Raspberry Pi OS blank installation on Micro SD card (Instructions: [raspberrypi.com/software/](https://www.raspberrypi.com/software/))
@ -36,206 +37,275 @@ If you're using a Raspberry Pi Zero or have missing peripherals to setup WiFi an
- insert Micro SD card with Raspberry Pi OS into a computer - insert Micro SD card with Raspberry Pi OS into a computer
- place an empty file called `ssh` into `/boot` folder/partioon - place an empty file called `ssh` into `/boot` folder/partioon
- place a filed called `wpa_supplicant.conf` into `/boot` folder/partition with following content - place a filed called `wpa_supplicant.conf` into `/boot` folder/partition with following content
``` > ```
country=$COUNTRY_CODE > country=$COUNTRY_CODE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev > ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1 > update_config=1
>
network={ > network={
ssid="$WIFI_SSID" > ssid="$WIFI_SSID"
psk="$WIFI_PASSWORD" > psk="$WIFI_PASSWORD"
} > }
``` > ```
- replace `$COUNTRY_CODE` with upper-case country code (eg. GB or DE) and `$WIFI_SSID` and `$WIFI_PASSWORD` with your WiFi credentials - replace `$COUNTRY_CODE` with upper-case country code (eg. GB or DE) and `$WIFI_SSID` and `$WIFI_PASSWORD` with your WiFi credentials
- plug card back into your Pi and connect power supply - plug card back into your Pi and connect power supply
## Setup ## Setup
Establish a ssh connection to your Pi: Open terminal on your pi or establish a ssh connection to your Pi:
- the Pi should be reachable under `raspberrypi` or `raspberrypi.local` in your network, if not try to find out it's IP address from your router. - the Pi should be reachable under `raspberrypi` or `raspberrypi.local` in your network, if not try to find out it's IP address from your router.
- default username is `pi` and default password is `raspberry` - default username is `pi` and default password is `raspberry`
- Example: `ssh pi@raspberrypi.local` or `ssh pi@192.168.2.100` - Example: `ssh pi@raspberrypi.local` or `ssh pi@192.168.2.100`
> ⚠️ Warning: you should change the default password by executing `passwd` after login
> **⚠️ Warning: you should change the default password by executing `passwd` after login**
### Automatic setup ### Automatic setup
> ⚠️ Warning: executing scripts from the internet without checking is bad. This is only done to get things done fast. In any doubts you can perform the [Manual setup](#manual-setup) and execute all commands step-by-step to understand what's going on. > **⚠️ Warning: executing scripts from the internet without checking is bad. This is only done to get things done fast. In any doubts you can perform the [Manual setup](#manual-setup) and execute all commands step-by-step to understand what's going on.**
- download and excecute setup script (you will be prompted to confirm certain steps beforehand anyway) - download and excecute setup script (you will be prompted to confirm certain steps beforehand anyway)
> `curl https://git.bstly.de/Lurkars/luniebox/raw/branch/main/luniebox.sh -o luniebox.sh`
> ```
> `chmod +x luniebox.sh` bash <(curl -s https://git.bstly.de/Lurkars/luniebox/raw/branch/main/luniebox.sh)
> ```
> `./luniebox.sh`
- Alternative first download script, take a look and then execute
```
curl https://git.bstly.de/Lurkars/luniebox/raw/branch/main/luniebox.sh -o luniebox.sh
chmod +x luniebox.sh
./luniebox.sh
```
### Manual setup ### Manual setup
#### Software setup #### Software setup
go to home directory - go to home directory
> `cd /home/pi`
install `git`, `python3-venv` and `python3-pip` ```
> `sudo apt install -y git python3-venv python3-pip` cd /home/pi
```
clone repository `https://git.bstly.de/Lurkars/luniebox.git` with sources and config: - install `git`, `python3-venv` and `python3-pip`
> `git clone https://git.bstly.de/Lurkars/luniebox.git luniebox`
setup application ```
> `cd /home/pi/luniebox/application` sudo apt install -y git python3-venv python3-pip
> ```
> `python -m venv venv`
>
> `source venv/bin/activate`
>
> `export CFLAGS=-fcommon`
>
> `pip install -r requirements.txt`
>
> `deactivate`
>
> `mkdir /home/pi/luniebox/config`
>
> `cp /home/pi/luniebox/contrib/config/luniebox.cfg /home/pi/luniebox/config/luniebox.cfg`
>
> `sudo cp /home/pi/luniebox/contrib/service/luniebox-app.service /etc/systemd/system/`
>
> `sudo cp /home/pi/luniebox/contrib/service/luniebox-daemon.service /etc/systemd/system/`
>
> `sudo systemctl daemon-reload`
>
> `sudo systemctl enable luniebox-app luniebox-daemon`
- clone repository `https://git.bstly.de/Lurkars/luniebox.git` with sources and config:
setup spotifyd ```
> `mkdir /home/pi/luniebox/bin` git clone https://git.bstly.de/Lurkars/luniebox.git luniebox
> ```
> `wget -c https://github.com/Spotifyd/spotifyd/releases/download/v0.3.3/spotifyd-linux-armv6-slim.tar.gz -O - | tar -xz -C /home/pi/luniebox/bin`
>
> `cp /home/pi/luniebox/contrib/config/spotifyd.cfg /home/pi/luniebox/config/spotifyd.cfg` (if you use other audio hardware, you may need to adjust the `backend` and `device` properties to your needs!)
>
> `sudo cp /home/pi/luniebox/contrib/service/spotifyd.service /etc/systemd/system/`
>
> `sudo systemctl daemon-reload`
>
> `sudo systemctl enable spotifyd`
setup mpd ##### Setup luniebox application and daemon
> `mkdir /home/pi/luniebox/library` - setup application by building python venv and setup systemd service
>
> `sudo apt install -y mpd`
>
> `sudo cp /home/pi/luniebox/contrib/config/mpd.conf /etc/mpd.conf` (if you use other audio hardware, you may need to adjust the `audio_output` section to your needs!)
>
setup ClSpotify ```
> `git clone https://github.com/agent255/clspotify.git /home/pi/clspotify` cd /home/pi/luniebox/application
>
> `cd /home/pi/clspotify`
>
> `python -m venv venv`
>
> `source venv/bin/activate`
>
> `pip install -r requirements.txt`
>
> `deactivate`
>
> `sed -i "s/^zspotify_path =.*$/zspotify_path = \/home\/pi\/clspotify\//" /home/pi/luniebox/config/luniebox.cfg`
start/restart all services python -m venv venv
> `sudo systemctl restart mpd spotifyd luniebox-daemon luniebox-app`
source venv/bin/activate
export CFLAGS=-fcommon
pip install -r requirements.txt
deactivate
mkdir /home/pi/luniebox/config
cp /home/pi/luniebox/contrib/config/luniebox.cfg /home/pi/luniebox/config/luniebox.cfg
sudo cp /home/pi/luniebox/contrib/service/luniebox-app.service /etc/systemd/system/
sudo cp /home/pi/luniebox/contrib/service/luniebox-daemon.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable luniebox-app luniebox-daemon
```
##### Setup spotify
For Spotify support, spofiyd is required.
- get spotifyd binary and setup systemd service
```
mkdir /home/pi/luniebox/bin`
wget -c https://github.com/Spotifyd/spotifyd/releases/download/v0.3.3/spotifyd-linux-armv6-slim.tar.gz -O - | tar -xz -C /home/pi/luniebox/bin
cp /home/pi/luniebox/contrib/config/spotifyd.cfg /home/pi/luniebox/config/spotifyd.cfg
sudo cp /home/pi/luniebox/contrib/service/spotifyd.service /etc/systemd/system/`
sudo systemctl daemon-reload`
sudo systemctl enable spotifyd
```
> If you use other audio hardware, you may need to adjust the `backend` and `device` property in `/home/pi/luniebox/config/spotifyd.cfg` to your needs!
##### Setup Music Player Daemon
for offline file support setup [Music Player Daemon](https://www.musicpd.org/) (mpd)
- create library folder and install `mpd`
```
mkdir /home/pi/luniebox/library
sudo apt install -y mpd
sudo cp /home/pi/luniebox/contrib/config/mpd.conf /etc/mpd.conf
```
> If you use other audio hardware, you may need to adjust the `audio_output` in `/etc/mpc.conf` section to your needs!
##### Setup ClSpotify
for Spotify offline support setup [ClSpotify](https://github.com/agent255/clspotify.git) (requires [spotify](#setup-spotify) and [mpd](#setup-music-player-daemon)!).
- get code, install pythen venv and update config
```
git clone https://github.com/agent255/clspotify.git /home/pi/clspotify
cd /home/pi/clspotify
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
deactivate
sed -i "s/^zspotify_path =.*$/zspotify_path = \/home\/pi\/clspotify\//" /home/pi/luniebox/config/luniebox.cfg
```
#### Hardware Setup #### Hardware Setup
##### enable SPI for RFID Reader For a detailed Raspberry Pi pinout take a look at [https://pinout.xyz](https://pinout.xyz).
uncomment `dtparam=spi=on` in `/boot/config.txt` ##### Setup RC522 RFID Reader
> `sudo sed -i "/dtparam=spi=on/s/^#//g" /boot/config.txt`
##### enable I2C for MPU9250 9-axis sensor - uncomment `dtparam=spi=on` in `/boot/config.txt` tp enable SPI for RC522
install `i2c-tools` and `python3-smbus` ```
> `sudo apt install -y i2c-tools python3-smbus` sudo sed -i "/dtparam=spi=on/s/^#//g" /boot/config.txt
```
uncomment `dtparam=i2c_arm=on` in `/boot/config.txt` - connect RC522
> `sudo sed -i "/dtparam=i2c_arm=on/s/^#//g" /boot/config.txt` - SDA to Pin 24 \[GPIO 8 / SPI0 CE0\]
- SCK to Pin 23 \[GPIO 11 / SPI0 SCLK / CLK\]
- MOSI to Pin 19 \[GPIO 10 / SPI0 MOSI\]
- MISO to Pin 21 \[GPIO 9 / SPI0 MISO\]
- GND to Pin 20 \[Ground\]
- RST to Pin 22 \[GPIO 25\]
- 3.3v to Pin 1 \[3v3 Power\]
##### Setup Pimoroni Amp or DAC
- disable onboard audio comment out `dtparam=audio=on` in `/boot/config.txt`
```
sudo sed -i "/dtparam=audio=on/s/^/#/g" /boot/config.txt
```
- setup hifiberry-dac by adding following content to `/boot/config.txt`
> ```
> # setup hifiberry for Pimoroni Shim
> dtoverlay=hifiberry-dac
> gpio=25=op,dh
> ```
```
printf "\n# setup hifiberry for Pimoroni Shim\ndtoverlay=hifiberry-dac\ngpio=25=op,dh\n" | sudo tee -a /boot/config.txt
```
##### Setup Adafruit Speaker Bonnet for Raspberry Pi
- disable onboard audio comment out `dtparam=audio=on` in `/boot/config.txt`
```
sudo sed -i "/dtparam=audio=on/s/^/#/g" /boot/config.txt
```
- setup hifiberry-dac and i2s by adding following content to `/boot/config.txt`
> ```
> # setup hifiberry and i2s for Adafruit Speaker Bonnet
> dtoverlay=hifiberry-dac
> dtoverlay=i2s-mmap
> ```
```
printf "\n# setup hifiberry and i2s for Adafruit Speaker Bonnet\ndtoverlay=hifiberry-dac\ndtoverlay=i2s-mmap\n" | sudo tee -a /boot/config.txt
```
- copy [contrib/config/asound.conf](contrib/config/asound.conf) to `/etc/asound.conf`.
```
cat /home/pi/luniebox/contrib/config/asound.conf | sudo tee /etc/asound.conf
```
- copy [contrib/config/.asoundrc](contrib/config/.asoundrc) to `/home/pi/.asoundrc`.
```
cat /home/pi/luniebox/contrib/config/.asoundrc | tee /home/pi/.asoundrc
```
##### Setup Push Buttons
- connect first push button (volume down)
1. Pin 8 \[GPIO 14\]
2. Pin 6 \[Ground\]
- connect second push button (volume up)
1. Pin 7 \[GPIO 4\]
2. Pin 9 \[Ground\]
##### Setup MPU9250 9-axis sensor
- install `i2c-tools` and `python3-smbus`
```
sudo apt install -y i2c-tools python3-smbus
```
- uncomment `dtparam=i2c_arm=on` in `/boot/config.txt` to enable I2C for MPU9250
```
sudo sed -i "/dtparam=i2c_arm=on/s/^#//g" /boot/config.txt
```
- setup i2c bus 4 for MPU9250 by adding following content to `/boot/config.txt`
> ```
> # setup ic2 bus 4 for mpu
> dtoverlay=i2c-gpio,bus=4,i2c_gpio_delay_us=1,i2c_gpio_sda=23,i2c_gpio_scl=24
> ```
```
printf "\n# setup i2c bus 4 for mpu\ndtoverlay=i2c-gpio,bus=4,i2c_gpio_delay_us=1,i2c_gpio_sda=23,i2c_gpio_scl=24\n" | sudo tee -a /boot/config.txt
```
- connect MPU9250
- SDA to Pin 16 \[GPIO 23\]
- SCL to Pin 18 \[GPIO 24\]
- GND to Pin 14 \[Ground\]
- 3V3 to Pin 17 \[3v3 Power\]
add `dtoverlay=i2c-gpio,bus=4,i2c_gpio_delay_us=1,i2c_gpio_sda=23,i2c_gpio_scl=24` to `/boot/config.txt` #### Finish Setup
> `printf "dtoverlay=i2c-gpio,bus=4,i2c_gpio_delay_us=1,i2c_gpio_sda=23,i2c_gpio_scl=24" | sudo tee -a /boot/config.txt` - After setup, reboot system.
#### Setup Audio ```
sudo reboot
##### for Pimoroni Amp or DAC ```
disable onboard audio comment out `dtparam=audio=on` in `/boot/config.txt`
> `sudo sed -i "/dtparam=audio=on/s/^/#/g" /boot/config.txt`
setup hifiberry-dac by adding
```
dtoverlay=hifiberry-dac
gpio=25=op,dh
```
to `/boot/config.txt`
> `printf "dtoverlay=hifiberry-dac\ngpio=25=op,dh" | sudo tee -a /boot/config.txt`
##### for Adafruit Speaker Bonnet for Raspberry Pi
disable onboard audio comment out `dtparam=audio=on` in `/boot/config.txt`
> `sudo sed -i "/dtparam=audio=on/s/^/#/g" /boot/config.txt`
setup hifiberry-dac and i2s by adding
```
dtoverlay=hifiberry-dac
dtoverlay=i2s-mmap
```
to `/boot/config.txt`
> `printf "dtoverlay=hifiberry-dac\ndtoverlay=i2s-mmap" | sudo tee -a /boot/config.txt`
create `/etc/asound.conf` file with following content:
```
pcm.speakerbonnet {
type hw card 0
}
pcm.dmixer {
type dmix
ipc_key 1024
ipc_perm 0666
slave {
pcm "speakerbonnet"
period_time 0
period_size 1024
buffer_size 8192
rate 44100
channels 2
}
}
ctl.dmixer {
type hw card 0
}
pcm.softvol {
type softvol
slave.pcm "dmixer"
control.name "PCM"
control.card 0
}
ctl.softvol {
type hw card 0
}
pcm.!default {
type plug
slave.pcm "softvol"
}
```
After setup, reboot system.
> `sudo reboot`
## Planned features ## Planned features

View File

@ -10,18 +10,6 @@ app = Flask(__name__)
app.register_blueprint(api, url_prefix='/api') app.register_blueprint(api, url_prefix='/api')
app.register_blueprint(pages) app.register_blueprint(pages)
loglevel = 'INFO'
if luniebox.get_setting('logging', 'level'):
loglevel = luniebox.get_setting('logging', 'level')
logger = logging.getLogger('luniebox')
logger.setLevel(logging._nameToLevel[loglevel])
logFormatter = logging.Formatter(
style='{', datefmt='%Y-%m-%d %H:%M:%S', fmt='{asctime} {levelname}: {message}')
logstdoutHandler = logging.StreamHandler(sys.stdout)
logstdoutHandler.setFormatter(logFormatter)
logger.addHandler(logstdoutHandler)
if __name__ != '__main__': if __name__ != '__main__':
gunicorn_logger = logging.getLogger('gunicorn.error') gunicorn_logger = logging.getLogger('gunicorn.error')
app.logger.handlers = gunicorn_logger.handlers app.logger.handlers = gunicorn_logger.handlers

View File

@ -3,6 +3,7 @@
import signal import signal
import time import time
import sys import sys
import subprocess
import logging import logging
from luniebox import luniebox from luniebox import luniebox
import RPi.GPIO as GPIO import RPi.GPIO as GPIO
@ -26,8 +27,10 @@ class LunieboxDaemon(object):
self.tolerance = self.luniebox.get_setting( self.tolerance = self.luniebox.get_setting(
'rfid', 'pause_tolerance', 4) 'rfid', 'pause_tolerance', 4)
self.reads = 0 self.reads = 0
self.error_text = False
if self.luniebox.get_setting('hardware', 'mpu') == 'True': if self.luniebox.get_setting('hardware', 'mpu') == 'True':
try:
self.mpu = MPU9250( self.mpu = MPU9250(
address_ak=AK8963_ADDRESS, address_ak=AK8963_ADDRESS,
address_mpu_master=MPU9050_ADDRESS_68, address_mpu_master=MPU9050_ADDRESS_68,
@ -38,11 +41,15 @@ class LunieboxDaemon(object):
mfs=AK8963_BIT_16, mfs=AK8963_BIT_16,
mode=AK8963_MODE_C100HZ) mode=AK8963_MODE_C100HZ)
self.mpu.configure() self.mpu.configure()
except Exception as exception:
logging.getLogger('luniebox').warning(
"Could not setup MPU9250: " + str(exception))
self.mpu = False
else: else:
self.mpu = False self.mpu = False
def run(self): def run(self):
logging.getLogger('luniebox').info("run luniebox") logging.getLogger('luniebox').info("run luniebox daemon")
while True: while True:
# mpu # mpu
@ -86,10 +93,14 @@ class LunieboxDaemon(object):
if self.reads >= self.tolerance: if self.reads >= self.tolerance:
self.reads = 0 self.reads = 0
self.luniebox.pause() self.luniebox.pause()
self.error_text = False
time.sleep(0.1) time.sleep(0.1)
else: else:
self.reads = 0 self.reads = 0
self.luniebox.play(text) if text != self.error_text and not self.luniebox.play(text):
if self.luniebox.get_setting('luniebox', 'error_sound') != 'False':
self.error_text = text
self.error_sound()
time.sleep(0.1) time.sleep(0.1)
def signal_handler(self, signal, frame): def signal_handler(self, signal, frame):
@ -98,6 +109,21 @@ class LunieboxDaemon(object):
luniebox.stop() luniebox.stop()
sys.exit(0) sys.exit(0)
def beep_sound(self):
self.play_sound("/home/pi/luniebox/audio/beep.wav",
str(self.luniebox.volume))
def error_sound(self):
self.play_sound("/home/pi/luniebox/audio/error.wav", "100")
def play_sound(self, path, volume):
volume_p = subprocess.Popen(
["amixer", "set", "PCM", volume + "%"], stdin=None,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, close_fds=True, shell=False, group="pi", user="pi")
volume_p.wait()
subprocess.Popen(["aplay", path], stdin=None,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, close_fds=True, shell=False, group="pi", user="pi")
if __name__ == "__main__": if __name__ == "__main__":
daemon = LunieboxDaemon(luniebox=luniebox) daemon = LunieboxDaemon(luniebox=luniebox)

View File

@ -168,9 +168,9 @@ class Luniebox(object):
self.zspotify_path, username, password, root) self.zspotify_path, username, password, root)
logging.getLogger('luniebox').info("spotifydl enabled!") logging.getLogger('luniebox').info("spotifydl enabled!")
return True return True
except Exception as ex: except Exception as exception:
logging.getLogger('luniebox').warning( logging.getLogger('luniebox').warning(
"error on setup spotifydl: " + str(ex)) "error on setup spotifydl: " + str(exception))
return False return False
def read_config(self): def read_config(self):
@ -315,14 +315,20 @@ class Luniebox(object):
else: else:
logging.getLogger('luniebox').warn( logging.getLogger('luniebox').warn(
"cannot resume spotify: " + self.current) "cannot resume spotify: " + self.current)
return True
elif self.service == PlayerService.MPD: elif self.service == PlayerService.MPD:
if text != self.current: if text != self.current:
if self.mpd_connect(): if self.mpd_connect():
try:
self.mpd.setvol(self.volume) self.mpd.setvol(self.volume)
self.mpd.clear() self.mpd.clear()
text = text.replace('mpd:', '') text = text.replace('mpd:', '')
self.mpd.add(text) self.mpd.add(text)
self.mpd.play() self.mpd.play()
except Exception as exception:
logging.getLogger('luniebox').warning(
"cannot not play mpd '" + text + "': " + str(exception))
return False
self.current = text self.current = text
self.set_setting('luniebox', 'current', self.current) self.set_setting('luniebox', 'current', self.current)
self.resume = False self.resume = False
@ -334,8 +340,13 @@ class Luniebox(object):
"play mpd: " + self.current) "play mpd: " + self.current)
elif self.resume and text == self.current: elif self.resume and text == self.current:
if self.mpd_connect(): if self.mpd_connect():
try:
self.mpd.setvol(self.volume) self.mpd.setvol(self.volume)
self.mpd.play() self.mpd.play()
except Exception as exception:
logging.getLogger('luniebox').warning(
"cannot not resume mpd '" + self.current + "': " + str(exception))
return False
self.resume = False self.resume = False
if text.startswith('spotify:'): if text.startswith('spotify:'):
logging.getLogger('luniebox').debug( logging.getLogger('luniebox').debug(
@ -343,10 +354,12 @@ class Luniebox(object):
else: else:
logging.getLogger('luniebox').debug( logging.getLogger('luniebox').debug(
"resume mpd: " + self.current) "resume mpd: " + self.current)
return True
elif text != None: elif text != None:
logging.getLogger('luniebox').info( logging.getLogger('luniebox').info(
"invalid value(?): " + str(text)) "invalid value(?): " + str(text))
return False
return False
def stop(self): def stop(self):
self.pause() self.pause()

View File

@ -6,4 +6,5 @@ mpu9250-jmdev==1.0.12
python-dateutil==2.8.2 python-dateutil==2.8.2
python-mpd2==3.0.4 python-mpd2==3.0.4
requests==2.26.0 requests==2.26.0
smbus==1.1.post2
smbus2==0.4.1 smbus2==0.4.1

BIN
audio/beep.wav Normal file

Binary file not shown.

BIN
audio/error.wav Normal file

Binary file not shown.

37
contrib/config/.asoundrc Normal file
View File

@ -0,0 +1,37 @@
pcm.speakerbonnet {
type hw card 0
}
pcm.dmixer {
type dmix
ipc_key 1024
ipc_perm 0666
slave {
pcm "speakerbonnet"
period_time 0
period_size 1024
buffer_size 8192
rate 44100
channels 2
}
}
ctl.dmixer {
type hw card 0
}
pcm.softvol {
type softvol
slave.pcm "dmixer"
control.name "PCM"
control.card 0
}
ctl.softvol {
type hw card 0
}
pcm.!default {
type plug
slave.pcm "softvol"
}

View File

@ -1,8 +1,12 @@
pcm.speakerbonnet { pcm.speakerbonnet {
type hw card 0 type hw card 0
} }
pcm.!default {
type plug
slave.pcm "dmixer"
}
pcm.dmixer { pcm.dmixer {
type dmix type dmix
ipc_key 1024 ipc_key 1024
@ -20,19 +24,3 @@ pcm.dmixer {
ctl.dmixer { ctl.dmixer {
type hw card 0 type hw card 0
} }
pcm.softvol {
type softvol
slave.pcm "dmixer"
control.name "PCM"
control.card 0
}
ctl.softvol {
type hw card 0
}
pcm.!default {
type plug
slave.pcm "softvol"
}

View File

@ -13,5 +13,5 @@ level = DEBUG
library_path = /home/pi/luniebox/library library_path = /home/pi/luniebox/library
[spotify] [spotify]
auto_download = False auto_download = True
zspotify_path = zspotify_path =

View File

@ -2,11 +2,10 @@
Description=Luniebox Application Description=Luniebox Application
[Service] [Service]
Type=simple
WorkingDirectory=/home/pi/luniebox/application WorkingDirectory=/home/pi/luniebox/application
ExecStart=/home/pi/luniebox/application/venv/bin/gunicorn -b 0.0.0.0:80 app:app ExecStart=/home/pi/luniebox/application/venv/bin/gunicorn -b 0.0.0.0:80 app:app
Restart=always Restart=on-failure
RestartSec=12 RestartSec=15
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@ -2,11 +2,13 @@
Description=Luniebox Daemon Description=Luniebox Daemon
[Service] [Service]
Type=simple User=pi
Group=pi
WorkingDirectory=/home/pi/luniebox/application WorkingDirectory=/home/pi/luniebox/application
ExecStart=/home/pi/luniebox/application/venv/bin/python daemon.py ExecStart=/home/pi/luniebox/application/venv/bin/python daemon.py
Restart=always Restart=on-failure
RestartSec=12 RestartSec=15
#FailureAction=/home/pi/luniebox/application/venv/bin/python daemon-failure.py
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@ -9,8 +9,8 @@ After=network-online.target
User=pi User=pi
Group=pi Group=pi
ExecStart=/home/pi/luniebox/bin/spotifyd --config-path /home/pi/luniebox/config/spotifyd.cfg --no-daemon ExecStart=/home/pi/luniebox/bin/spotifyd --config-path /home/pi/luniebox/config/spotifyd.cfg --no-daemon
Restart=always Restart=on-failure
RestartSec=12 RestartSec=15
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@ -1,19 +1,22 @@
#!/usr/bin/env bash #!/usr/bin/env bash
INSTALL_CONFIG_FILE="/home/pi/luniebox/config/install.cfg"
REPO_URL="https://git.bstly.de/Lurkars/luniebox.git"
AUTOMATIC=false AUTOMATIC=false
NO_UPDATES=false NO_UPDATES=false
NO_SPOTIFYDL=false NO_SPOTIFYDL=false
NO_SPOTIFY=false NO_SPOTIFY=false
NO_MPD=false NO_MPD=false
NO_AUDIO=false NO_AUDIO=false
MPU=false NO_MPU=true
AUDIO_DEVICE=false AUDIO_DEVICE=false
AUDIO_DEVICES=("pimoroni" "adafruit") AUDIO_DEVICES=("pimoroni" "adafruit")
DEVICE_NAME=false DEVICE_NAME=false
REBOOT=false
help() { help() {
local IFS="|" local IFS="|"
printf "Usage: ${SCRIPTNAME} [-h] [-a] [--audio-device AUDIO_DEVICE] [--device-name DEVICE_NAME] [--no-updates] [--no-spotifydl] [--no-spotify] [--no-mpd] [--mpu] \n" printf "Usage: ${SCRIPTNAME} [-h] [-a] [--audio-device AUDIO_DEVICE] [--device-name DEVICE_NAME] [--no-updates] [--no-spotifydl] [--no-spotify] [--no-mpd] [--mpu] [--repo-url] \n"
printf " -h\t\t\t\tshow this help\n" printf " -h\t\t\t\tshow this help\n"
printf " -a\t\t\t\tautomatic/non-interactive mode (without --audio-device, no Audio device is set up)\n" printf " -a\t\t\t\tautomatic/non-interactive mode (without --audio-device, no Audio device is set up)\n"
printf " --audio-device [AUDIO_DEVICE]\tset Audio device (one of [${AUDIO_DEVICES[*]}])\n" printf " --audio-device [AUDIO_DEVICE]\tset Audio device (one of [${AUDIO_DEVICES[*]}])\n"
@ -23,6 +26,7 @@ help() {
printf " --no-mpd\t\t\tskip installation of Music Player Daemon (no offline support, also skips zspotify)\n" printf " --no-mpd\t\t\tskip installation of Music Player Daemon (no offline support, also skips zspotify)\n"
printf " --no-spotify\t\t\tskip installation of spotifyd (no Spotify support, also skips zspotify)\n" printf " --no-spotify\t\t\tskip installation of spotifyd (no Spotify support, also skips zspotify)\n"
printf " --mpu\t\t\t\tsetup MPU9250 on I2C port (default is no MPU9250)\n" printf " --mpu\t\t\t\tsetup MPU9250 on I2C port (default is no MPU9250)\n"
printf " --repo-url [REPOSITORY_URL]\tset luniebox repository url (default https://git.bstly.de/Lurkars/luniebox.git)\n"
exit 0 exit 0
} }
@ -55,7 +59,11 @@ while [ -n "$1" ]; do
shift shift
;; ;;
"--mpu") "--mpu")
MPU=true NO_MPU=false
;;
"--repo-url")
REPO_URL="$2"
shift
;; ;;
*) *)
printf "\nargument '$1' not supported!\n\n" printf "\nargument '$1' not supported!\n\n"
@ -106,25 +114,52 @@ Run the script with -h to get more information about possible options to be appl
setup() { setup() {
cd /home/pi cd /home/pi
if [[ ${NO_UPDATES} == "false" ]]; then initialize
update update
fi setup_device_name
setup_software setup_software
set_device_name
setup_rfid setup_rfid
setup_mpu
if [[ ${NO_AUDIO} == "false" ]]; then
setup_audio setup_audio
fi setup_mpu
finalize finalize
} }
initialize() {
echo "Initizalize setup..."
echo "Check for previous setup..."
if [[ -f "${INSTALL_CONFIG_FILE}" ]]; then
eval $(sed -r "/[^=]+=[^=]+/!d;s/\s+=\s/=/g" "${INSTALL_CONFIG_FILE}")
fi
if [[ -z ${SETUP_INITIALIZE+x} ]]; then
echo "Install required packages..."
sudo apt install -y git
echo "Fetch luniebox repository..."
git clone "${REPO_URL}" /home/pi/luniebox
echo "Create config directory"
mkdir -p /home/pi/luniebox/config
echo "SETUP_INITIALIZE=true" | tee -a "${INSTALL_CONFIG_FILE}" 1>/dev/null
else
echo "luniebox is already setup!"
fi
if [[ -z ${SETUP_REPO_URL+x} ]]; then
echo "SETUP_REPO_URL=${REPO_URL}" | tee -a "${INSTALL_CONFIG_FILE}" 1>/dev/null
else
REPO_URL="${SETUP_REPO_URL}"
fi
}
update() { update() {
if [[ -z ${SETUP_UPDATES+x} ]]; then
if [[ ${NO_UPDATES} == "false" ]]; then
if [[ ${AUTOMATIC} == "false" ]]; then if [[ ${AUTOMATIC} == "false" ]]; then
read -rp "Do you want to update system now? [Y/n] (recommended) " response read -rp "Do you want to update system now? [Y/n] (recommended) " response
echo "" echo ""
case "$response" in case "$response" in
[nN][oO] | [nN]) [nN][oO] | [nN])
NO_UPDATES=true
return 0 return 0
;; ;;
esac esac
@ -133,27 +168,28 @@ update() {
echo "Update system" echo "Update system"
sudo apt update sudo apt update
sudo apt upgrade -y sudo apt upgrade -y
echo "SETUP_UPDATES=true" | tee -a "${INSTALL_CONFIG_FILE}" 1>/dev/null
fi
fi
if [[ -z ${SETUP_NO_UPDATES+x} ]]; then
echo "SETUP_NO_UPDATES=${NO_UPDATES}" | tee -a "${INSTALL_CONFIG_FILE}" 1>/dev/null
else
NO_UPDATES="${SETUP_NO_UPDATES}"
fi
} }
setup_software() { setup_software() {
setup_app setup_app
if [[ ${NO_SPOTIFY} == "false" ]]; then
setup_spotify setup_spotify
fi
if [[ ${NO_MPD} == "false" ]]; then
setup_mpd setup_mpd
fi
if [[ ${NO_SPOTIFYDL} == "false" ]]; then
setup_zspotify setup_zspotify
fi
} }
setup_app() { setup_app() {
if [[ -z ${SETUP_APP+x} ]]; then
echo "Install required packages..." echo "Install required packages..."
sudo apt install -y git python3-venv python3-pip sudo apt install -y python3-venv python3-pip
echo "Fetch luniebox repository..."
git clone https://git.bstly.de/Lurkars/luniebox.git /home/pi/luniebox
cd /home/pi/luniebox/application cd /home/pi/luniebox/application
echo "Setup python venv..." echo "Setup python venv..."
python -m venv venv python -m venv venv
@ -162,16 +198,20 @@ setup_app() {
echo "Install pip requirements..." echo "Install pip requirements..."
pip install -r requirements.txt pip install -r requirements.txt
deactivate deactivate
mkdir /home/pi/luniebox/config
echo "Setup config and systemd services..." echo "Setup config and systemd services..."
cp /home/pi/luniebox/contrib/config/luniebox.cfg /home/pi/luniebox/config/luniebox.cfg cp /home/pi/luniebox/contrib/config/luniebox.cfg /home/pi/luniebox/config/luniebox.cfg
sudo cp /home/pi/luniebox/contrib/service/luniebox-app.service /etc/systemd/system/ sudo cp /home/pi/luniebox/contrib/service/luniebox-app.service /etc/systemd/system/
sudo cp /home/pi/luniebox/contrib/service/luniebox-daemon.service /etc/systemd/system/ sudo cp /home/pi/luniebox/contrib/service/luniebox-daemon.service /etc/systemd/system/
sudo systemctl daemon-reload sudo systemctl daemon-reload
sudo systemctl enable luniebox-app luniebox-daemon sudo systemctl enable luniebox-app luniebox-daemon
REBOOT=true
echo "SETUP_APP=true" | tee -a "${INSTALL_CONFIG_FILE}" 1>/dev/null
fi
} }
setup_spotify() { setup_spotify() {
if [[ -z ${SETUP_SPOTIFY+x} ]]; then
if [[ ${NO_SPOTIFY} == "false" ]]; then
if [[ ${AUTOMATIC} == "false" ]]; then if [[ ${AUTOMATIC} == "false" ]]; then
read -rp "Do you want to install spotifyd for Spofity support? [Y/n] " response read -rp "Do you want to install spotifyd for Spofity support? [Y/n] " response
echo "" echo ""
@ -183,7 +223,7 @@ setup_spotify() {
esac esac
fi fi
mkdir /home/pi/luniebox/bin mkdir -p /home/pi/luniebox/bin
echo "Download spotifyd..." echo "Download spotifyd..."
wget -c https://github.com/Spotifyd/spotifyd/releases/download/v0.3.3/spotifyd-linux-armv6-slim.tar.gz -O - | tar -xz -C /home/pi/luniebox/bin wget -c https://github.com/Spotifyd/spotifyd/releases/download/v0.3.3/spotifyd-linux-armv6-slim.tar.gz -O - | tar -xz -C /home/pi/luniebox/bin
echo "Setup config and systemd services..." echo "Setup config and systemd services..."
@ -192,12 +232,25 @@ setup_spotify() {
echo "" echo ""
fi fi
cp /home/pi/luniebox/contrib/config/spotifyd.cfg /home/pi/luniebox/config/spotifyd.cfg cp /home/pi/luniebox/contrib/config/spotifyd.cfg /home/pi/luniebox/config/spotifyd.cfg
sed -i "s/^device_name.*=.*$/device_name = \"${DEVICE_NAME}\"/" /home/pi/luniebox/config/spotifyd.cfg
sudo cp /home/pi/luniebox/contrib/service/spotifyd.service /etc/systemd/system/ sudo cp /home/pi/luniebox/contrib/service/spotifyd.service /etc/systemd/system/
sudo systemctl daemon-reload sudo systemctl daemon-reload
sudo systemctl enable spotifyd sudo systemctl enable spotifyd
REBOOT=true
echo "SETUP_SPOTIFY=true" | tee -a "${INSTALL_CONFIG_FILE}" 1>/dev/null
fi
fi
if [[ -z ${SETUP_NO_SPOTIFY+x} ]]; then
echo "SETUP_NO_SPOTIFY=${NO_SPOTIFY}" | tee -a "${INSTALL_CONFIG_FILE}" 1>/dev/null
else
NO_SPOTIFY="${SETUP_NO_SPOTIFY}"
fi
} }
setup_mpd() { setup_mpd() {
if [[ -z ${SETUP_MPD+x} ]]; then
if [[ ${NO_MPD} == "false" ]]; then
if [[ ${AUTOMATIC} == "false" ]]; then if [[ ${AUTOMATIC} == "false" ]]; then
read -rp "Do you want to install mpd (Music Player Daemon) for offline file support? [Y/n] " response read -rp "Do you want to install mpd (Music Player Daemon) for offline file support? [Y/n] " response
echo "" echo ""
@ -208,7 +261,7 @@ setup_mpd() {
;; ;;
esac esac
fi fi
mkdir /home/pi/luniebox/library mkdir -p /home/pi/luniebox/library
echo "Install required packages..." echo "Install required packages..."
sudo apt install -y mpd sudo apt install -y mpd
echo "Setup config..." echo "Setup config..."
@ -217,10 +270,21 @@ setup_mpd() {
echo "" echo ""
fi fi
sudo cp /home/pi/luniebox/contrib/config/mpd.conf /etc/mpd.conf sudo cp /home/pi/luniebox/contrib/config/mpd.conf /etc/mpd.conf
REBOOT=true
echo "SETUP_MPD=true" | tee -a "${INSTALL_CONFIG_FILE}" 1>/dev/null
fi
fi
if [[ -z ${SETUP_NO_MPD+x} ]]; then
echo "SETUP_NO_MPD=${NO_MPD}" | tee -a "${INSTALL_CONFIG_FILE}" 1>/dev/null
else
NO_MPD="${SETUP_NO_MPD}"
fi
} }
setup_zspotify() { setup_zspotify() {
if [[ ${NO_SPOTIFY} == "false" ]] && [[ ${NO_MPD} == "false" ]]; then if [[ -z ${SETUP_SPOTIFYDL+x} ]]; then
if [[ ${NO_SPOTIFYDL} == "false" ]] && [[ ${NO_SPOTIFY} == "false" ]] && [[ ${NO_MPD} == "false" ]]; then
if [[ ${AUTOMATIC} == "false" ]]; then if [[ ${AUTOMATIC} == "false" ]]; then
read -rp "Do you want to install zspotify for downloading Spotify tracks for offline support? [Y/n] " response read -rp "Do you want to install zspotify for downloading Spotify tracks for offline support? [Y/n] " response
echo "" echo ""
@ -243,10 +307,20 @@ setup_zspotify() {
deactivate deactivate
echo "Setup config..." echo "Setup config..."
sed -i "s/^zspotify_path =.*$/zspotify_path = \/home\/pi\/clspotify\//" /home/pi/luniebox/config/luniebox.cfg sed -i "s/^zspotify_path =.*$/zspotify_path = \/home\/pi\/clspotify\//" /home/pi/luniebox/config/luniebox.cfg
REBOOT=true
echo "SETUP_SPOTIFYDL=true" | tee -a "${INSTALL_CONFIG_FILE}" 1>/dev/null
fi
fi
if [[ -z ${SETUP_NO_SPOTIFY+x} ]]; then
echo "SETUP_NO_SPOTIFYDL=${NO_SPOTIFYDL}" | tee -a "${INSTALL_CONFIG_FILE}" 1>/dev/null
else
NO_SPOTIFYDL="${SETUP_NO_SPOTIFYDL}"
fi fi
} }
set_device_name() { setup_device_name() {
if [[ -z ${SETUP_DEVICE_NAME+x} ]]; then
if [[ ${AUTOMATIC} == "false" ]] && [[ ${DEVICE_NAME} == "false" ]]; then if [[ ${AUTOMATIC} == "false" ]] && [[ ${DEVICE_NAME} == "false" ]]; then
read -rp "Name for your Luniebox devices [default: luniebox]: " DEVICE_NAME read -rp "Name for your Luniebox devices [default: luniebox]: " DEVICE_NAME
fi fi
@ -259,25 +333,30 @@ set_device_name() {
printf "${DEVICE_NAME}" | sudo tee /etc/hostname 1>/dev/null printf "${DEVICE_NAME}" | sudo tee /etc/hostname 1>/dev/null
sudo sed -i "/^127.0.0.1/s/$/ ${DEVICE_NAME}/g" /etc/hosts sudo sed -i "/^127.0.0.1/s/$/ ${DEVICE_NAME}/g" /etc/hosts
REBOOT=true
if [[ NO_SPOTIFY == "false" ]]; then echo "SETUP_DEVICE_NAME=${DEVICE_NAME}" | tee -a "${INSTALL_CONFIG_FILE}" 1>/dev/null
sed -i "s/^device_name.*=.*$/device_name = \"${DEVICE_NAME}\"/" /home/pi/luniebox/config/spotifyd.cfg else
DEVICE_NAME="${SETUP_DEVICE_NAME}"
fi fi
} }
setup_rfid() { setup_rfid() {
if [[ -z ${SETUP_RFID+x} ]]; then
echo "Enable SPI for RFID reader" echo "Enable SPI for RFID reader"
sudo sed -i "/dtparam=spi=on/s/^#//g" /boot/config.txt sudo sed -i "/dtparam=spi=on/s/^#//g" /boot/config.txt
REBOOT=true
echo "SETUP_RFID=true" | tee -a "${INSTALL_CONFIG_FILE}" 1>/dev/null
fi
} }
setup_mpu() { setup_mpu() {
if [[ ${AUTOMATIC} == "false" ]] && [[ ${MPU} == "false" ]]; then if [[ -z ${SETUP_MPU+x} ]]; then
if [[ ${AUTOMATIC} == "false" ]] && [[ ${NO_MPU} == "true" ]]; then
read -rp "Do you want to setup I2C for MPU9250 9-axis sensor? [y/N] " response read -rp "Do you want to setup I2C for MPU9250 9-axis sensor? [y/N] " response
echo "" echo ""
case "$response" in case "$response" in
[yY][eE][sS] | [yY]) [yY][eE][sS] | [yY])
MPU=true NO_MPU=false
break
;; ;;
*) *)
return 0 return 0
@ -285,16 +364,27 @@ setup_mpu() {
esac esac
fi fi
if [[ ${MPU} == "true" ]]; then if [[ ${NO_MPU} == "false" ]]; then
echo "Install I2C software, enable i2c bus 4, enable mpu" echo "Install I2C software, enable i2c bus 4, enable mpu"
sudo apt install -y i2c-tools python3-smbus sudo apt install -y i2c-tools python3-smbus
sudo sed -i "/dtparam=i2c_arm=on/s/^#//g" /boot/config.txt sudo sed -i "/dtparam=i2c_arm=on/s/^#//g" /boot/config.txt
printf "dtoverlay=i2c-gpio,bus=4,i2c_gpio_delay_us=1,i2c_gpio_sda=23,i2c_gpio_scl=24" | sudo tee -a /boot/config.txt 1>/dev/null printf "\n# setup i2c bus 4 for mpu\ndtoverlay=i2c-gpio,bus=4,i2c_gpio_delay_us=1,i2c_gpio_sda=23,i2c_gpio_scl=24\n" | sudo tee -a /boot/config.txt 1>/dev/null
sed -i "s/^mpu =.*$/mpu = True/" /home/pi/luniebox/config/luniebox.cfg sed -i "s/^mpu =.*$/mpu = True/" /home/pi/luniebox/config/luniebox.cfg
REBOOT=true
echo "SETUP_MPU=true" | tee -a "${INSTALL_CONFIG_FILE}" 1>/dev/null
fi
fi
if [[ -z ${SETUP_NO_MPU+x} ]]; then
echo "SETUP_NO_MPU=${NO_MPU}" | tee -a "${INSTALL_CONFIG_FILE}" 1>/dev/null
else
NO_MPU="${SETUP_NO_MPU}"
fi fi
} }
setup_audio() { setup_audio() {
if [[ -z ${SETUP_AUDIO+x} ]]; then
if [[ ${NO_AUDIO} == "false" ]]; then
if [[ ${AUTOMATIC} == "false" ]]; then if [[ ${AUTOMATIC} == "false" ]]; then
echo "Choose your audio hardware" echo "Choose your audio hardware"
select response in "${AUDIO_DEVICES[@]}"; do select response in "${AUDIO_DEVICES[@]}"; do
@ -316,22 +406,42 @@ setup_audio() {
echo "WARNING: please setup your audio device manually!" echo "WARNING: please setup your audio device manually!"
;; ;;
esac esac
fi
fi
if [[ -z ${SETUP_AUDIO_DEVICE+x} ]]; then
echo "SETUP_AUDIO_DEVICE=${AUDIO_DEVICE}" | tee -a "${INSTALL_CONFIG_FILE}" 1>/dev/null
else
AUDIO_DEVICE="${SETUP_AUDIO_DEVICE}"
fi
if [[ -z ${SETUP_NO_AUDIO+x} ]]; then
echo "SETUP_NO_AUDIO=${NO_AUDIO}" | tee -a "${INSTALL_CONFIG_FILE}" 1>/dev/null
else
NO_AUDIO="${SETUP_NO_AUDIO}"
fi
} }
setup_pimoroni() { setup_pimoroni() {
echo "Setup Pimoroni Shim" echo "Setup Pimoroni Shim"
sudo sed -i "/dtparam=audio=on/s/^/#/g" /boot/config.txt sudo sed -i "/dtparam=audio=on/s/^/#/g" /boot/config.txt
printf "dtoverlay=hifiberry-dac\ngpio=25=op,dh" | sudo tee -a /boot/config.txt 1>/dev/null printf "\n# setup hifiberry for Pimoroni Shim\ndtoverlay=hifiberry-dac\ngpio=25=op,dh\n" | sudo tee -a /boot/config.txt 1>/dev/null
REBOOT=true
echo "SETUP_AUDIO=true" | tee -a "${INSTALL_CONFIG_FILE}" 1>/dev/null
} }
setup_adafruit() { setup_adafruit() {
echo "Setup Adafruit Speaker Bonnet" echo "Setup Adafruit Speaker Bonnet"
sudo sed -i "/dtparam=audio=on/s/^/#/g" /boot/config.txt sudo sed -i "/dtparam=audio=on/s/^/#/g" /boot/config.txt
printf "dtoverlay=hifiberry-dac\ndtoverlay=i2s-mmap" | sudo tee -a /boot/config.txt 1>/dev/null printf "\n# setup hifiberry and i2s for Adafruit Speaker Bonnet\ndtoverlay=hifiberry-dac\ndtoverlay=i2s-mmap\n" | sudo tee -a /boot/config.txt 1>/dev/null
cat /home/pi/luniebox/contrib/config/asound.conf | sudo tee /etc/asound.conf 1>/dev/null cat /home/pi/luniebox/contrib/config/asound.conf | sudo tee /etc/asound.conf 1>/dev/null
cat /home/pi/luniebox/contrib/config/.asoundrc | tee /home/pi/.asoundrc 1>/dev/null
REBOOT=true
echo "SETUP_AUDIO=true" | tee -a "${INSTALL_CONFIG_FILE}" 1>/dev/null
} }
finalize() { finalize() {
if [[ ${REBOOT} == "true" ]]; then
if [[ ${AUTOMATIC} == "false" ]]; then if [[ ${AUTOMATIC} == "false" ]]; then
read -rp "Setup finished and reboot required. Do you want to automatically reboot your luniebox now? [Y/n] " response read -rp "Setup finished and reboot required. Do you want to automatically reboot your luniebox now? [Y/n] " response
echo "" echo ""
@ -345,9 +455,13 @@ finalize() {
fi fi
echo "Rebooting now...." echo "Rebooting now...."
sleep 2 sleep 1
sudo reboot sudo reboot
exit exit 0
else
echo "Bye...."
exit 0
fi
} }
start start