TechSomething

Kindle 4 NT Jailbreaking and converting to a dashboard

Preface: #

I collect some useful metrics of my house on influxdb, and I'd like to have them ready to be glanced.

Device: #

Kindle 4th gen Non Touch (K4 NT)

Preparation: #

Donwload:

from: https://www.mobileread.com/forums/showthread.php?t=225030

and unzip both files

Jailbreaking: #

follow the instructions from: https://wiki.mobileread.com/wiki/Kindle4NTHacking
which are:

usbNetwork: #

once you are sure everything is ok, you can install usbnetwork
connect your kindle to your pc and move the file Update_usbnetwork_0.57.N_k4_install.bin into your kindle root folder

then in kindle's settings select "Update Your Kindle"

now read carefully the file README_FIRST.txt
be careful: when the instructions say to put the commands
;debugOn and ~usbNetwork in the searchbar you can rach that by clicking the keyboard button in yor home screen (it's not options --> Search)

you can put your ssh pubkeys in /usbnet/etc/authorized_keys

and configure your /usbnet/etc/config file,
after testing everything was ok I've settled for these config:

HOST_IP=192.168.15.201
KINDLE_IP=192.168.15.244
K3_WIFI="true"
K3_WIFI_SSHD_ONLY="true"
USE_OPENSSH="false"
USE_VOLUMD="true"
QUIET_DROPBEAR="false"
TWEAK_MAC_ADDRESS="false"

where I've only modified "K3_WIFI" and "K3_WIFI_SSHD_ONLY"

the workflow I've used has been:

NB: if you don't use ssh keys it asks you for a password which should be retrievable from the serial of the device using this site: https://www.sven.de/kindle/
but unfortunately that did not work tou for me.

KAUL: #

I've tried to install KUAL but I've not succeded,
it should ease some configurations like enabling usbnet.

I didn't needed it in the end so I didn't put too much effort in it
KUAL: https://www.mobileread.com/forums/showthread.php?t=203326

Dashboard: #

I've liked this project: https://github.com/pascalw/kindle-dash
because it simplifies the process rendering a dashboard image on a remote server then retrieving that image and displaying it on the kindle.

follo the instructions here to install it: https://github.com/pascalw/kindle-dash#installation

Dashboard config: #

I've edited my configuration as follows:

export WIFI_TEST_IP=${WIFI_TEST_IP:-1.1.1.1}                                                         
export REFRESH_SCHEDULE=${REFRESH_SCHEDULE:-"*/5 7-23,0-2 * * *"}                                    
export TIMEZONE=${TIMEZONE:-"Europe/Rome"}                                                           
export FULL_DISPLAY_REFRESH_RATE=${FULL_DISPLAY_REFRESH_RATE:-4}                                     
export SLEEP_SCREEN_INTERVAL=3600                                                                    
export LOW_BATTERY_REPORTING=${LOW_BATTERY_REPORTING:-true}                                          
export LOW_BATTERY_THRESHOLD_PERCENT=10   

I've edited only LOW_BATTERY_REPORTING to true, the TIMEZONE and REFRESH_SCHEDULE

Dashboard tweaks: #

update time and battery: #

see: https://github.com/pascalw/kindle-dash/issues/13

I want a line that displays the battery status and the last update time, especially in the first period of debugging.

in your /mnt/us/dashboard/local/dash.sh
find the "refresh_dashboard" function and add this line:

/usr/sbin/eips 1 39 "last update: $(date -Iminutes) battery: $(gasgauge-info -c | sed 's/%//g')"

like this:

refresh_dashboard() {
  echo "Refreshing dashboard"
  "$DIR/wait-for-wifi.sh" "$WIFI_TEST_IP"

  "$FETCH_DASHBOARD_CMD" "$DASH_PNG"

  if [ $num_refresh -eq $FULL_DISPLAY_REFRESH_RATE ]; then
    num_refresh=0

    # trigger a full refresh once in every 4 refreshes, to keep the screen clean
    echo "Full screen refresh"
    /usr/sbin/eips -f -g "$DASH_PNG"
    /usr/sbin/eips 1 39 "last update: $(date -Iminutes) battery: $(gasgauge-info -c | sed 's/%//g')"

  else
    echo "Partial screen refresh"
    /usr/sbin/eips -g "$DASH_PNG"
    /usr/sbin/eips 1 39 "last update: $(date -Iminutes) battery: $(gasgauge-info -c | sed 's/%//g')"
  fi

  num_refresh=$((num_refresh+1))
}

starting and stopping the dashboard: #

starting:

stopping:

at this point that's what you sould do to revert to normal functionality:

/mnt/us/dashboard/stop.sh
lipc-set-prop com.lab126.powerd preventScreenSaver 0
echo ondemand >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
initctl start webreader
/etc/init.d/framework start

also a device reboot works well :D

see: https://github.com/pascalw/kindle-dash/issues/12

changing the image: #

edit: /mnt/us/dashboard/local/fetch-dashboard.sh
changing the line:

$(dirname $0)/../ht -d -q -o "$1" get https://raw.githubusercontent.com/pascalw/kindle-dash/master/example/example.png

creating my own dashboard: #

dependencies:

apt-get install ImageMagic jq curl
yum install ImageMagick jq curl gnu-free-mono-fonts

I've some data on influxdb, so with API calls I can retrieve the last value of what I need:

home_temp=$(curl -s -G 'http://192.168.0.4:8086/query' --data-urlencode "db=home" --data-urlencode "q=SELECT LAST(\"value\") FROM \"temp\" WHERE \"sensor\" = 'home'")

then i can retrieve the clean value I need and round it to 1 decimal:

home_temp_cl=$(echo $home_temp | jq -r "(.results[0].series[0].columns), (.results[0].series[0].values[]) | @csv" | tail -1 | cut -d, -f2 | awk '{printf("%.1f\n", $1)}')

at this point I can create a simple txt file with all the values I need:

echo "Home temp: "$home_temp_cl > /tmp/dashboard.txt

then we can convert the txt file in an image:

convert -size 600x800 xc:white -font "FreeMono-Bold" -density 70 -pointsize 48 -gravity center -fill black -annotate +15+15 "@/tmp/dashboard.txt" /tmp/dashboard.png

NB: I've encountered some problems due to this part of the command: "@/tmp/dashboard.txt"
under 'buntu I had to edit /etc/ImageMagick-6/policy.xml
and comment out:

<policy domain="path" rights="none" pattern="@*"/>

that became:

<!--  <policy domain="path" rights="none" pattern="@*"/> -->

that was due to a security configuration of ImageMagick

under Centos the line was already disabled, and that was the default of the package.

output image:

description

NB: sometimes the kindle renders a white image instead of the correct one,
it seemed to be a problem of text being too near the border.
I did not understand if that was the real issue or not but fiddling with "density" and "pointsize" in convert did the trick.

Hosting the image: #

then you have to host it somewhere to make it available to the kindle
that's up to you

Final result: #

and that's the final result:

description

obviously my dashboard has more data,
but that's none of your beeswax.

Todo: #