# Kindle 4 as an e-ink dashboard (full guide for your AI agent)

> **For the AI agent reading this file**
>
> This is a step-by-step technical guide for turning a **Kindle 4 non-touch (model D01100, firmware 4.0.1), already jailbroken**, into an e-ink screen that shows dashboard boards (site stats, weather, AI limits and similar). A computer on the home network draws the boards as PNG files and serves them over HTTP. The Kindle only downloads and displays them.
>
> How to use it:
>
> - Guide the user **one step at a time**. Wait for them to confirm each step worked before moving on.
> - **Before you start, ask the user** which computer will run the board server and what system it runs (macOS, Linux, Windows), what its local IP address is (or will be), and whether the Kindle is already jailbroken with the hotfix that runs scripts. The jailbreak itself is not covered here.
> - All addresses below (`192.168.1.x`), ports and tokens are examples. Replace them with the user's own values. Never ask the user to paste private keys or passwords into chat.
> - Read section 10 (pitfalls) before you suggest anything. Most of it cost real hours.
>
> Source: https://hendzel.is/writing/kindle-dashboard

---

This guide is for someone who has a jailbroken Kindle 4 non-touch (model D01100, firmware 4.0.1) and wants to turn it into a screen that shows boards (site stats, weather, calendar and similar). The boards are drawn and served by a computer on the home network. The Kindle just downloads and shows them.

The guide came out of our own mistakes. There are quite a few hours in here you can save yourself.

## Contents

1. [The shortest version](#1-the-shortest-version)
2. [How it works (architecture)](#2-how-it-works-architecture)
3. [What you need](#3-what-you-need)
4. [Step 1: the board server on the computer](#4-step-1-the-board-server-on-the-computer)
5. [Step 2: scripts on the Kindle](#5-step-2-scripts-on-the-kindle)
6. [Step 3: autostart through a root init script](#6-step-3-autostart-through-a-root-init-script)
7. [Step 4: Wi-Fi on demand and saving battery](#7-step-4-wi-fi-on-demand-and-saving-battery)
8. [Step 5: SSH over Wi-Fi (so you stop running around with a cable)](#8-step-5-ssh-over-wi-fi)
9. [Step 6: diagnostics](#9-step-6-diagnostics)
10. [What not to do / pitfalls](#10-what-not-to-do--pitfalls)
11. [Quick checklist](#11-quick-checklist)

---

## 1. The shortest version

- The computer generates 600x800 grayscale PNG images and serves them over a plain HTTP server.
- After boot, the Kindle runs a script by itself (through a system init script), stops the book reader (the framework), downloads the images and draws them with `eips -f -g`.
- The buttons switch boards from memory, with no network. Wi-Fi turns on only for the download.
- **Don't try to install KUAL.** We lost many hours on it and it didn't work (section 10.1).
- You change files over SSH via Wi-Fi, but for SSH to work at all you have to open the Kindle's firewall (section 8).

## 2. How it works (architecture)

```
Computer on the home network                    Kindle 4
+--------------------------+                    +-----------------------------+
| boards.py: draws PNG     |   HTTP, once       | loop.sh:                    |
|   600x800, grayscale     |   every 15 min     |  1. turns Wi-Fi on          |
| serve.py: HTTP server    | <----------------> |  2. downloads every PNG     |
|   /TOKEN/board.png       |                    |  3. turns Wi-Fi off         |
|   /TOKEN/maint           |                    |  4. draws: eips -f -g       |
+--------------------------+                    |  5. waits for keys          |
                                                +-----------------------------+
```

The key decisions that worked:

| Decision | Why |
|---|---|
| The computer draws the whole image (PNG), the Kindle renders nothing | The Kindle 4 is very weak. A web page in its browser would be slow and ugly. With PNG you have full control over fonts and layout. |
| 600x800 image, grayscale mode "L" | That is exactly the screen resolution. No transparency, no colour. |
| Drawing with `eips -f -g file.png` | A built-in Kindle tool. `-g` draws the image, `-f` forces a full refresh so the previous board doesn't leave ghosts. |
| Downloading all boards at once into `/tmp` | Switching with the keys is then instant and needs no network. |
| `/etc/init.d/framework stop` at start | We stop the book reader, otherwise it overwrites the screen and handles keys its own way. |
| A manual `AUTOSTART` file as a kill switch | One place to turn autostart off, without digging through the system. |
| A token in the URL (`/TOKEN/board.png`) | Simple protection against random requests from the home network. Not real security, just a filter. |

## 3. What you need

- A Kindle 4 non-touch (D01100) with firmware 4.0.1, jailbroken (the jailbreak and the hotfix that runs scripts must already work. This guide doesn't cover them).
- A computer that is always on (ours is a small Mac). Python 3 and the Pillow library.
- Wi-Fi at home. The Kindle gets its address from DHCP, so it can change.
- A USB cable for the first file upload.
- The USBNetwork package by NiLuJe (only needed for the SSH program, section 8).

## 4. Step 1: the board server on the computer

Two files: `boards.py` (draws) and `serve.py` (serves).

### Drawing a board

Each board is a 600x800 image in `"L"` mode (grayscale), white background, black ink. Draw the fonts much bigger than you think. The screen has low contrast and you look at it from a distance.

```python
from PIL import Image, ImageDraw, ImageFont

WIDTH, HEIGHT = 600, 800

def new_board():
    img = Image.new("L", (WIDTH, HEIGHT), 255)   # 255 = white
    return img, ImageDraw.Draw(img)

img, d = new_board()
d.text((40, 36), "MONDAY", font=ImageFont.truetype("Arial Bold.ttf", 28), fill=0)
img.save("out/weather.png")
```

Notes:

- Always **draw the time and date on the server** (with an explicit time zone), not on the Kindle (see pitfall 10.9).
- Fetch data from external services on the server. If one of them is down, draw the board with a "no data" note instead of crashing the whole process.
- Make a separate PNG file for each board, e.g. `stats.png`, `weather.png`.

### HTTP server

A minimal server that refreshes the boards every 15 minutes and only answers URLs with the token:

```python
import subprocess, sys, threading, time
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from pathlib import Path

ROOT = Path(__file__).resolve().parent
OUT = ROOT / "out"
TOKEN = "put-a-random-token-here"     # e.g. 16 random characters
PORT = 8080
NAMES = {"stats.png", "weather.png"}  # allowlist of files

def render():
    subprocess.run([sys.executable, str(ROOT / "boards.py")], cwd=ROOT, check=False)

def refresh_loop():
    while True:
        time.sleep(15 * 60)
        render()

class Handler(BaseHTTPRequestHandler):
    def do_GET(self):
        prefix = "/" + TOKEN + "/"
        if not self.path.startswith(prefix):
            self.send_error(404); return
        name = self.path[len(prefix):].split("?", 1)[0]
        path = OUT / name
        if name not in NAMES or not path.is_file():
            self.send_error(404); return
        data = path.read_bytes()
        self.send_response(200)
        self.send_header("Content-Type", "image/png")
        self.send_header("Content-Length", str(len(data)))
        self.end_headers()
        self.wfile.write(data)

def main():
    threading.Thread(target=lambda: (render(), refresh_loop()), daemon=True).start()
    ThreadingHTTPServer(("0.0.0.0", PORT), Handler).serve_forever()

main()
```

Note that **the server starts right away and the drawing happens in the background**. Ours did it the other way round (pitfall 10.8).

Keep the file name allowlist (`NAMES`). Thanks to it nobody can pull other files from your disk through the URL.

### Test on the computer

```sh
python3 serve.py &
curl -s -o /dev/null -w "%{http_code} %{size_download}\n" http://127.0.0.1:8080/TOKEN/weather.png
```

You should get `200` and a size of a few dozen KB.

### The server has to run all the time

Run `serve.py` as a system service (launchd with `KeepAlive` on macOS, systemd on Linux). Also make sure the computer doesn't go to sleep and comes back after a power cut. Remember that after a power cut a computer with disk encryption may stop at the login screen, and the service won't start until someone logs in.

Reserve a **fixed IP address** for the computer in your router. The Kindle has it hard-coded.

## 5. Step 2: scripts on the Kindle

When connected with a cable, the Kindle shows up as a drive (the `/mnt/us` directory on the Kindle). Create a `dashboard` directory there with these files:

| File | What for |
|---|---|
| `config.sh` | server address and interval |
| `start.sh` | stops the reader, starts the loop |
| `loop.sh` | the loop: download, draw, keys |
| `watch.sh` | key listener |
| `stop.sh` | exit to the normal shelf |
| `boot.sh` | the init script version (copied to `/etc/init.d`, section 6) |
| `sshd.sh` | SSH server (section 8) |

### config.sh

```sh
BASE="http://192.168.1.50:8080/put-a-random-token-here"
REFRESH_MIN=15
```

### start.sh (the core)

```sh
#!/bin/sh
DIR=/mnt/us/dashboard
TMP=/tmp/dash
mkdir -p "$TMP"
# don't start while the Kindle is exposed as a USB drive
if grep -q '/dev/' /sys/devices/platform/*/gadget/lun*/file 2>/dev/null; then
    exit 0
fi
# don't run twice
if [ -f "$TMP/loop.pid" ] && kill -0 "$(cat "$TMP/loop.pid")" 2>/dev/null; then
    exit 0
fi
# copy the scripts to /tmp: the loop must not read from the USB drive, which can disappear
cp "$DIR/config.sh" "$DIR/loop.sh" "$DIR/watch.sh" "$DIR/stop.sh" "$TMP/"
eips -c                                   # clear the screen
eips 8 18 "Starting boards..."
lipc-set-prop com.lab126.powerd preventScreenSaver 1   # no screensaver
/etc/init.d/framework stop                # stop the book reader
setsid sh "$TMP/loop.sh" < /dev/null > /dev/null 2>&1 &
```

Why we copy the scripts to `/tmp`: when you connect the Kindle to a computer as a drive, the `/mnt/us` partition disappears from the Kindle's system. A loop reading files from there would crash.

### loop.sh (skeleton)

```sh
#!/bin/sh
trap '' HUP
DIR=/mnt/us/dashboard; TMP=/tmp/dash; CACHE=$TMP/c
. $TMP/config.sh
mkdir -p "$CACHE"; echo $$ > "$TMP/loop.pid"
PAGES="stats.png weather.png"; npages=2

show_page() {  # draws board number $page from memory
    name=...                      # the n-th name from $PAGES
    if [ -s "$CACHE/$name" ]; then eips -f -g "$CACHE/$name"
    else eips -c; eips 4 18 "No board $name"; fi
}

while true; do
    # 1) if a key was pressed ($TMP/key): switch, refresh or exit
    # 2) every REFRESH_MIN minutes: download everything again
    sleep 1
done
```

The full key and download logic is in section 7 and below.

### Keys

To listen for keys we use `waitforkey` (a program already on the Kindle in `/usr/bin`). It blocks until someone presses a key and prints two numbers: the key code and the state (1 = pressed).

```sh
while true; do
    line=$(/usr/bin/waitforkey) || { sleep 1; continue; }
    set -- $line
    [ "$2" = "1" ] || continue          # only presses, not releases
    echo "$1" > /tmp/dash/key           # the main loop reads this file
done
```

Codes that worked for us (check on your own unit: run `waitforkey` over SSH and press the keys):

| Codes | Action |
|---|---|
| 104, 191, 106, 108 | next board (page turn buttons, arrows) |
| 109, 193, 103, 105 | previous board |
| 194, 28 | middle button (OK): download the boards again |
| 102, 158, 139 | Home, Back, Menu: exit to the shelf |

Good practice: after handling a key, delete the `key` file once more after a short pause (`sleep 1`) so you don't catch a "bounce" (we sometimes got a double press).

We have a slower fallback without `waitforkey` in the code (reading `/dev/input/event*` directly with `dd`), but it is complicated and fragile. If `waitforkey` exists on your unit, don't go down to that level.

### Exit to the shelf (stop.sh)

```sh
kill "$(cat /tmp/dash/loop.pid)" 2>/dev/null
killall waitforkey 2>/dev/null
eips -c
lipc-set-prop com.lab126.powerd preventScreenSaver 0
lipc-set-prop com.lab126.wifid enable 1     # Wi-Fi back to normal
/etc/init.d/powerd start
/etc/init.d/framework start                 # the book reader comes back
```

**You only get back to the boards by restarting the Kindle** (Menu, Settings, Menu, Restart), because without KUAL there is no "launch" button.

## 6. Step 3: autostart through a root init script

This is the right way. At boot the Kindle runs scripts from `/etc/init.d` linked in `rc5.d`. We add our own.

The `boot.sh` file (installed as `/etc/init.d/dashboard` in our setup):

```sh
#!/bin/sh
# Start the dashboard after the Kindle boots, only if the AUTOSTART file exists.
case "$1" in
start)
    (
        trap '' HUP
        # wait until /mnt/us is mounted
        i=0
        while [ ! -f /mnt/us/dashboard/start.sh ] && [ $i -lt 90 ]; do
            sleep 2; i=$((i + 1))
        done
        [ -f /mnt/us/dashboard/AUTOSTART ] || exit 0       # kill switch
        sleep 55                                           # let the system come up
        [ -f /mnt/us/dashboard/AUTOSTART ] || exit 0       # check again
        # don't start while the Kindle is a USB drive
        if grep -q '/dev/' /sys/devices/platform/*/gadget/lun*/file 2>/dev/null; then
            exit 0
        fi
        sh /mnt/us/dashboard/start.sh >> /mnt/us/dashboard/boot.log 2>&1
    ) < /dev/null > /dev/null 2>&1 &
    ;;
esac
exit 0
```

Installation (once, as root, over SSH or from another startup script):

```sh
mntroot rw                                   # unlock writing to the system partition
cp /mnt/us/dashboard/boot.sh /etc/init.d/dashboard
chmod 755 /etc/init.d/dashboard
ln -sf ../init.d/dashboard /etc/rc5.d/S99dashboard
mntroot ro                                   # lock it again
```

What matters here:

- All the code runs in the background in a subshell and doesn't block system boot.
- We wait for the files to appear on `/mnt/us`, because at boot the partition can mount later than the script starts.
- The **`AUTOSTART` file is the kill switch**: delete it (via the USB drive or SSH) and after a restart the Kindle boots as a normal reader. This saves you when you make a mistake in the loop and the screen hangs.
- Always check whether the Kindle is currently a USB drive (see pitfall 10.5).
- Prepare an emergency route beforehand: a script that copies a new version of `boot.sh` into `/etc/init.d` and deletes itself after running (ours is `emergency.sh`). If you install a broken init script, without it all you have left is pulling files off the drive, and the system partition itself is read-only.

After installing: restart the Kindle (Menu, Settings, Menu, Restart). After about a minute you'll see "Starting boards..." and the first board.

## 7. Step 4: Wi-Fi on demand and saving battery

Wi-Fi that stays on drains the Kindle in a few days. So we turn it on only for the download, a few seconds every 15 minutes in total.

```sh
wifi_on()  { lipc-set-prop com.lab126.wifid enable 1 > /dev/null 2>&1; }
wifi_off() { lipc-set-prop com.lab126.wifid enable 0 > /dev/null 2>&1; }

wifi_wait() {                    # wait up to 60 s for a connection
    n=0
    while [ $n -lt 60 ]; do
        [ "$(lipc-get-prop com.lab126.wifid cmState)" = "CONNECTED" ] && return 0
        sleep 1; n=$((n + 1))
    done
    return 1
}
```

**`enable 1` on its own is not enough.** The interface still has to connect and get an address. Wait for `cmState` to equal `CONNECTED`, then give it 2 more seconds before the first download.

### Downloading with a time limit

The Kindle has a simplified `wget` (busybox). So that a hanging connection doesn't block the loop, we wrap it in our own timer:

```sh
dl() {   # dl URL FILE LIMIT_SECONDS
    wget -q -O "$2" "$1" &
    wpid=$!
    ( sleep "$3"; kill "$wpid" 2>/dev/null ) &
    dogpid=$!
    wait "$wpid"; rc=$?
    kill "$dogpid" 2>/dev/null
    return $rc
}
```

### The download cycle

```sh
fetch_all() {
    wifi_on
    wifi_wait
    sleep 2
    for n in $PAGES; do
        rm -f "$CACHE/$n.part"
        if dl "$BASE/$n" "$CACHE/$n.part" 30 && [ -s "$CACHE/$n.part" ]; then
            mv "$CACHE/$n.part" "$CACHE/$n"      # swap only after success
        fi
    done
    wifi_off
    show_page
}
```

Rules that saved us:

- Download to a `.part` file and swap only when the file is not empty. Then, with no network, the old board stays instead of a blank screen.
- With no network, retry after 2 minutes, not after the full 15.
- If the first download fails, don't bother with the rest (saves battery).

### Maintenance mode

When you want to work on the Kindle over SSH, Wi-Fi can't keep switching off. The solution: **a flag file on the server**. The server has a `/TOKEN/maint` URL that returns `1` if a `MAINT` file exists on the computer, and `0` otherwise. After every download the Kindle asks this URL and turns Wi-Fi off only when it got `0`.

On the server side (inside `do_GET`):

```python
if name == "maint":
    body = b"1\n" if (ROOT / "MAINT").exists() else b"0\n"
    self.send_response(200)
    self.send_header("Content-Type", "text/plain")
    self.send_header("Content-Length", str(len(body)))
    self.end_headers()
    self.wfile.write(body)
    return
```

On the Kindle side, after downloading the boards:

```sh
rm -f "$TMP/maint"                                  # IMPORTANT: delete the old result
if dl "$BASE/maint" "$TMP/maint" 15 && grep -q 1 "$TMP/maint"; then
    maint=1
fi
[ "$maint" = 1 ] || wifi_off
```

While you're at it, you can add the Kindle's address to the request (`/maint?ip=...`) and have the server save it to a file. That way you always know where to find it (section 9).

Remember to **delete the `MAINT` file** when you're done, otherwise the Kindle keeps Wi-Fi on all the time and drains fast.

## 8. Step 5: SSH over Wi-Fi

With SSH you can change scripts, read logs and restart the loop without a cable. It saves a ton of time, but three things have to be done right.

### 8.1. The SSH server from the USBNetwork package

From the USBNetwork package (by NiLuJe, on the MobileRead forum) we only need three pieces. Copy them to the Kindle into `/mnt/us/usbnet`:

```
/mnt/us/usbnet/bin/dropbearmulti     (the SSH program, one file for everything)
/mnt/us/usbnet/lib/libz.so.1         (a library, dropbear won't start without it)
/mnt/us/usbnet/etc/authorized_keys   (your public key)
```

We don't use the full USBNetwork installer, because it needs KUAL or its own hotfix. The files alone plus your own `sshd.sh` are enough.

**The paths are hard-coded** (`/mnt/us/usbnet/...`). If you unpack the package somewhere else, nothing will start, and you won't see an error.

### 8.2. The sshd.sh script

```sh
#!/bin/sh
# SSH server, keys only, no passwords.
U=/mnt/us/usbnet
LOG=/mnt/us/dashboard/boot.log
DB=$U/bin/dropbearmulti
[ -f "$DB" ] || exit 0

# 1) FIREWALL: open SSH and ping (see below)
for r in "-p tcp --dport 22 -j ACCEPT" "-p icmp -j ACCEPT"; do
    iptables -C INPUT $r 2>/dev/null || iptables -I INPUT $r >> "$LOG" 2>&1
done

# 2) don't run twice
if [ -f /tmp/dash/sshd.pid ] && kill -0 "$(cat /tmp/dash/sshd.pid)" 2>/dev/null; then
    exit 0
fi
mkdir -p /tmp/dash
export LD_LIBRARY_PATH=$U/lib

# 3) generate host keys ON THE DEVICE, once
for t in ed25519 rsa; do
    k=$U/etc/dropbear_${t}_host_key
    [ -s "$k" ] || "$DB" dropbearkey -t $t -f "$k" >> "$LOG" 2>&1
done

# 4) start: -s disables password login
"$DB" dropbear -s -p 22 -P /tmp/dash/sshd.pid \
    -r $U/etc/dropbear_ed25519_host_key -r $U/etc/dropbear_rsa_host_key >> "$LOG" 2>&1
```

Call this script from `start.sh` and after every board download (it is idempotent: it checks whether it's already running and doesn't duplicate firewall rules).

### 8.3. The Kindle firewall: the biggest pitfall

The Kindle has a built-in `iptables` firewall with an `INPUT DROP` policy. It drops **everything that comes to it over Wi-Fi, even ping**. Symptoms:

- the Kindle downloads boards normally (outgoing connections work),
- the server sees its address,
- but `ping` and `ssh` end with a timeout (`Operation timed out`).

For us it looked like an SSH failure, but really the two rules from step 1 above (tcp/22 and icmp) were all it took. Ping is useful for diagnostics, so open it too.

We only did this after several rounds with the cable. Open the firewall right away.

### 8.4. Keys and passwords

- Use **keys only**. Don't set a root password on the Kindle.
- Put your own public key into `authorized_keys`. Don't use keys from the package.
- Don't take host keys from a public package. Generate them on the Kindle (step 3 of the script).
- Add an entry to `~/.ssh/config` on your computer with an alias and the Kindle's address, user `root`.

### 8.5. The Kindle's address

A DHCP address can change. That's why the Kindle reports it to the server (`/maint?ip=...`) and the server saves it to a file. Or reserve a fixed address for the Kindle in the router (better).

## 9. Step 6: diagnostics

Without diagnostics you're guessing. The Kindle has no console screen, so you have to build your own view.

**On the Kindle side**, write to a single file at `/mnt/us/dashboard/boot.log`:

- every start (`start.sh`, script version),
- Wi-Fi on and off, plus the `cmState` value,
- how many boards were downloaded (`3/7`),
- which keys were detected,
- the Kindle's address and firewall state (`iptables -L INPUT -n`).

You read the file via the USB drive or over SSH. Trim it (e.g. when it goes over 50 KB, keep the last 200 lines), because memory is small.

**On the server side**, log every request (time, client address, URL). In code it's enough to override `log_message` in `BaseHTTPRequestHandler`. That way you immediately see:

- whether the Kindle connects at all,
- when it last did, at what time and which files it downloaded,
- at what address to find it.

Cap the log size (ours is about 200 KB, then it gets cleared).

**On-screen status:** a short message with `eips x y "text"` at key points ("Starting boards...", "No network, retry in 2 min", "Back to the shelf...") saves a lot of guessing.

## 10. What not to do / pitfalls

### 10.1. Don't install KUAL on a K4 with firmware 4.0.1

KUAL is a popular app launcher. On a Kindle 4 with firmware 4.0.1 **it didn't work for us in any version**. Every time the same message:

> This item is not signed by an authorized developer.

What we tried (all without success):

1. Old MKK keys (from 2014): expired, don't work.
2. New official MKK keys from April 2025 plus the official KUAL signed in 2025: doesn't work. The system log showed the app was recognised as a developer app, and it was still rejected.
3. Re-signing KUAL with an older algorithm (SHA-1 with RSA) using the same 2025 keys: doesn't work. The hypothesis that the old Java on the K4 can't verify newer SHA-256 digests was not confirmed by a fix.
4. Our own DSA keys (1024 bit, valid until 2099) and KUAL signed with SHA1withDSA: doesn't work.

Recommendation: **go straight to autostart through a root init script** (section 6). We lost most of the first day on kindlets and keys.

### 10.2. Files with the "immutable" attribute (chattr)

When trying to replace the keystore file in the system we got `Operation not permitted`, even as root. The reason: the file had the immutable attribute. Only `chattr -i file` let us overwrite it. If root gets "Operation not permitted" on `cp` or `chmod` of a system file, check `lsattr`. Also remember the system partition is read-only by default and needs `mntroot rw`.

### 10.3. The Kindle shows up as a drive only while the book reader is running

While the boards are on (framework stopped), plugging in the cable **does not expose the drive**. The computer sees nothing and you think the cable is broken. The order that works:

1. Press **Home** on the Kindle (back to the shelf, the framework starts).
2. Wait a dozen or so seconds until "USB drive mode" appears and the drive shows up on the computer.
3. Only then copy the files.
4. Eject the drive, unplug the cable, restart the Kindle.

And the other way round: if the Kindle boots with the cable plugged into a computer, the boards will **not** start, by design (we check this in `boot.sh` and `start.sh` via `/sys/devices/platform/*/gadget/lun*/file`). A plain wall charger doesn't interfere. Connect to the computer only after the boards are up, or after Home.

### 10.4. Uploading files by cable is a slog

Every fix by cable means: Home, cable, wait for the drive, copy, eject, unplug, restart, a minute of waiting. Set up SSH as early as possible (section 8), and **open the firewall in the very first version**. We only did it at the end and went back to the cable several times.

### 10.5. Don't leave the Kindle connected to the computer at boot

See above. The boards won't start, and you'll look for a bug in the scripts when it's just the cable.

### 10.6. Stale result file with busybox wget

The Kindle has a simplified `wget` (busybox). When the target file already exists, the next download into it can fail, and your script gets an error or the old result. For us this hit the maintenance mode URL: the first request after boot worked, every following one didn't (see 10.7).

Always:

```sh
rm -f "$FILE"          # delete before downloading
dl "$URL" "$FILE" 15   # download
[ -s "$FILE" ] || ...  # check it's not empty
```

### 10.7. Maintenance mode worked only once

Symptom: after boot the Kindle left Wi-Fi on, but after every following refresh (OK) it turned it off anyway, despite the `MAINT` flag on the server. The server log showed the request and the `1` answer. The cause is pitfall 10.6: the result file from the previous time blocked the new download. One `rm -f` line before the download fixed it.

### 10.8. The server starts only after the first render

In our `serve.py`, `main()` first drew all the boards (several external services, each with a timeout), and only then started the server. After the computer restarted, the Kindle knocked on a port that didn't exist yet, and the download failed. Start the server right away and draw in a separate thread (as in section 4). For boards that don't exist yet the server answers 404, and the Kindle retries after 2 minutes.

### 10.9. The Kindle's clock and time zone don't match the computer

The Kindle's clock had a different time zone (in the logs the zone showed up as an odd abbreviation, and the times were several hours off the computer's clock). Result: times in `boot.log` don't match the server log, and it's easy to decide nothing is happening when it is. Rules:

- draw the date and time on the board **on the server** with an explicit zone (e.g. `Europe/Warsaw`),
- don't trust `date` on the Kindle as a source of truth,
- when comparing logs, look at the order of events, not the times.

### 10.10. The Kindle firewall (again, because it cost the most)

`INPUT policy DROP`. Outgoing connections work, incoming ones don't, not even ping. Add the tcp/22 and icmp rules right away in `sshd.sh`. Check with `iptables -L INPUT -n`.

### 10.11. The Kindle doesn't report its address, so you don't know where to look

For a few hours we waited for an address the Kindle never sent, because nobody had restarted it after the new version was uploaded. First check the server log: were there any requests from the Kindle at all, and when was the last one. If not, the problem is on the Kindle side (Wi-Fi, script start), not SSH.

### 10.12. The e-ink screen and ghosts

Fast refresh leaves shadows of the previous board. Use `eips -f -g` (full refresh) when switching boards. A black-and-white image with high contrast looks best. Very thin lines and small fonts blur together, so draw thicker and with a bigger typeface than on a normal screen.

### 10.13. What else not to do

- **Don't put passwords or private keys in files on the Kindle.** Only the public key in `authorized_keys`.
- **Don't let SSH accept passwords.** Keep `-s`.
- **Don't leave maintenance mode on permanently.** It will drain the battery.
- **Don't assume the service on the computer comes back after a power cut.** Check the login screen and disk encryption.
- **Don't change the init script without an emergency route** (the `AUTOSTART` file as a kill switch and a script that repairs `/etc/init.d` via the cable).
- **Don't copy the whole USBNetwork package** with its installer. You only need `dropbearmulti`, `libz.so.1` and your own `authorized_keys`.
- **Don't expose the board server outside the home network.** A token in the URL is not real protection.

## 11. Quick checklist

Before the first upload:

- [ ] Kindle jailbroken, the hotfix scripts run.
- [ ] The server on the computer answers `200` for every board (`curl`).
- [ ] The computer has a fixed IP address, written into `config.sh`.
- [ ] The server starts right away, drawing happens in the background.

Upload:

- [ ] Home on the Kindle first, only then the cable.
- [ ] Copied: `dashboard/*`, `usbnet/bin/dropbearmulti`, `usbnet/lib/libz.so.1`, `usbnet/etc/authorized_keys`.
- [ ] `sshd.sh` has `iptables` rules for tcp/22 and icmp.
- [ ] The `AUTOSTART` file exists.
- [ ] Init script in `/etc/init.d/dashboard` and the link in `rc5.d` (once, `mntroot rw`).

First run:

- [ ] Restart the Kindle (Menu, Settings, Menu, Restart), don't press anything for a minute.
- [ ] Requests from the Kindle show up in the server log.
- [ ] `ping` and `ssh` to the Kindle work. If not: the firewall first.
- [ ] The keys switch boards, the middle one refreshes, Home goes back to the shelf.
- [ ] When you're done: delete the `MAINT` file on the server.
