Mauersegler

From Lolly's Wiki
Jump to navigationJump to search

Lockrufe mit einem RaspberryPi und Bluetooth-Boxen abspielen

Womit ich es realisiert habe

  • RaspberryPi 3B.
  • Micro-SD Karte (die Größe ist den aktuellen Anforderungen auf Raspian.org zu entnehmen).
  • USB Netzteil mit Micro-USB Steckern (für den RaspberryPi).
  • An meinem Laptop ist ein SD Card Reader, um das Betriebssystem auf die SD-Karte zu bekommen. Ist dieser nicht vorhanden, braucht man noch einen USB SD Card Reader. Kostet aber auch nicht die Welt.

Gründe für diese Wahl

Dank der guten Reichweite von Bluetooth, kann der RaspberryPi im Haus bleiben und nur die Boxen und ein Netzteil müssen nach draußen.

Raspian auf dem Pi installieren

  • Anleitungen etc. sind auf Raspian.org zu finden, das würde hier kein Sinn machen alles doppelt zu halten.

Bluetooth aktivieren

Mit ssh als Benutzer pi auf den RaspberryPi verbinden. Windows-Nutzer können dafür Putty nutzen.

Bluetooth Service dauerhaft anschalten

pi@raspberrypi:~ $ sudo systemctl enable bluetooth.service
pi@raspberrypi:~ $ sudo systemctl start bluetooth.service

Bluetooth Service Status prüfen

So sollte es aussehen:

pi@raspberrypi:~ $ sudo systemctl status bluetooth.service
* bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2021-02-03 09:18:58 CET; 32min ago
     Docs: man:bluetoothd(8)
 Main PID: 943 (bluetoothd)
   Status: "Running"
    Tasks: 1 (limit: 2062)
   CGroup: /system.slice/bluetooth.service
           `-943 /usr/lib/bluetooth/bluetoothd
...

Sieht es hingegen so aus:

pi@raspberrypi:~ $ sudo systemctl status bluetooth.service
* bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:bluetoothd(8)

Dann sind im Betriebssystem die entsprechenden Treiber(module) für Bluetooth nicht geladen.

Bluetooth Module aktivieren

Wenn die Module deaktiviert (blacklisted) sind, müssen wir das ändern.

Der Befehl

egrep "(hci_uart|btbcm)" /etc/modprobe.d/*.conf

zeigt einem die Datei, wo das passiert.

Beispiel:

pi@raspberrypi:~ $ egrep "(hci_uart|btbcm)" /etc/modprobe.d/*.conf
/etc/modprobe.d/blacklist-bluetooth.conf:blacklist hci_uart
/etc/modprobe.d/blacklist-bluetooth.conf:blacklist btbcm

In meinem Beispiel also in /etc/modprobe.d/blacklist-bluetooth.conf.

Der Befehl

sudo perl -pi -e "s/(blacklist.*(hci_uart|btbcm))/#\1/g" <Datei>

kommentiert die blacklist Zeilen für die Beiden benötigten Module aus.

pi@raspberrypi:~ $ sudo perl -pi -e "s/(blacklist.*(hci_uart|btbcm))/#\1/g" /etc/modprobe.d/blacklist-bluetooth.conf

Anschließend einen Neustart(reboot) durchführen

pi@raspberrypi:~ $ sudo reboot

Wenn die Module nach dem geladen sind, sieht es so aus:

pi@raspberrypi:~ $ sudo lsmod | grep bt
btbcm                  16384  1 hci_uart
bluetooth             393216  37 hci_uart,bnep,btbcm,rfcomm

Dann nochmal den Bluetooth Service Status prüfen. Jetzt sollte alles gut sein.

Finden der Bluetooth-Boxen

pi@raspberrypi:~ $ sudo bluetoothctl
Agent registered
[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:E6:D3:79 Discovering: yes

Jetzt die Bluetooth-Boxen an

[NEW] Device D6:53:25:BE:37:73 SPEAKER5.0

Ah, da ist sie ja! Jetzt noch verbinden und raus:

[bluetooth]# scan off
[CHG] Controller B8:27:EB:E6:D3:79 Discovering: no
Discovery stopped
[bluetooth]# 
[bluetooth]# connect D6:53:25:BE:37:73
Attempting to connect to D6:53:25:BE:37:73
[CHG] Device D6:53:25:BE:37:73 Connected: yes
[CHG] Device D6:53:25:BE:37:73 UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device D6:53:25:BE:37:73 UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device D6:53:25:BE:37:73 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device D6:53:25:BE:37:73 UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device D6:53:25:BE:37:73 ServicesResolved: yes
[CHG] Device D6:53:25:BE:37:73 Paired: yes
Connection successful
[SPEAKER5.0]# trust D6:53:25:BE:37:73
[CHG] Device D6:53:25:BE:37:73 Trusted: yes
Changing D6:53:25:BE:37:73 trust succeeded
[SPEAKER5.0]# paired-devices
Device D6:53:25:BE:37:73 SPEAKER5.0
[SPEAKER5.0]# quit

Jetzt muß noch die Addresse der Boxen in die /etc/asound.conf eingetragen werden (die existiert normalerweise noch nicht, einfach neu anlegen).

pcm.!default {
type plug
 slave {
   pcm {
       type bluealsa
       device D6:53:25:BE:37:73
       profile "a2dp"
   }
 }
 hint {
   show on
   description "Bluetooth SPEAKER5.0"
 }
}
ctl.!default {
  type bluealsa
}

Noch einmal reboot:

pi@raspberrypi:~ $ sudo reboot

Die Boxen sollten beim Starten des RaspberryPi jetzt auch ein kleines Signal abspielen, wenn das Pairing stattfindet.

Jetzt kann man mal Testen:

pi@raspberrypi:~ $ aplay -L
...
default
    Bluetooth SPEAKER5.0
...