Dies ist eine alte Version des Dokuments!
Inhaltsverzeichnis
Bluetooth
Bluetooth-Installation
Installation "früher":
# aptitude install bluez bluez-utils bluez-hcidump
Installation in "Ubuntu 20.04":
# apt install bluez bluez-tools bluez-hcidump
# service bluetooth restart # hcitool dev # hciconfig --all # hcitool scan
/etc/bluetooth/hcid.conf bzw. /etc/bluetooth/main.conf (bluez-utils)
Für die Installation einer Bluetooth-Lautsprecher-Box habe ich diese Datei vollkommen unberührt gelassen.
options {
autoinit yes;
security auto;
pairing multi;
passkey "1234";
}
device {
name "%h-%d";
class 0x00100;
iscan enable; pscan enable;
discovto 0;
lm accept;
lp rswitch,hold,sniff,park;
}
Das Passwort bzw. der PIN wird hier eingegeben: passkey "1234";
bei einem Mobiltelefon: class 0x100100;
bei jedem Start deaktivieren
/etc/rc.local
rfkill block bluetooth
Bluetooth-Gerät anpingen
scan-Programm installieren:
> aptitude install bluez-hcidump
den Scan durchfuhren (für den scannen muss das Geraet kurzzeitig sichtbar sein):
> hcitool scan
Scanning ...
3C:36:3D:F8:C0:C7 Mobil-Telefon
Die MAC-Adresse sollte man sich jetzt notieren.
Ping installieren:
> aptitude install bluez
den Ping durchführen (die Bluetooth-Sichtbarkeit ist zur Sicherheit wieder abgeschaltet worden):
> l2ping -c 4 -r 3C:36:3D:F8:C0:C7 Can't connect: Connection refused
pingt das Gerät an, wenn es nicht in der Nähe ist, dann sieht das so aus:
> l2ping -c 4 -r 3C:36:3D:F8:C0:C7 Can't connect: Host is down
ein Skript, mit dem man die Anwesenheit eines bekannten Bluetooth-Gerätes ermitteln kann:
> vi /home/sbin/bluez_ping.sh
#!/bin/bash
#BLUEZMAC="3C:36:3D:C6:C0:C8" # Nokia C5.00 - Schwarz
BLUEZMAC="F4:8E:09:88:03:69" # Nokia C5.00 - Weiß
#BLUEZMAC="64:A7:69:BB:CA:0F" # HTC Wildfire
LOGDATEI="/var/log/bluez_ping.log"
#------------------------------------------------------------------------------#
WEG=" Host is down"
DA=" Connection refused"
#------------------------------------------------------------------------------#
### Bluetooth-Scan
# hcitool scan
#Scanning ...
# F4:8E:09:88:03:69 Weiß
#------------------------------------------------------------------------------#
if [ -r "${LOGDATEI}" ] ; then
STATUS="$(tail -n1 ${LOGDATEI} | awk -F':' '{print $1}')"
else
STATUS="neu"
fi
ERGEBNIS="$(l2ping -c 4 -r ${BLUEZMAC} 2>&1 | awk -F':' '{print $NF}')"
ZEITPUNKT="$(date +'%F %T')"
if [ "${ERGEBNIS}" = "${DA}" ] ; then
if [ "${STATUS}" != "ist da" ] ; then
echo "ist da: ${ZEITPUNKT}" >> ${LOGDATEI}
fi
elif [ "${ERGEBNIS}" = "${WEG}" ] ; then
if [ "${STATUS}" != "ist weg" ] ; then
echo "ist weg: ${ZEITPUNKT}" >> ${LOGDATEI}
fi
fi
Bluetooth per ALSA
nach Bluetooth-Gerät suchen, und MAC-Adresse notieren:
# hcitool scan
Scanning ...
00:10:60:00:62:72 JA2
.asoundrc
Konfigurationsdatei (mit der gescannten Bluetooth-MAC-Adresse) erstellen:
pcm.btbox {
type bluetooth
device 00:10:60:00:62:72
profile "auto"
}
pcm.!default {
type plug
slave.pcm "btbox"
}
Probe
Tonausgabe mit einer WAVE-Datei testen:
# aplay -D btbox /usr/share/sounds/purple/login.wav
Audio-Ausgabe umschalten
Wenn man seine Musik über das Bluetooth-Gerät hören will,
dann stellt man die Ausgabe seines Musikplayers auf "ALSA"
und sonst stellt man die Ausgabe auf "PulseAudio" ein.
