出自flip the world

Bluetooth keyboard auto connect:修訂間差異

Tommy​(留言 | 貢獻)
已建立頁面,內容為 "== Find keyboard & device MAC == <pre> #hcitool scan Scanning ... 23:E4:87:4C:B3:A1 Wireless Keyboard # hcitool dev Devices: hci0 06:05:04:03:02:01 <…"
 
Tommy​(留言 | 貢獻)
Add a lead sentence
 
(未顯示同一使用者於中間所作的 3次修訂)
第1行: 第1行:
Pairing a '''Bluetooth keyboard''' to a Raspberry Pi and having systemd reconnect it automatically at boot.
== Find keyboard & device MAC ==
== Find keyboard & device MAC ==
<pre>
<pre>
第29行: 第31行:


== Automative connecting with systemd ==
== Automative connecting with systemd ==
==== /etc/btkbd.conf ====
=== /etc/btkbd.conf ===
<pre>
<pre>
# Config file for btkbd.service
# Config file for btkbd.service
第37行: 第39行:
</pre>
</pre>


==== /etc/systemd/system/btkbd.service ====
=== /etc/systemd/system/btkbd.service ===
<pre>
<pre>
[Unit]
[Unit]
第56行: 第58行:
</pre>
</pre>


== reference ==
== Reference ==
*[https://wiki.archlinux.org/index.php/bluetooth_keyboard Bluetooth keyboard]
*[https://wiki.archlinux.org/index.php/bluetooth_keyboard Bluetooth keyboard]
*[http://www.correlatedcontent.com/blog/bluetooth-keyboard-on-the-raspberry-pi/ Bluetooth Keyboard on the Raspberry Pi]
*[http://www.correlatedcontent.com/blog/bluetooth-keyboard-on-the-raspberry-pi/ Bluetooth Keyboard on the Raspberry Pi]
[[Category:Projects]]

2026年8月23日 (日) 17:57的最新修訂

Pairing a Bluetooth keyboard to a Raspberry Pi and having systemd reconnect it automatically at boot.

Find keyboard & device MAC

#hcitool scan
Scanning ...
    23:E4:87:4C:B3:A1       Wireless Keyboard

# hcitool dev
Devices:
   hci0   06:05:04:03:02:01

Paring

#bluez-simple-agent hci0 23:E4:87:4C:B3:A1

If everything goes well, you will be prompted to type a passkey with your keyboard:
DisplayPasskey (/org/bluez/14656/hci0/dev_23_E4_87_4C_B3_A1, 936319)
Your passkey is the number at the end of the line. Don’t forget to press ‘Enter’ after typing the passcode! Now your device is paired with the Raspberry Pi.

Trusting & Connecting

The final stage is making sure that the raspberry will automatically connect to the keyboard when it is turned on. This is called ‘trusting’ and is invoked by this command:
#bluez-test-device trusted 23:E4:87:4C:B3:A1 yes

After trusing it, all you need to do is connect to it:
#bluez-test-input connect 23:E4:87:4C:B3:A1 yes

Automative connecting with systemd

/etc/btkbd.conf

# Config file for btkbd.service
# change when required (e.g. keyboard hardware changes, more hci devices are connected)
BTKBDMAC = 6C:5D:63:22:0B:05
HCIDEVICE = 00:1A:7D:DA:71:13

/etc/systemd/system/btkbd.service

[Unit]
Description=systemd Unit to automatically start a Bluetooth keyboard
Documentation=https://wiki.archlinux.org/index.php/Bluetooth_Keyboard
Requires=dbus-org.bluez.service
After=dbus-bluez.org.service
ConditionPathExists=/etc/btkbd.conf
ConditionPathExists=/usr/bin/hcitool
ConditionPathExists=/usr/sbin/hciconfig

[Service]
Type=oneshot
EnvironmentFile=/etc/btkbd.conf
ExecStart=-/usr/sbin/hciconfig ${HCIDEVICE} up
# ignore errors on connect, spurious problems with bt? so start next command with -
ExecStart=-/usr/bin/hcitool cc ${BTKBDMAC}

Reference