maggioni.xyz/_site/linux/2016/07/07/get-a-bluetooth-keyboard-wo...

190 lines
8.8 KiB
HTML

<!-- vim: set ts=2 sw=2 et tw=80: -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Get a Bluetooth keyboard work with Arch Linux</title>
<meta name="description" content="I've recently got a Rapoo E6100. This is a minimal and space saving Bluetooth 3.0 keyboard. If you pair it with Windows 10, it will remain paired after reboo...">
<link rel="stylesheet" href="/css/main.css">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono&display=swap" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Hammersmith+One' rel='stylesheet' type='text/css'>
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet">
<link rel="canonical" href="https://maggioni.xyz/linux/2016/07/07/get-a-bluetooth-keyboard-work-with-arch.html">
<link rel="alternate" type="application/rss+xml" title="maggioni.xyz" href="https://maggioni.xyz/feed.xml">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.6.0/css/font-awesome.min.css">
<script src="https://rawgit.com/snaptortoise/konami-js/master/konami.js"></script>
<!-- Favicon -->
<link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
</head>
<body>
<header class="header">
<nav class="head navbar">
<h1 class="title container">maggioni.xyz</h1>
<!-- vim: set ts=2 sw=2 et tw=80: -->
<div class="links container">
<a href="/">home</a>
<a href="/blog/">Blog</a>
<a href="/feed.xml">RSS</a>
<a href="/cv.html">CV</a>
</div>
<div class="links container">
<a href="https://git.maggioni.xyz">Git</a>
<a href="https://cloud.maggioni.xyz">Cloud</a>
</div>
</section>
</header>
<main class="container">
<article class="post" itemscope itemtype="http://schema.org/BlogPosting">
<header class="post-header">
<h2 class="post-title" itemprop="name headline">Get a Bluetooth keyboard work with Arch Linux</h2>
<h4 class="post-meta"><time datetime="2016-07-07T14:49:18+02:00" itemprop="datePublished">Jul 7, 2016</time></h4>
</header>
<div class="post-content" itemprop="articleBody">
<p>
I've recently got a Rapoo E6100. This is a minimal and space saving Bluetooth 3.0 keyboard. If you pair it with Windows 10, it will remain paired after reboot, giving the possibility to use it since the login screen. After installing the Bluetooth stack on my Arch via the <code>bluez</code> and <code>bluez-utils</code> packages I thought the pairing process would be as simple as Windows if I used the KDE GUI menus for Bluetooth management. That's not true. The keyboard, once paired, will reconnect automatically just after <code>plasmashell</code> loaded, leaving me without keyboard during the SDDM login screen and, of course, during a non-graphical session.
</p>
<p>
As usual, i've searched help in the ArchWiki, founding <a href="https://wiki.archlinux.org/index.php/Bluetooth_keyboard">this</a> article. With that, i've succesfully reconnected my Bluetooth keyboard using the <code>bluetoothctl</code> utility. The next step was configuring the service for auto connection during boot. I've created the <code>btkbd.conf</code> and the <code>btkbd.service</code> files, enabling the last one with systemd. Let's give a look to the service file:
</p>
<p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><table class="rouge-table"><tbody><tr><td class="gutter gl"><pre class="lineno">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre><span class="o">[</span>Unit]
<span class="nv">Description</span><span class="o">=</span>systemd Unit to automatically start a Bluetooth keyboard
<span class="nv">Documentation</span><span class="o">=</span>https://wiki.archlinux.org/index.php/Bluetooth_Keyboard
<span class="nv">Requires</span><span class="o">=</span>dbus-org.bluez.service
<span class="nv">After</span><span class="o">=</span>dbus-org.bluez.service
<span class="nv">ConditionPathExists</span><span class="o">=</span>/etc/btkbd.conf
<span class="nv">ConditionPathExists</span><span class="o">=</span>/usr/bin/hcitool
<span class="nv">ConditionPathExists</span><span class="o">=</span>/usr/bin/hciconfig
<span class="o">[</span>Service]
<span class="nv">Type</span><span class="o">=</span>oneshot
<span class="nv">EnvironmentFile</span><span class="o">=</span>/etc/btkbd.conf
<span class="nv">ExecStart</span><span class="o">=</span>/usr/bin/hciconfig <span class="k">${</span><span class="nv">HCIDEVICE</span><span class="k">}</span> up
<span class="c"># ignore errors on connect, spurious problems with bt?</span>
<span class="c"># so start next command with -</span>
<span class="nv">ExecStart</span><span class="o">=</span>-/usr/bin/hcitool cc <span class="k">${</span><span class="nv">BTKBDMAC</span><span class="k">}</span>
<span class="o">[</span>Install]
<span class="nv">WantedBy</span><span class="o">=</span>multi-user.target
</pre></td></tr></tbody></table></code></pre></figure>
</p>
<p>
Line 13 enables the Bluetooth dongle, and line 16 connects it to the keyboard we gave the mac address in <code>/etc/btkbd.conf</code>. This should work flawlessly, right? Of course it doesn't. The service starts before the <code>dbus-org.bluez.service</code> is loaded and fails. However, if the service is started manually after login the Bluetooth keyboard works. After hours of trying figuring out what was wrong I've almost asked for a return on Amazon! The last attempt I made was with sddm disabled and involved built from scratch service:
</p>
<p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><table class="rouge-table"><tbody><tr><td class="gutter gl"><pre class="lineno">1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre><span class="o">[</span>Unit]
<span class="nv">Description</span><span class="o">=</span>systemd Unit to automatically start a Bluetooth keyboard
<span class="o">[</span>Service]
<span class="nv">Type</span><span class="o">=</span>oneshot
<span class="nv">ExecStart</span><span class="o">=</span>/bin/hciconfig hci0 up
<span class="nv">ExecStart</span><span class="o">=</span>/bin/hcitool cc 00:11:22:33:44:55
<span class="o">[</span>Install]
<span class="nv">WantedBy</span><span class="o">=</span>bluetooth.target
</pre></td></tr></tbody></table></code></pre></figure>
</p>
<p>
This incredibly worked. I think the problem was that <code>multi-user.target</code> that needs to be reached earlier than <code>bluetooth.target</code>. I got rid of all the tidiness of the ArchWiki solution just to be sure that was not the problem, but I think you can use all of that just correcting <code>WantedBy=</code>. Currently I haven't an ArchWiki account nor a forum one, but as soon as I'll register I'll correct the article.
</p>
<p>
Last thing: I discovered that my Bluetooth dongle is CSR 8510 A10 based so expect some ramblings about <a href="http://www.0xf8.org/2014/02/the-crux-of-finding-a-hid-proxy-capable-usb-bluetooth-adapter/">hid proxy</a>.
</p>
</div>
</article>
</main>
<footer class="site-footer">
<div class="icons">
<a class="icon" href="https://github.com/maggicl"><i class="fa fa-github"></i></a>
<a class="icon" href="https://gitlab.com/maggicl"><i class="fa fa-gitlab"></i></a>
</div>
<h6 class="author">
<i class="fa fa-cc" aria-hidden="true"></i>
Claudio Maggioni
<script>
document.write((new Date()).getFullYear());
</script><br>
Content under
<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
CC BY-NC-SA 4.0</a>
</h6>
</footer>
</body>
</html>