Raspberry Pi – Bluetooth dongle en instellingen
Je kan bluetooth gebruiken op de Raspberry Pi, en zo de services daarvan gebruiken op apparaten die deze ook ondersteunen.
Bluetooth software installeren
Installeer de bluetooth software met het commando: sudo apt-get install bluez
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: libcap-ng0 The following NEW packages will be installed: bluez libcap-ng0 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded. Need to get 908 kB of archives. After this operation, 2,130 kB of additional disk space will be used. Do you want to continue [Y/n]? Y Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libcap-ng0 armhf 0.6.6-2 [12.3 kB] Get:2 http://mirrordirector.raspbian.org/raspbian/ wheezy/main bluez armhf 4.99-2 [895 kB] Fetched 908 kB in 1s (670 kB/s) Selecting previously unselected package libcap-ng0. (Reading database ... 77383 files and directories currently installed.) Unpacking libcap-ng0 (from .../libcap-ng0_0.6.6-2_armhf.deb) ... Selecting previously unselected package bluez. Unpacking bluez (from .../bluez_4.99-2_armhf.deb) ... Processing triggers for man-db ... Setting up libcap-ng0 (0.6.6-2) ... Setting up bluez (4.99-2) ... [ ok ] Reloading system message bus config...done. [ ok ] Starting bluetooth: bluetoothd rfcomm. W: Operation was interrupted before it could finish |
Bluetooth status en service
Je kan de status van de bluetooth zien met en van deze 2 commando’s:
sudo service bluetooth status
/etc/init.d/bluetooth status
Je krijg dan te zien: [ ok ] bluetooth is running
Ps. Dit is een service je kan deze dus stoppen, herstarten, starten, herladen.
Usage: /etc/init.d/bluetooth {start|stop|restart|force-reload|status}
Commandolijn tools, hcitool en hciconfig
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
hcitool - HCI Tool ver 4.99 Usage: hcitool [options] <command> [command parameters] Options: --help Display help -i dev HCI device Commands: dev Display local devices inq Inquire remote devices scan Scan for remote devices name Get name from remote device info Get information from remote device spinq Start periodic inquiry epinq Exit periodic inquiry cmd Submit arbitrary HCI commands con Display active connections cc Create connection to remote device dc Disconnect from remote device sr Switch master/slave role cpt Change connection packet type rssi Display connection RSSI lq Display link quality tpl Display transmit power level afh Display AFH channel map lp Set/display link policy settings lst Set/display link supervision timeout auth Request authentication enc Set connection encryption key Change connection link key clkoff Read clock offset clock Read local or remote clock lescan Start LE scan lewladd Add device to LE White List lewlrm Remove device from LE White List lewlsz Read size of LE White List lewlclr Clear LE White list lecc Create a LE Connection ledc Disconnect a LE Connection lecup LE Connection Update |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
hciconfig - HCI device configuration utility Usage: hciconfig hciconfig [-a] hciX [command ...] Commands: up Open and initialize HCI device down Close HCI device reset Reset HCI device rstat Reset statistic counters auth Enable Authentication noauth Disable Authentication encrypt Enable Encryption noencrypt Disable Encryption piscan Enable Page and Inquiry scan noscan Disable scan iscan Enable Inquiry scan pscan Enable Page scan ptype [type] Get/Set default packet type lm [mode] Get/Set default link mode lp [policy] Get/Set default link policy name [name] Get/Set local name class [class] Get/Set class of device voice [voice] Get/Set voice setting iac [iac] Get/Set inquiry access code inqtpl [level] Get/Set inquiry transmit power level inqmode [mode] Get/Set inquiry mode inqdata [data] Get/Set inquiry data inqtype [type] Get/Set inquiry scan type inqparms [win:int] Get/Set inquiry scan window and interval pageparms [win:int] Get/Set page scan window and interval pageto [to] Get/Set page timeout afhmode [mode] Get/Set AFH mode sspmode [mode] Get/Set Simple Pairing Mode aclmtu <mtu:pkt> Set ACL MTU and number of packets scomtu <mtu:pkt> Set SCO MTU and number of packets putkey <bdaddr> Store link key on the device delkey <bdaddr> Delete link key from the device oobdata Display local OOB data commands Display supported commands features Display device features version Display version information revision Display revision information block <bdaddr> Add a device to the blacklist unblock <bdaddr> Remove a device from the blacklist lerandaddr <bdaddr> Set LE Random Address leadv Enable LE advertising noleadv Disable LE advertising lestates Display the supported LE states |
Bluetooth adapter
Het MAC adres van de bluetooth adaprer is te zien met het commando: hcitool dev
1 2 |
Devices: hci0 00:11:67:1F:96:7A |
Naar apparaten scannen
Om bluetooth apparaten te scannen gebruik je het commando: hcitool scan
Je krijg dan het MAC adres te zien en de naam:
1 2 3 |
Scanning ... 78:1F:DB:BD:07:15 GT-S6810P 98:52:B1:4C:29:13 Starlord |
Apparaten pingen
Je kan een bluetooth apparaat pingen met het commando:
sudo l2ping -c 1 [MAC ADRES]
Bijvoorbeeld:
sudo l2ping -c 1 98:52:B1:4C:29:13
het ping resultaat:
1 2 3 |
Ping: 98:52:B1:4C:29:13 from 00:11:67:1F:96:7A (data size 44) ... 0 bytes from 98:52:B1:4C:29:13 id 0 time 32.31ms 1 sent, 1 received, 0% loss |
Zolang je het MAC adres weet, behoeft het toestel niet eens een ID uit te zenden (zichtbaar te zijn), zolang bluetooth aanstaat is het apparaat te pingen, staat bluetooth echt uit, dan krijg je dit te zien:
Can't connect: Host is down
Zo kun je dus eenvoudig een script schrijven als CRON om bijvoorbeeld om de 15 minuten te pingen of iemand thuis is en als er iets moet gaan gebeuren.
Bluetooth Class of Device
Een bluetooth apparaat heeft een code om weer te geven wat voor apparaat het is of waar het in zit, als je bijvoorbeeld een bluetooth stick op een Raspberry Pi hebt geinstalleerd, kun je de classes zien van de gescande apparaten met het commando:
cat /var/lib/bluetooth/[MAC adres van de dongle]/classes
bijvoorbeeld:
cat /var/lib/bluetooth/00:11:67:1F:96:7A/classes geeft:
1 2 |
98:52:B1:4C:29:13 0x5a020c 78:1F:DB:BD:07:15 0x5a020c |
Een lijst kun je hier vinden… 0x5a020c is een “smart phone”, er zijn zelfs site’s waarmee je een CoD kan genereren.
Je kan de class ook op de commandolijn aanpassen, bijvoorbeeld een “car audio system”:
hciconfig hci0 class 0x200420
Bluetooth pakketten TX/RX informatie
Net al het commando iwconfig voor het netwerk, kun je nu het commando: hciconfig gebruiken om TX/RX van alle bluetooth apparaten te zien:
1 2 3 4 5 |
hci0: Type: BR/EDR Bus: USB BD Address: 00:11:67:1F:96:7A ACL MTU: 678:8 SCO MTU: 48:10 UP RUNNING PSCAN ISCAN RX bytes:4253 acl:25 sco:0 events:161 errors:0 TX bytes:1446 acl:25 sco:0 commands:88 errors:0 |
Raspberry ID uitzenden
Standaard staat de Rapsberry niet in “discovery” modus, dit zet je aan doormiddel van het commando:
sudo hciconfig hci0 piscan
Als je nu bijvoorbeeld je telefoon pakt en scant voor bleutooth pparaten, staat de raspberry in de lijst:
Wil je snel zien of je de scan aan hebt staan, gebruik dan het commando:
sudo hciconfig -a hci0 | grep -i 'PSCAN *ISCAN'
1 2 |
pi@raspberrypi / $ sudo hciconfig -a hci0 | grep -i 'PSCAN *ISCAN' UP RUNNING PSCAN ISCAN |
Foutmelding “Can’t set scan mode on hci0: Network is down (100)”
Krijg je deze foutmelding te zien: “Can’t set scan mode on hci0: Network is down (100)”, dan kun je de hci config resetten met het commando:
sudo hciconfig hci0 reset
Raspberry Bluetooth naam (ID) en klasse aanpassen
De bluetooth adapter ID configuratie op de raspberry pi is aan te passen door het bestand config te bewerken, doormiddel van het commando:
sudo nano /var/lib/bluetooth/[MAC adres van de adapter]/config
bijvoorbeeld:
sudo nano /var/lib/bluetooth/00:11:67:1F:96:7A/config
1 2 3 |
name raspberrypi-0 pairable yes class 0x520100 |
Dit is bijvoorbeeld aan te passen naar:
1 2 3 |
name RPi_Audio pairable yes class 0x42041c |
Druk op CTRL+O en dan op ENTER om op te slaan, daarna op CTRL+X om nano af te sluiten.
Gebuik sudo service bluetooth restart of sudo service bluetooth force-reload om de configuratie opnieuw in te lezen:
1 2 |
[ ok ] Stopping bluetooth: rfcomm /usr/sbin/bluetoothd. [ ok ] Starting bluetooth: bluetoothd rfcomm. |
Daarna weer het commando: sudo hciconfig hci0 piscan om de Raspberry Pi te kunnen scannen.
Wil je snel de ID of naam controleren vanaf de Raspberry Pi, gebruik het commando:
sudo hciconfig -a hci0 | grep -i Name
1 2 |
pi@raspberrypi / $ sudo hciconfig -a hci0 | grep -i Name Name: 'raspberrypi-0' |
Bluetooth manager GUI
Standaard is er geen bluetooth manager geïnstalleerd op de Raspberry Pi:
Met het commando: sudo apt-get install blueman installeer je een bluetooth manager om zo de bluetooth verbindingen te beheren.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: imagemagick-common libcanberra-gtk3-0 libcanberra-gtk3-module libcanberra0 liblqr-1-0 libmagickcore5 libmagickwand5 lib notification-daemon obex-data-server python-cairo python-gconf python-gobject python-gobject-2 python-gtk2 python-notif Suggested packages: libcanberra-gtk0 libcanberra-pulse libmagickcore5-extra python-gnome2-doc python-gobject-2-dbg python-gtk2-doc The following NEW packages will be installed: blueman imagemagick-common libcanberra-gtk3-0 libcanberra-gtk3-module libcanberra0 liblqr-1-0 libmagickcore5 libmagickw libpulse-mainloop-glib0 notification-daemon obex-data-server python-cairo python-gconf python-gobject python-gobject-2 0 upgraded, 18 newly installed, 0 to remove and 0 not upgraded. Need to get 5,922 kB of archives. After this operation, 18.9 MB of additional disk space will be used. Do you want to continue [Y/n]? n Abort. pi@raspberrypi / $ sudo apt-get install blueman Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: imagemagick-common libcanberra-gtk3-0 libcanberra-gtk3-module libcanberra0 liblqr-1-0 libmagickcore5 libmagickwand5 lib notification-daemon obex-data-server python-cairo python-gconf python-gobject python-gobject-2 python-gtk2 python-notif Suggested packages: libcanberra-gtk0 libcanberra-pulse libmagickcore5-extra python-gnome2-doc python-gobject-2-dbg python-gtk2-doc The following NEW packages will be installed: blueman imagemagick-common libcanberra-gtk3-0 libcanberra-gtk3-module libcanberra0 liblqr-1-0 libmagickcore5 libmagickw libpulse-mainloop-glib0 notification-daemon obex-data-server python-cairo python-gconf python-gobject python-gobject-2 0 upgraded, 18 newly installed, 0 to remove and 0 not upgraded. Need to get 5,922 kB of archives. After this operation, 18.9 MB of additional disk space will be used. Do you want to continue [Y/n]? Y Get:1 http://archive.raspberrypi.org/debian/ wheezy/main python-gobject all 3.8.2-1+rpi1rpi2 [242 kB] Get:2 http://mirrordirector.raspbian.org/raspbian/ wheezy/main imagemagick-common all 8:6.7.7.10-5+deb7u3 [128 kB] Get:3 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libcanberra0 armhf 0.28-6 [36.6 kB] Get:4 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libcanberra-gtk3-0 armhf 0.28-6 [14.2 kB] Get:5 http://mirrordirector.raspbian.org/raspbian/ wheezy/main liblqr-1-0 armhf 0.4.1-2 [26.6 kB] Get:6 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libmagickcore5 armhf 8:6.7.7.10-5+deb7u3 [2,096 kB] Get:7 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libmagickwand5 armhf 8:6.7.7.10-5+deb7u3 [513 kB] Get:8 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libpulse-mainloop-glib0 armhf 2.0-6.1 [24.3 kB] Get:9 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libopenobex1 armhf 1.5-2+deb7u1 [21.3 kB] Get:10 http://mirrordirector.raspbian.org/raspbian/ wheezy/main obex-data-server armhf 0.4.5-1 [89.0 kB] Get:11 http://mirrordirector.raspbian.org/raspbian/ wheezy/main python-cairo armhf 1.8.8-1 [68.6 kB] Get:12 http://mirrordirector.raspbian.org/raspbian/ wheezy/main python-gobject-2 armhf 2.28.6-10 [475 kB] Get:13 http://mirrordirector.raspbian.org/raspbian/ wheezy/main python-gtk2 armhf 2.24.0-3 [1,450 kB] Get:14 http://mirrordirector.raspbian.org/raspbian/ wheezy/main python-notify armhf 0.1.1-3 [17.9 kB] Get:15 http://mirrordirector.raspbian.org/raspbian/ wheezy/main notification-daemon armhf 0.7.6-1 [49.0 kB] Get:16 http://mirrordirector.raspbian.org/raspbian/ wheezy/main blueman armhf 1.23-1 [578 kB] Get:17 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libcanberra-gtk3-module armhf 0.28-6 [16.1 kB] Get:18 http://mirrordirector.raspbian.org/raspbian/ wheezy/main python-gconf armhf 2.28.1+dfsg-1 [75.7 kB] Fetched 5,922 kB in 4s (1,348 kB/s) Selecting previously unselected package imagemagick-common. (Reading database ... 77480 files and directories currently installed.) Unpacking imagemagick-common (from .../imagemagick-common_8%3a6.7.7.10-5+deb7u3_all.deb) ... Selecting previously unselected package libcanberra0:armhf. Unpacking libcanberra0:armhf (from .../libcanberra0_0.28-6_armhf.deb) ... Selecting previously unselected package libcanberra-gtk3-0:armhf. Unpacking libcanberra-gtk3-0:armhf (from .../libcanberra-gtk3-0_0.28-6_armhf.deb) ... Selecting previously unselected package liblqr-1-0:armhf. Unpacking liblqr-1-0:armhf (from .../liblqr-1-0_0.4.1-2_armhf.deb) ... Selecting previously unselected package libmagickcore5:armhf. Unpacking libmagickcore5:armhf (from .../libmagickcore5_8%3a6.7.7.10-5+deb7u3_armhf.deb) ... Selecting previously unselected package libmagickwand5:armhf. Unpacking libmagickwand5:armhf (from .../libmagickwand5_8%3a6.7.7.10-5+deb7u3_armhf.deb) ... Selecting previously unselected package libpulse-mainloop-glib0:armhf. Unpacking libpulse-mainloop-glib0:armhf (from .../libpulse-mainloop-glib0_2.0-6.1_armhf.deb) ... Selecting previously unselected package libopenobex1. Unpacking libopenobex1 (from .../libopenobex1_1.5-2+deb7u1_armhf.deb) ... Selecting previously unselected package obex-data-server. Unpacking obex-data-server (from .../obex-data-server_0.4.5-1_armhf.deb) ... Selecting previously unselected package python-cairo. Unpacking python-cairo (from .../python-cairo_1.8.8-1_armhf.deb) ... Selecting previously unselected package python-gobject-2. Unpacking python-gobject-2 (from .../python-gobject-2_2.28.6-10_armhf.deb) ... Selecting previously unselected package python-gtk2. Unpacking python-gtk2 (from .../python-gtk2_2.24.0-3_armhf.deb) ... Selecting previously unselected package python-notify. Unpacking python-notify (from .../python-notify_0.1.1-3_armhf.deb) ... Selecting previously unselected package notification-daemon. Unpacking notification-daemon (from .../notification-daemon_0.7.6-1_armhf.deb) ... Selecting previously unselected package blueman. Unpacking blueman (from .../blueman_1.23-1_armhf.deb) ... Selecting previously unselected package libcanberra-gtk3-module:armhf. Unpacking libcanberra-gtk3-module:armhf (from .../libcanberra-gtk3-module_0.28-6_armhf.deb) ... Selecting previously unselected package python-gconf. Unpacking python-gconf (from .../python-gconf_2.28.1+dfsg-1_armhf.deb) ... Selecting previously unselected package python-gobject. Unpacking python-gobject (from .../python-gobject_3.8.2-1+rpi1rpi2_all.deb) ... Processing triggers for man-db ... Processing triggers for desktop-file-utils ... Processing triggers for hicolor-icon-theme ... Processing triggers for gconf2 ... Setting up imagemagick-common (8:6.7.7.10-5+deb7u3) ... Setting up libcanberra0:armhf (0.28-6) ... Setting up libcanberra-gtk3-0:armhf (0.28-6) ... Setting up liblqr-1-0:armhf (0.4.1-2) ... Setting up libmagickcore5:armhf (8:6.7.7.10-5+deb7u3) ... Setting up libmagickwand5:armhf (8:6.7.7.10-5+deb7u3) ... Setting up libpulse-mainloop-glib0:armhf (2.0-6.1) ... Setting up libopenobex1 (1.5-2+deb7u1) ... Setting up obex-data-server (0.4.5-1) ... Setting up python-cairo (1.8.8-1) ... Setting up python-gobject-2 (2.28.6-10) ... Setting up python-gtk2 (2.24.0-3) ... Setting up python-notify (0.1.1-3) ... Setting up notification-daemon (0.7.6-1) ... Setting up blueman (1.23-1) ... [ ok ] Reloading system message bus config...done. Setting up libcanberra-gtk3-module:armhf (0.28-6) ... Setting up python-gconf (2.28.1+dfsg-1) ... Setting up python-gobject (3.8.2-1+rpi1rpi2) ... Processing triggers for python-support ... |
Bronnen: modmypi.com / raspberrypi.org / correlatedcontent.com / instructables.com / davidvassallo.me / bbs.archlinux.org