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 07-14-2024, 04:16 PM   #1
RDavidson
Member
RDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day now
 
Posts: 10
Karma: 139288
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
Old 07-21-2024, 02:11 PM   #2
jixbo
Junior Member
jixbo began at the beginning.
 
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.
jixbo is offline   Reply With Quote
Advert
Old 07-22-2024, 12:27 AM   #3
RDavidson
Member
RDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day now
 
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.
RDavidson is offline   Reply With Quote
Old 08-08-2024, 10:50 AM   #4
lumping-sugar66
Connoisseur
lumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trolls
 
lumping-sugar66's Avatar
 
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:
hciconfig hci0 up
would simply not bring the device up. This insmod seem to do the trick.

I will give your solution a try, I think the only thing missing from your script as it currently sits is the
Quote:
hciconfig hci0 up
at the end, but it goes through hiccup.

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:
killall -q -TERM nickel hindenburg sickel fickel strickel fontickel adobehost foxitpdf iink dhcpcd-dbu # bluetoothd
But If you can turn it on from the koreader via a plugin (which I'm writing), I wouldn't comment it out, and leave it as it is.


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.
Attached Files
File Type: txt turn_on.txt (820 Bytes, 35 views)
File Type: txt turn_off.txt (436 Bytes, 43 views)
File Type: txt oldpost.txt (1.0 KB, 36 views)

Last edited by lumping-sugar66; 08-08-2024 at 11:23 AM.
lumping-sugar66 is offline   Reply With Quote
Old 08-09-2024, 01:55 AM   #5
RDavidson
Member
RDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day nowRDavidson will be dicovering the secret to cold fusion any day now
 
Posts: 10
Karma: 139288
Join Date: May 2017
Device: Kindle Voyage, Kobo Clara HD
Quote:
Originally Posted by lumping-sugar66 View Post
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.
It's not that wild at all. It's very common in embedded scenarios for the Wifi and Bluetooth to be part of the same chip; in fact, you'll note that the kernel module has 'wifi' in the path.
RDavidson is offline   Reply With Quote
Advert
Old 08-12-2024, 10:29 AM   #6
trence
Connoisseur
trence will become famous soon enoughtrence will become famous soon enoughtrence will become famous soon enoughtrence will become famous soon enoughtrence will become famous soon enoughtrence will become famous soon enough
 
Posts: 72
Karma: 548
Join Date: Nov 2018
Device: Likebook Mars
Quote:
Originally Posted by lumping-sugar66 View Post
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 would simply not bring the device up. This insmod seem to do the trick.

I will give your solution a try, I think the only thing missing from your script as it currently sits is the at the end, but it goes through hiccup.

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


But If you can turn it on from the koreader via a plugin (which I'm writing), I wouldn't comment it out, and leave it as it is.


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.
This plugin will allow connection to remote turners within Koreader? Will this allow for pairing within koreader or would we need to connect the remote first, then boot into Koreader? I'd be more than happy to help test, I have been looking for Bluetooth page turning in Koreader forever.
trence is offline   Reply With Quote
Old 08-12-2024, 12:11 PM   #7
lumping-sugar66
Connoisseur
lumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trolls
 
lumping-sugar66's Avatar
 
Posts: 95
Karma: 81981
Join Date: Oct 2023
Location: Ontario, Canada
Device: Kobo Aura Edition 2, Kobo Clara 2E
Quote:
Originally Posted by trence View Post
This plugin will allow connection to remote turners within Koreader? Will this allow for pairing within koreader or would we need to connect the remote first, then boot into Koreader? I'd be more than happy to help test, I have been looking for Bluetooth page turning in Koreader forever.
Yes, it does. I've been using it for the past week, and so far so good.

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.
lumping-sugar66 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 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


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


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