# epaper-e100x-demos

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
![Platform](https://img.shields.io/badge/platform-ESP32--S3-blue)
![Firmware](https://img.shields.io/badge/firmware-MicroPython%20v1.25-orange)
![Hardware](https://img.shields.io/badge/hardware-reTerminal%20E1001-green)
![Network](https://img.shields.io/badge/network-local%20only-brightgreen)

Open-source demos for the **Seeed reTerminal E100x** e-paper series (E1001 / E1002 / E1003), focused on **local-network-first architectures**: no cloud, no MQTT broker, no external APIs — the display pulls a pre-rendered image from a host on your LAN and goes back to sleep.

## Why

The stock workflows for this hardware (SenseCraft HMI, ESPHome YAML lambdas, MQTT push pipelines) put layout, fonts, and business logic *inside the device firmware*. Every UI change means a recompile and reflash, CJK text means maintaining glyph tables, and the whole pipeline breaks when the broker or the internet goes away.

These demos flip the model:

```
┌─────────────────────┐      HTTP      ┌──────────────────────┐
│   LAN host           │  /dashboard   │   reTerminal E1001   │
│  (any machine)       │ ◄──────────── │     (ESP32-S3)       │
│                      │  1-bit raw    │                      │
│  Pillow renders      │               │  fetch → cache →     │
│  the dashboard image │               │  refresh → deepsleep │
└─────────────────────┘               └──────────────────────┘
```

- **Device is a dumb frame**: fetch an image over HTTP, show it, cache it to flash, deep-sleep.
- **Host owns everything else**: layout, fonts, data sources, business logic — all in one Python script you can edit without touching the device.
- **Offline-tolerant**: if the host is down, the device keeps showing the last cached image. The host never needs to know whether the device is online.
- **Local-only**: no internet dependency on either side.

## Demos

| Demo | Description | Status |
|---|---|---|
| [`host/` + `device/`](host/) | **MCV Dashboard** — minimalist current-city display for a mobile base vehicle. One big centered city name, day counter, clock. | ✅ Working |

More demos (weather station, calendar, photo frame with dithering) are planned — see [Roadmap](#roadmap).

### MCV Dashboard preview

![MCV Dashboard](docs/mcv-dashboard-preview.png)

## Hardware

- **Seeed reTerminal E1001** — 7.5" monochrome e-paper, 800×480, ESP32-S3 (N8R8: 8MB flash + 8MB Octal PSRAM)
- Any LAN host capable of running Python (Raspberry Pi, NAS, Home Assistant box, laptop)

The display panel is a Waveshare 7.5" V2 variant; the driver in [`device/epd.py`](device/epd.py) matches its SPI timing and command set.

## Quick Start

### 1. Host side

Requires [uv](https://docs.astral.sh/uv/) and the Noto Sans CJK / Noto Sans Mono fonts (preinstalled on most Linux desktops; otherwise `pacman -S noto-fonts-cjk noto-fonts` or your distro's equivalent).

```bash
cd host
./dashboard_server.py
```

Endpoints:

- `http://<host-ip>:8124/dashboard.png` — browser preview (debug)
- `http://<host-ip>:8124/dashboard.bin` — 48,000-byte 1-bit raw image (device pulls this)

The `.bin` endpoint supports `ETag` / `If-None-Match` and returns `304 Not Modified` when nothing changed.

### 2. Device side

```bash
cd device

# 1. Edit main.py: WIFI_SSID / WIFI_PASS / SERVER_URL

# 2. Connect the reTerminal over USB-C

# 3. One-shot flash (downloads firmware, erases, flashes, uploads files)
./flash.sh
```

Step-by-step variants:

```bash
./flash.sh firmware   # flash MicroPython only (hold BOOT → tap RESET to enter download mode first)
./flash.sh files      # upload main.py / epd.py / boot.py only
./flash.sh repl       # open REPL for debugging
PORT=/dev/ttyACM0 ./flash.sh   # specify serial port manually
```

> **Firmware variant matters**: the reTerminal E1001 uses an ESP32-S3 **N8R8** with Octal PSRAM. `flash.sh` pins the `ESP32_GENERIC_S3-SPIRAM_OCT` build — a plain build will boot but won't see the PSRAM.

### 3. Change what's displayed

Edit `host/trip.json`:

```json
{
  "start_date": "2026-04-22",
  "current": 9,
  "stops": [
    {"cn": "深圳", "en": "Shenzhen"},
    {"cn": "成都", "en": "Chengdu"}
  ]
}
```

`current` is the index into `stops`. The host picks it up on the next render; the device picks it up on its next wake cycle (default: every 5 minutes). No device reflash needed.

## Repository layout

```
├── host/                    # LAN host: image renderer + HTTP server
│   ├── dashboard_server.py  #   Flask app, Pillow renderer (PEP 723, runs via uv)
│   ├── trip.json            #   data source: city list + current index
│   └── state.json           #   reserved state file
├── device/                  # reTerminal E1001: MicroPython firmware
│   ├── main.py              #   Wi-Fi → HTTP fetch → flash cache → refresh → deep sleep
│   ├── epd.py               #   Waveshare 7.5" V2 driver (800×480, 1-bit)
│   ├── boot.py              #   boot entry
│   └── flash.sh             #   one-shot flashing script (esptool + mpremote via uv)
├── docs/                    # preview images
└── LICENSE
```

## Design notes

- **Image format**: raw 1-bit, 800×480 = 48,000 bytes. No PNG/JPEG decoder needed on the device — bytes go straight to the panel framebuffer.
- **Power profile**: ESP32-S3 deep sleep (~10–100 µA) + e-paper image retention → months of battery life with a 5-minute refresh cadence.
- **Grayscale content**: photos and avatars are dithered host-side with Pillow (`img.convert("1", dither=Image.FLOYDSTEINBERG)`); text and geometry are rendered 1-bit natively.
- **No OTA by design**: the device logic (fetch → show → sleep) is deliberately frozen. All behavioral changes happen in host-side rendering.

## Roadmap

- [ ] Weather station demo (local Home Assistant weather entity)
- [ ] Photo frame demo with Floyd–Steinberg dithering
- [ ] Partial refresh support in `epd.py`
- [ ] E1002 (Spectra 6 color) variant
- [ ] Web-based layout editor generating host configs

## License

[MIT](LICENSE)
