Ramblings of an archer archer Things which an Arch Linux user that also owns an recurve bow can write. http://praticamentetilde.github.io/ Thu, 07 Jul 2016 21:23:45 +0200 Thu, 07 Jul 2016 21:23:45 +0200 Jekyll v3.1.6 Get a Bluetooth keyboard work with Arch Linux <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 class="highlighter-rouge">bluez</code> and <code class="highlighter-rouge">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 class="highlighter-rouge">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 class="highlighter-rouge">bluetoothctl</code> utility. The next step was configuring the service for auto connection during boot. I’ve created the <code class="highlighter-rouge">btkbd.conf</code> and the <code class="highlighter-rouge">btkbd.service</code> files, enabling the last one with systemd. Let’s give a look to the service file:</p> <figure class="highlight"><pre><code class="language-bash" data-lang="bash"><table style="border-spacing: 0"><tbody><tr><td class="gutter gl" style="text-align: right"><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<span class="w"> </span></pre></td></tr></tbody></table></code></pre></figure> <p>Line 13 enables the Bluetooth dongle, and line 16 connects it to the keyboard we gave the mac address in <code class="highlighter-rouge">/etc/btkbd.conf</code>. This should work flawlessly, right? Of course it doesn’t. The service starts before the <code class="highlighter-rouge">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> <figure class="highlight"><pre><code class="language-bash" data-lang="bash"><table style="border-spacing: 0"><tbody><tr><td class="gutter gl" style="text-align: right"><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<span class="w"> </span></pre></td></tr></tbody></table></code></pre></figure> <p>This incredibly worked. I think the problem was that <code class="highlighter-rouge">multi-user.target</code> that needs to be reached earlier than <code class="highlighter-rouge">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 class="highlighter-rouge">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>Let me know in the comments if this solution is well made or if it’s just a bodge. 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> Thu, 07 Jul 2016 14:49:18 +0200 http://praticamentetilde.github.io/linux/2016/07/07/get-a-bluetooth-keyboard-work-with-arch.html http://praticamentetilde.github.io/linux/2016/07/07/get-a-bluetooth-keyboard-work-with-arch.html linux