Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 12-10-2021, 05:05 AM   #1
Kindleschokolade
Connoisseur
Kindleschokolade began at the beginning.
 
Posts: 59
Karma: 14
Join Date: Dec 2021
Device: kindle PW3
Kindle brightness remote ( USB or Bluetooth )

Hello,

I have some older kindles that I found for cheap in a thrift store and I would like to use them in an installation we are preparing.
For this to work as we are planning it, I 'd need to be able to control the kindle's brightness and power-on remotely.
Preferably via Bluetooth but I guess USB seems to be possible as well?
I have found Kindle Lazy ( https://github.com/llakssz/KindleLazy ) so far, but maybe there are some other ways as well?
As for the power-on, it might not work when the kindle is off but we are thinking about a mechanincally controlled magnet which would actuate the kindle magnet switch.
Thanks for all help!
Kindleschokolade is offline   Reply With Quote
Old 12-10-2021, 02:49 PM   #2
katadelos
rm -rf /
katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.
 
Posts: 219
Karma: 3333683
Join Date: Nov 2019
Location: United Kingdom
Device: K5, KT, KT2, KT3, KT4, KV, PW2, PW3, PW4, PW5
Not enough info here, we'd need to hear more about your intended use case before being able to assist more.
  • What model + firmware are your Kindles?
  • Are you planning on running the devices on battery power during your installation?
  • When you say "power-on", do you mean a cold start as in, first boot on a brand new device/completely dead device being charged or just waking the device up as a cover or the power button would do?
  • What connectivity options do you have at the site of your installation? If WiFi is an option, it wouldn't be difficult to create a simple server to control brightness over HTTP
katadelos is offline   Reply With Quote
Advert
Old 12-10-2021, 05:17 PM   #3
Kindleschokolade
Connoisseur
Kindleschokolade began at the beginning.
 
Posts: 59
Karma: 14
Join Date: Dec 2021
Device: kindle PW3
Hello and thanks for replying.
- The Kindles I have here are two jailbroken PW2s ( B0D4 ) with Fw 5.10.3
and one PW1 ( B024 )
- I was hoping to be able to run the devices on power from an usb power supply.
- The "power-on" would mean "waking up" like the cover or the button would do.
- The preferred connectivity would be wifi as I am planning to be able to read and display data ( letters and numbers ) from an udp connection as well, which I hope to be able to display on screen via a simple dynamic website or similar.
an option would be to connect the external brightness buttons via an arduino working as a mock usb-keyboard.

Thanks!
Kindleschokolade is offline   Reply With Quote
Old 12-10-2021, 08:38 PM   #4
katadelos
rm -rf /
katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.
 
Posts: 219
Karma: 3333683
Join Date: Nov 2019
Location: United Kingdom
Device: K5, KT, KT2, KT3, KT4, KV, PW2, PW3, PW4, PW5
I got bored and wrote a quick script that should handle your use case:

Code:
import subprocess
from http.server import *

class KindleLipcHandler(BaseHTTPRequestHandler):
    def _set_backlight_level(self, level):
        subprocess.run(
            f"lipc-set-prop com.lab126.powerd flIntensity {level}", 
            shell=True
        )

    def _get_backlight_level(self):
        level = subprocess.check_output(
            "lipc-get-prop com.lab126.powerd flIntensity", 
            shell=True
        )
        return int(level.strip().decode())

    def _wakeup(self):
        subprocess.run(
            "lipc-set-prop com.lab126.powerd wakeUp 1", 
            shell=True
        )

    def handle_backlight(self, path_tokens):
        action = path_tokens[-1]
        current_level = self._get_backlight_level()
        new_level = current_level

        if action == "up":
            if current_level < 24:
                new_level = current_level + 1
        elif action == "down":
            if current_level > 0:
                new_level = current_level - 1
        elif action.isdigit():
            if int(action) in range(0,25):
                new_level = int(action)

        if new_level != current_level:
            self._set_backlight_level(new_level)
            return 1

        return 0

    def handle_wake(self):
        self._wakeup()        
        return 1

    def do_GET(self):
        path_tokens = self.path.split("/")
        t_len = len(path_tokens)
        ret = 0
        if t_len == 3:
            if path_tokens[1] == "backlight":
                ret = self.handle_backlight(path_tokens)
        elif t_len == 2:
            if path_tokens[1] == "wake":
                ret = self.handle_wake()

        if ret:
            self.send_response(200)
        else:
            self.send_response(500)
        self.send_header("Content-type", "text/html")
        self.end_headers()

        if ret:
            res = "<html>OK</html>"
        else:
            res = "<html>FAIL</html>"
        self.wfile.write(res.encode())

def run(server_class=HTTPServer, handler_class=KindleLipcHandler):
    server_address = ('', 8000)
    httpd = server_class(server_address, handler_class)
    httpd.serve_forever()

run()
It provides a very simple API accessible over HTTP with the following endpoints:
  • http://{device_ip}/wake - Wake device from sleep
  • http://{device_ip}/brightness/up - Set brightness to next level up
  • http://{device_ip}/brightness/down - Set brightness to next level down
  • http://{device_ip}/brightness/{0,24} - Set brightness to specific level

To run it, install NiLuJe's build of Python3 from here, save the script above to /mnt/us/server.py and run nohup python3 /mnt/us/server.py & from a shell using SSH.

You'll probably need to open port 8000 on the firewall of the Kindle before you can call the endpoints over WiFi.

Last edited by katadelos; 12-10-2021 at 08:42 PM.
katadelos is offline   Reply With Quote
Old 12-11-2021, 04:42 AM   #5
Kindleschokolade
Connoisseur
Kindleschokolade began at the beginning.
 
Posts: 59
Karma: 14
Join Date: Dec 2021
Device: kindle PW3
Oh. Wow. Thanks so much.
As a general question:
I have experience with python, apache, linux and bsd but not with the kindle yet.
Is there a compendium of kindle-os specific info? so that I dont have to ask too many questions and can find out on my own?
my next step would be to connect to and read udp data and/or to connect to and read from signal k running on a raspberry on the same network.
Thanks a lot!
Kindleschokolade is offline   Reply With Quote
Advert
Old 12-14-2021, 03:03 PM   #6
katadelos
rm -rf /
katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.katadelos ought to be getting tired of karma fortunes by now.
 
Posts: 219
Karma: 3333683
Join Date: Nov 2019
Location: United Kingdom
Device: K5, KT, KT2, KT3, KT4, KV, PW2, PW3, PW4, PW5
Quote:
Originally Posted by Kindleschokolade View Post
Oh. Wow. Thanks so much.
As a general question:
I have experience with python, apache, linux and bsd but not with the kindle yet.
Is there a compendium of kindle-os specific info? so that I dont have to ask too many questions and can find out on my own?
my next step would be to connect to and read udp data and/or to connect to and read from signal k running on a raspberry on the same network.
Thanks a lot!
There's no decent source of Kindle specific data apart from the forum itself; the wiki has bits and pieces but it's scattered about and is often severely outdated.

Broadly speaking, the Kindle OS consists of a (usually ancient) Linux kernel and a userland that would have been considered really modern circa ~2011. Reading a few books on embedded Linux from that era will give you a good idea of how things work internally.
katadelos is offline   Reply With Quote
Old 12-16-2021, 08:56 PM   #7
lclrc
Member
lclrc began at the beginning.
 
Posts: 10
Karma: 16
Join Date: Oct 2021
Device: kindle: Voyage, Paperwhite3
Quote:
Originally Posted by katadelos View Post
I got bored and wrote a quick script that should handle your use case:

Code:
import subprocess
from http.server import *

class KindleLipcHandler(BaseHTTPRequestHandler):
    def _set_backlight_level(self, level):
        subprocess.run(
            f"lipc-set-prop com.lab126.powerd flIntensity {level}", 
            shell=True
        )

    def _get_backlight_level(self):
        level = subprocess.check_output(
            "lipc-get-prop com.lab126.powerd flIntensity", 
            shell=True
        )
        return int(level.strip().decode())

    def _wakeup(self):
        subprocess.run(
            "lipc-set-prop com.lab126.powerd wakeUp 1", 
            shell=True
        )

    def handle_backlight(self, path_tokens):
        action = path_tokens[-1]
        current_level = self._get_backlight_level()
        new_level = current_level

        if action == "up":
            if current_level < 24:
                new_level = current_level + 1
        elif action == "down":
            if current_level > 0:
                new_level = current_level - 1
        elif action.isdigit():
            if int(action) in range(0,25):
                new_level = int(action)

        if new_level != current_level:
            self._set_backlight_level(new_level)
            return 1

        return 0

    def handle_wake(self):
        self._wakeup()        
        return 1

    def do_GET(self):
        path_tokens = self.path.split("/")
        t_len = len(path_tokens)
        ret = 0
        if t_len == 3:
            if path_tokens[1] == "backlight":
                ret = self.handle_backlight(path_tokens)
        elif t_len == 2:
            if path_tokens[1] == "wake":
                ret = self.handle_wake()

        if ret:
            self.send_response(200)
        else:
            self.send_response(500)
        self.send_header("Content-type", "text/html")
        self.end_headers()

        if ret:
            res = "<html>OK</html>"
        else:
            res = "<html>FAIL</html>"
        self.wfile.write(res.encode())

def run(server_class=HTTPServer, handler_class=KindleLipcHandler):
    server_address = ('', 8000)
    httpd = server_class(server_address, handler_class)
    httpd.serve_forever()

run()
It provides a very simple API accessible over HTTP with the following endpoints:
  • http://{device_ip}/wake - Wake device from sleep
  • http://{device_ip}/brightness/up - Set brightness to next level up
  • http://{device_ip}/brightness/down - Set brightness to next level down
  • http://{device_ip}/brightness/{0,24} - Set brightness to specific level

To run it, install NiLuJe's build of Python3 from here, save the script above to /mnt/us/server.py and run nohup python3 /mnt/us/server.py & from a shell using SSH.

You'll probably need to open port 8000 on the firewall of the Kindle before you can call the endpoints over WiFi.
Good idea!
I use this method to turn pages and exec some other commands with remote dongle.
lclrc is offline   Reply With Quote
Old 12-18-2021, 12:47 PM   #8
Kindleschokolade
Connoisseur
Kindleschokolade began at the beginning.
 
Posts: 59
Karma: 14
Join Date: Dec 2021
Device: kindle PW3
Quote:
Originally Posted by katadelos View Post
There's no decent source of Kindle specific data apart from the forum itself; the wiki has bits and pieces but it's scattered about and is often severely outdated.

Broadly speaking, the Kindle OS consists of a (usually ancient) Linux kernel and a userland that would have been considered really modern circa ~2011. Reading a few books on embedded Linux from that era will give you a good idea of how things work internally.
Thanks a lot. Will look into that then.
Kindleschokolade is offline   Reply With Quote
Old 12-28-2021, 11:41 AM   #9
Kindleschokolade
Connoisseur
Kindleschokolade began at the beginning.
 
Posts: 59
Karma: 14
Join Date: Dec 2021
Device: kindle PW3
Hello.
Finally came about to testing the script.
it works fine if the endpoint ist corrected to:
http://{device_ip}/backlight/
instead of
http://{device_ip}/brightness/

Thanks again!
Kindleschokolade is offline   Reply With Quote
Old 12-28-2021, 11:48 AM   #10
Kindleschokolade
Connoisseur
Kindleschokolade began at the beginning.
 
Posts: 59
Karma: 14
Join Date: Dec 2021
Device: kindle PW3
Also:
If I want to start this script on boot and keep it alive if it should crash, is this best done with cron?
Kindleschokolade is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
KindleLazy - remote control page turns + brightness zxczxc Kindle Developer's Corner 333 01-06-2024 10:51 PM
best solution for remote page turns? phone? bluetooth selfie remote? bluetooth mouse arooni Onyx Boox 2 09-13-2021 08:07 PM
Bluetooth remote for android? Blackheart Android Devices 15 08-09-2017 09:58 AM
Bluetooth remote control mxadler Marvin 8 11-13-2014 07:53 AM
602 bluetooth function as remote control for lego NXT brick dagplaytune PocketBook 3 03-08-2011 10:27 AM


All times are GMT -4. The time now is 04:10 AM.


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