Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Kobo Reader > Kobo Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old Today, 03:16 PM   #1
RDavidson
Junior Member
RDavidson can fool all of the people all of the time.RDavidson can fool all of the people all of the time.RDavidson can fool all of the people all of the time.RDavidson can fool all of the people all of the time.RDavidson can fool all of the people all of the time.RDavidson can fool all of the people all of the time.RDavidson can fool all of the people all of the time.RDavidson can fool all of the people all of the time.RDavidson can fool all of the people all of the time.RDavidson can fool all of the people all of the time.RDavidson can fool all of the people all of the time.
 
Posts: 8
Karma: 138888
Join Date: May 2017
Device: Kindle Voyage, Kobo Clara HD
Post 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:
  1. Kill nickel and related processes (not strictly required, but recommended)
  2. Insert the sdio_bt_pwr kernel module (plus the uhid module if you want keyboard support)
  3. Launch hciattach
  4. Communicate with BlueZ over D-Bus (to launch the bluetooth daemon)

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
This is in fact what nickel does to turn bluetooth on; although it uses Qt's D-Bus module and it makes different calls to BlueZ (to handle scanning, pairing, etc). nickel also uses the -n argument to hciattach instead of -p; this causes it to remain in the foreground, instead of printing its pid and backgrounding itself. If you're starting hciattach as a subprocess you will likely want to do the same thing.

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.
RDavidson is offline   Reply With Quote
Reply

Tags
bluetooth


Forum Jump

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 07:50 PM
Command line - HOW? bookfanmd Calibre 19 01-12-2013 09:17 AM
Need help using command line tsger Recipes 2 07-16-2011 03:23 AM
Bluetooth enabling metras3 Nook Developer's Corner 1 01-30-2011 02:47 PM
Why use the command line? slantybard Calibre 6 07-22-2009 12:17 PM


All times are GMT -4. The time now is 06:39 PM.


MobileRead.com is a privately owned, operated and funded community.