Mauersegler: Difference between revisions

From Lolly's Wiki
Jump to navigationJump to search
m (Text replacement - "<source" to "<syntaxhighlight")
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
[[Category:Vögel]]
==Lockrufe mit einem RaspberryPi und Bluetooth-Boxen abspielen==
==Lockrufe mit einem RaspberryPi und Bluetooth-Boxen abspielen==


Line 25: Line 26:
pi@raspberrypi:~ $ sudo systemctl enable bluetooth.service
pi@raspberrypi:~ $ sudo systemctl enable bluetooth.service
pi@raspberrypi:~ $ sudo systemctl start bluetooth.service
pi@raspberrypi:~ $ sudo systemctl start bluetooth.service
</source>
</syntaxhighlight>


====Bluetooth Service Status prüfen====
====Bluetooth Service Status prüfen====
Line 41: Line 42:
           `-943 /usr/lib/bluetooth/bluetoothd
           `-943 /usr/lib/bluetooth/bluetoothd
...
...
</source>
</syntaxhighlight>
Sieht es hingegen so aus:
Sieht es hingegen so aus:
<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
Line 49: Line 50:
Active: inactive (dead)
Active: inactive (dead)
Docs: man:bluetoothd(8)
Docs: man:bluetoothd(8)
</source>
</syntaxhighlight>
Dann sind im Betriebssystem die entsprechenden Treiber(module) für Bluetooth nicht geladen.
Dann sind im Betriebssystem die entsprechenden Treiber(module) für Bluetooth nicht geladen.


Line 64: Line 65:
/etc/modprobe.d/blacklist-bluetooth.conf:blacklist hci_uart
/etc/modprobe.d/blacklist-bluetooth.conf:blacklist hci_uart
/etc/modprobe.d/blacklist-bluetooth.conf:blacklist btbcm
/etc/modprobe.d/blacklist-bluetooth.conf:blacklist btbcm
</source>
</syntaxhighlight>
In meinem Beispiel also in <i>/etc/modprobe.d/blacklist-bluetooth.conf</i>.
In meinem Beispiel also in <i>/etc/modprobe.d/blacklist-bluetooth.conf</i>.


Line 72: Line 73:
<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
pi@raspberrypi:~ $ sudo perl -pi -e "s/(blacklist.*(hci_uart|btbcm))/#\1/g" /etc/modprobe.d/blacklist-bluetooth.conf
pi@raspberrypi:~ $ sudo perl -pi -e "s/(blacklist.*(hci_uart|btbcm))/#\1/g" /etc/modprobe.d/blacklist-bluetooth.conf
</source>
</syntaxhighlight>
Anschließend einen Neustart(reboot) durchführen
Anschließend einen Neustart(reboot) durchführen
<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
pi@raspberrypi:~ $ sudo reboot
pi@raspberrypi:~ $ sudo reboot
</source>
</syntaxhighlight>


Wenn die Module nach dem geladen sind, sieht es so aus:
Wenn die Module nach dem geladen sind, sieht es so aus:
Line 83: Line 84:
btbcm                  16384  1 hci_uart
btbcm                  16384  1 hci_uart
bluetooth            393216  37 hci_uart,bnep,btbcm,rfcomm
bluetooth            393216  37 hci_uart,bnep,btbcm,rfcomm
</source>
</syntaxhighlight>
Dann nochmal den [[#Bluetooth Service Status prüfen|Bluetooth Service Status prüfen]].
Dann nochmal den [[#Bluetooth Service Status prüfen|Bluetooth Service Status prüfen]].
Jetzt sollte alles gut sein.
Jetzt sollte alles gut sein.
Line 94: Line 95:
Discovery started
Discovery started
[CHG] Controller B8:27:EB:E6:D3:79 Discovering: yes
[CHG] Controller B8:27:EB:E6:D3:79 Discovering: yes
</source>
</syntaxhighlight>
Jetzt die Bluetooth-Boxen an
Jetzt die Bluetooth-Boxen an
<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
[NEW] Device D6:53:25:BE:37:73 SPEAKER5.0
[NEW] Device D6:53:25:BE:37:73 SPEAKER5.0
</source>
</syntaxhighlight>
Ah, da ist sie ja!
Ah, da ist sie ja!
Jetzt noch verbinden und raus:
Jetzt noch verbinden und raus:
Line 122: Line 123:
Device D6:53:25:BE:37:73 SPEAKER5.0
Device D6:53:25:BE:37:73 SPEAKER5.0
[SPEAKER5.0]# quit
[SPEAKER5.0]# quit
</source>
</syntaxhighlight>


Jetzt muß noch die Addresse der Boxen in die <i>/etc/asound.conf</i> eingetragen werden (die existiert normalerweise noch nicht, einfach neu anlegen).
Jetzt muß noch die Addresse der Boxen in die <i>/etc/asound.conf</i> eingetragen werden (die existiert normalerweise noch nicht, einfach neu anlegen).
Line 143: Line 144:
   type bluealsa
   type bluealsa
}
}
</source>
</syntaxhighlight>


Noch einmal reboot:
Noch einmal reboot:
<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
pi@raspberrypi:~ $ sudo reboot
pi@raspberrypi:~ $ sudo reboot
</source>
</syntaxhighlight>
Die Boxen sollten beim Starten des RaspberryPi jetzt auch ein kleines Signal abspielen, wenn das Pairing stattfindet.
Die Boxen sollten beim Starten des RaspberryPi jetzt auch ein kleines Signal abspielen, wenn das Pairing stattfindet.


Line 158: Line 159:
     Bluetooth SPEAKER5.0
     Bluetooth SPEAKER5.0
...
...
</source>
</syntaxhighlight>

Latest revision as of 10:53, 26 November 2021

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
...