Skip to content

Commit

Permalink
feat #15: bluetooth
Browse files Browse the repository at this point in the history
- a2dp as bluetooth speaker
- disable discovery while connected
- bt-agent service accepts connections without authorization
- OSMC and Dietpi clients
  • Loading branch information
markferry committed Jul 25, 2023
1 parent 27819aa commit 31eea97
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 4 deletions.
19 changes: 17 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?=
Expand Down Expand Up @@ -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/[email protected]
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)

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions bluetooth/99-bluetooth-udev.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SUBSYSTEM=="input", GROUP="input", MODE="0660"
KERNEL=="input[0-9]*", RUN+="/usr/local/bin/bluetooth-udev"
18 changes: 18 additions & 0 deletions bluetooth/bluetooth-udev
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions bluetooth/[email protected]
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions bluetooth/main.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[General]
# bluetooth speaker
Class = 0x200414

0 comments on commit 31eea97

Please sign in to comment.