diff --git a/Makefile b/Makefile index 3bc0898..22283d1 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ HOME_ASSISTANT_CONFIG := ~/network/home-assistant/config DEV_SYSTEMD_CONFIG_DIR := ~/.config/systemd/user LIVE_SYSTEMD_CONFIG_DIR := /etc/systemd/system LIVE_NGINX_CONFIG_DIR := /etc/nginx/sites-available +LIVE_BLUETOOTH_CONFIG_DIR := /etc/bluetooth VENV := .venv SYSTEMCTL_USER ?= @@ -197,14 +198,28 @@ live-install: debian $(DEBIAN_UNITS) # Player install # -debian-%-install: debian iris.%.conf debian/nginx.override.conf +install-bluetooth: + install -t $(LIVE_SYSTEMD_CONFIG_DIR) bluetooth/bt-agent@.service + install -t $(LIVE_BLUETOOTH_CONFIG_DIR) bluetooth/main.conf + install -m 0775 -t /usr/local/bin/ bluetooth/bluetooth-udev + install -t /etc/udev/rules.d/ bluetooth/99-bluetooth-udev.rules + +debian-%-install: iris.%.conf debian/nginx.override.conf install-bluetooth install -t $(LIVE_NGINX_CONFIG_DIR) iris.$*.conf install -T -D debian/nginx.override.conf $(LIVE_SYSTEMD_CONFIG_DIR)/nginx.service.d/override.conf -dietpi-%-install: dietpi iris.%.conf dietpi/nginx.override.conf +# osmc 2022.09+ already has some of these +debian-install-bluetooth: + apt-get install -y --no-install-recommends bluetooth bluez-tools armv7-bluezalsa-osmc + +dietpi-%-install: iris.%.conf dietpi/nginx.override.conf install-bluetooth install -t $(LIVE_NGINX_CONFIG_DIR) iris.$*.conf install -T -D dietpi/nginx.override.conf $(LIVE_SYSTEMD_CONFIG_DIR)/nginx.service.d/override.conf +# bluez-alsa is in: Raspbian 10 (but not installable) and Raspbian 12+ +dietpi-install-bluetooth: + apt-get install -y --no-install-recommends bluetooth bluez-tools bluez-alsa + clean: -rm $(ALL_CONFIGS) diff --git a/README.md b/README.md index 25dc500..2e2c745 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,8 @@ A **config generator** for a multizone audio system based on snapcast, Mopidy an - [x] Airplay - [x] Mopidy/MPD - [x] Kodi - - [ ] Bluetooth + - [x] Bluetooth + - [x] automatically accept new connections - [x] seamless switching between protocols in each zone - [x] high-priority announcement streams (alarms, doorbells) - [ ] invisible, automatic party reconfiguration @@ -105,7 +106,7 @@ which implements control of concurrent playback streams via - snapclient v0.25+ - nginx -- dietpi +- dietpi 9+ (Debian 12 "Bookworm") or [DietPi Bookworm test images](https://dietpi.com/blog/?p=2809)) - OSMC / Kodi v19+ - [kodi2mqtt](https://github.com/void-spark/kodi2mqtt) - install by manually extracting the zip in `~/.kodi/addons/` on the client diff --git a/bluetooth/99-bluetooth-udev.rules b/bluetooth/99-bluetooth-udev.rules new file mode 100644 index 0000000..bb9d63b --- /dev/null +++ b/bluetooth/99-bluetooth-udev.rules @@ -0,0 +1,2 @@ +SUBSYSTEM=="input", GROUP="input", MODE="0660" +KERNEL=="input[0-9]*", RUN+="/usr/local/bin/bluetooth-udev" diff --git a/bluetooth/bluetooth-udev b/bluetooth/bluetooth-udev new file mode 100644 index 0000000..a7ae1b9 --- /dev/null +++ b/bluetooth/bluetooth-udev @@ -0,0 +1,18 @@ +#!/bin/bash +# +# From rpi-audio-receiver by nicokaiser +# https://github.com/nicokaiser/rpi-audio-receiver/blob/main/install-bluetooth.sh +# +# +if [[ ! $NAME =~ ^\"([0-9A-F]{2}[:-]){5}([0-9A-F]{2})\"$ ]]; then exit 0; fi +action=$(expr "$ACTION" : "\([a-zA-Z]\+\).*") +if [ "$action" = "add" ]; then + bluetoothctl discoverable off + # disconnect wifi to prevent dropouts + #ifconfig wlan0 down & +fi +if [ "$action" = "remove" ]; then + # reenable wifi + #ifconfig wlan0 up & + bluetoothctl discoverable on +fi diff --git a/bluetooth/bt-agent@.service b/bluetooth/bt-agent@.service new file mode 100644 index 0000000..e8c97c5 --- /dev/null +++ b/bluetooth/bt-agent@.service @@ -0,0 +1,16 @@ +[Unit] +Description=Bluetooth Agent +Requires=bluetooth.service +After=bluetooth.service + +[Service] +ExecStartPre=/usr/bin/bluetoothctl discoverable on +ExecStartPre=/usr/bin/hciconfig %I piscan +ExecStartPre=/usr/bin/hciconfig %I sspmode 1 +ExecStart=/usr/bin/bt-agent --capability=NoInputNoOutput +RestartSec=5 +Restart=always +KillSignal=SIGUSR1 + +[Install] +WantedBy=multi-user.target diff --git a/bluetooth/main.conf b/bluetooth/main.conf new file mode 100644 index 0000000..6d2394e --- /dev/null +++ b/bluetooth/main.conf @@ -0,0 +1,3 @@ +[General] +# bluetooth speaker +Class = 0x200414