07-14-2024, 04:16 PM | #1 |
Member
Posts: 10
Karma: 139288
Join Date: May 2017
Device: Kindle Voyage, Kobo Clara HD
|
Tutorial: enabling bluetooth from the command line
This tutorial is ONLY for the Clara 2E. Other devices, such as the recent Clara BW and Clara Color, will probably require very different steps.
Suppose for some reason you're developing an app that will kill nickel and take over the screen (you know, like alternative reader apps do), and you want to use bluetooth. You could turn bluetooth on in the settings screen before launching your app, but you might forget, and then if you do you have to exit and wait for nickel to restart, and then do the whole thing over again. Much better to be able to start bluetooth on your own, whenever you want. On the Clara 2E, here's what you have to do:
If you leave nickel running, I strongly recommend that you don't try toggling the Bluetooth setting in the UI. Only one bluetooth manager at a time, please! Code:
$ insmod /drivers/mx6sll-ntx/wifi/sdio_bt_pwr.ko $ /sbin/hciattach -p ttymxc1 any 1500000 flow -t 20 $ dbus-send --system --dest=org.bluez --print-reply / org.freedesktop.DBus.ObjectManager.GetManagedObjects When nickel turns bluetooth off, it kills the hciattach process and removes the sdio_bt_pwr kernel module. The bluetooth daemon (/libexec/bluetooth/bluetoothd) stays running unless it is separately killed. The sdio_bt_pwr kernel module seems to control the bluetooth hardware itself. Running hciattach connects the bluetooth hardware to the bluetooth stack; without this step you could interact with BlueZ but no adapters would be present, which makes the whole thing pretty useless. Interacting with BlueZ over D-Bus is exactly the same as it is on any other Bluetooth-enabled Linux machine. Plenty of tutorials and sample code are available. The relevant config directories are /etc/dbus-1 and /usr/share/dbus-1. D-Bus is configured to launch the bluetooth daemon as soon as any interaction happens with the org.bluez busname. So in the above example, just asking it what objects it knows about is sufficient to launch the daemon. Once the daemon is launched, you can use the bluetoothctl command line tool, or keep interacting with it over D-Bus, depending on the scope of your program. As far as I can tell, nothing you do here is going to break nickel's Bluetooth support, though nickel may be a little confused if you pair a keyboard, because nickel assumes you're going to be pairing audio devices. If you wanted to completely isolated from nickel's bluetooth settings, you may be able to do this by swapping out the contents of /var/db/bluetooth. (That is, move the existing contents to a safe place, then put in the saved settings files for your app, and then reverse this process before allowing nickel to restart.) I have not tested this for safety. Needless to say, if you do try this, you should make absolutely certain that bluetoothd is not running when you make changes in its settings directory. |
07-21-2024, 02:11 PM | #2 |
Junior Member
Posts: 2
Karma: 10
Join Date: Jul 2024
Device: kobo clara 2e
|
Can you do this permanently?
I am trying to use my kobo clara 2e for typing with a bluetooth keyboard, but I have to enable bluetooth every time, and I haven't found a way to take notes, as Koreader kills bluetooth. |
07-22-2024, 12:27 AM | #3 |
Member
Posts: 10
Karma: 139288
Join Date: May 2017
Device: Kindle Voyage, Kobo Clara HD
|
I don't know what you mean by "do this permanently". Of course bluetooth will be turned off the next time the device reboots, and there is no way (other than modding koreader) to prevent koreader from turning bluetooth off.
|
08-08-2024, 10:50 AM | #4 | |||
Connoisseur
Posts: 95
Karma: 81981
Join Date: Oct 2023
Location: Ontario, Canada
Device: Kobo Aura Edition 2, Kobo Clara 2E
|
Hello. Wow, I must've I missed this because I asked the question which you answered here.
For archive purposes I'll share my turn on/off scripts below. But I was going crazy with how Quote:
I will give your solution a try, I think the only thing missing from your script as it currently sits is the Quote:
One thing that I've notived with my experiments so that is that if you turn on bluetooth via nickel, then no matter what you do the system will lose 3% battery per hour, doesn't matter if you properly shutdown bluetooth or pkill all processes, nothing. Maybe this mod you mentioned is the trick. I will experiment and share my findings here. FWIW, it's easy to prevent koreader from killing bluetoothd on startup: Just comment out the bluetoothd in the killall comment in koreader/koreader.sh Quote:
One thing that still baffles me is the requirement to have wifi enabled is still present with this set of commands. I disable network and trigger these commands via koreader, and bluetooth won't come up. It doesn't have to be connected to any network, but wifi needs to be turned on. Last edited by lumping-sugar66; 08-08-2024 at 11:23 AM. |
|||
08-09-2024, 01:55 AM | #5 | |
Member
Posts: 10
Karma: 139288
Join Date: May 2017
Device: Kindle Voyage, Kobo Clara HD
|
Quote:
|
|
08-12-2024, 10:29 AM | #6 | |
Connoisseur
Posts: 72
Karma: 548
Join Date: Nov 2018
Device: Likebook Mars
|
Quote:
|
|
08-12-2024, 12:11 PM | #7 | |
Connoisseur
Posts: 95
Karma: 81981
Join Date: Oct 2023
Location: Ontario, Canada
Device: Kobo Aura Edition 2, Kobo Clara 2E
|
Quote:
There are a few one-time setup operations you need to do which are currently not automated via the plugin, but once you've done them (they're fairly simple), it's entirely handled inside KOReader. I made a post about it on KOReader forum. https://www.mobileread.com/forums/sh...d.php?t=362986 Essentially you need to find the your bluetooth devices' event codes, add them to device.lua manually as shown in the examples, and pair the bluetooth device one-time via either nickel or command line. |
|
Tags |
bluetooth |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Is there a way to execute a non-root command without access to command line | Galunid | Kindle Developer's Corner | 4 | 05-15-2018 08:50 PM |
Command line - HOW? | bookfanmd | Calibre | 19 | 01-12-2013 10:17 AM |
Need help using command line | tsger | Recipes | 2 | 07-16-2011 04:23 AM |
Bluetooth enabling | metras3 | Nook Developer's Corner | 1 | 01-30-2011 03:47 PM |
Why use the command line? | slantybard | Calibre | 6 | 07-22-2009 01:17 PM |