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
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;
rfkill block bluetooth
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 /root/bin/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
nach Bluetooth-Gerät suchen, und MAC-Adresse notieren:
# hcitool scan
Scanning ...
00:10:60:00:62:72 JA2
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"
}
Tonausgabe mit einer WAVE-Datei testen:
# aplay -D btbox /usr/share/sounds/purple/login.wav
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.
> bluetoothctl help
> bluetoothctl list Controller 58:FB:84:27:CD:EF wanderer [default]
> bluetoothctl scan on Discovery started [CHG] Controller 58:FB:84:27:CD:EF Discovering: yes [NEW] Device CC:B1:1A:E5:F4:19 [TV] Samsung 5 Series (32) [NEW] Device 14:3F:A6:7E:B5:1B LE_WH-XB900N [CHG] Device 4C:87:5D:5D:92:B4 RSSI: -40 [CHG] Device 4C:87:5D:5D:92:B4 TxPower: -10 [CHG] Device 4C:87:5D:5D:92:B4 Name: LE-Bose Frames [CHG] Device 4C:87:5D:5D:92:B4 Alias: LE-Bose Frames [CHG] Device 4C:87:5D:5D:92:B4 ManufacturerData Key: 0x2001 [CHG] Device 4C:87:5D:5D:92:B4 ManufacturerData Value: 01 10 39 80 76 71 47 ..9.vqG
> bluetoothctl pair 4C:87:5D:5D:92:B4 Attempting to pair with 4C:87:5D:5D:92:B4 [CHG] Device 4C:87:5D:5D:92:B4 Connected: yes [NEW] Primary Service (Handle 0x2d5d) /org/bluez/hci1/dev_4C_87_5D_5D_92_B3/service0001 0000febe-0000-1000-8000-00805f9b34fb Bose Corporation ... [CHG] Device 4C:87:5D:5D:92:B4 ServicesResolved: yes [CHG] Device 4C:87:5D:5D:92:B4 Name: LE-Bose Frames [CHG] Device 4C:87:5D:5D:92:B4 Alias: LE-Bose Frames Pairing successful
> bluetoothctl connect 4C:87:5D:5D:92:B4 Attempting to connect to 4C:87:5D:5D:92:B4 Connection successful [CHG] Device CC:B1:1A:E5:F4:19 RSSI: -69 [CHG] Device CC:B1:1A:E5:F4:19 RSSI: -58
> bluetoothctl info 4C:87:5D:5D:92:B4 Device 4C:87:5D:5D:92:B4 (public) Name: Bose Frames Alias: Bose Frames Class: 0x00240418 Icon: audio-card Paired: yes Trusted: yes Blocked: no Connected: yes LegacyPairing: no