feat(rest): simplify web ui and prune non-core endpoints

This commit is contained in:
admin
2026-02-28 21:52:11 +08:00
parent 421fd9da62
commit d6fae38d46
9 changed files with 282 additions and 2308 deletions

115
README.md
View File

@@ -10,7 +10,7 @@ ESP32-S3 works as a Wi-Fi REST controller and replaces Android App logic:
## Features
- Wi-Fi STA-only mode (configured SSID/password; no SoftAP fallback)
- Built-in web UI at `/` for connect/status, text print, and Z-Image prompt print
- Built-in minimal web UI at `/` for voice tap2talk
- BLE central client auto-scan/connect to printer name
- Async print queue with jobs (`queued/running/success/failed/canceled`)
- Printer precheck (paper / battery / temperature)
@@ -26,6 +26,8 @@ ESP32-S3 works as a Wi-Fi REST controller and replaces Android App logic:
- `0x00` power off
- `0x02` feed paper
- REST APIs:
- Root:
- `GET /`
- Health/connection:
- `GET /v1/health`
- `POST /v1/printer/connect`
@@ -34,26 +36,10 @@ ESP32-S3 works as a Wi-Fi REST controller and replaces Android App logic:
- Print:
- `POST /v1/print/raster`
- `POST /v1/print/image` (JSON prompt -> generate image -> print, also compatible with direct PNG binary upload)
- `POST /v1/print/qr`
- `POST /v1/print/text`
- `POST /v1/print/receipt`
- `POST /v1/print/label`
- Jobs:
- `GET /v1/jobs`
- `DELETE /v1/jobs`
- `GET /v1/jobs/{id}`
- `DELETE /v1/jobs/{id}`
- Label control:
- `POST /v1/label/gap_move`
- `GET /v1/label/offset`
- `POST /v1/label/offset`
- OTA:
- `GET /v1/ota/version`
- `POST /v1/ota/jump_boot`
- `POST /v1/ota/jump_app`
- `POST /v1/ota/erase_page`
- `POST /v1/ota/write_frame`
- `POST /v1/ota/upgrade`
- Voice:
- `GET /v1/voice/status`
- `POST /v1/voice/session/start`
@@ -147,14 +133,9 @@ Open the controller IP in a browser:
http://<esp-ip>/
```
The page provides:
- health/status check
- connect/disconnect printer
- submit a simple text print job
- input an image prompt, then let ESP32-S3 call DashScope Z-Image, download PNG, decode/threshold/scale/raster conversion, and print
- view jobs list
If API key is enabled, input it in the page before invoking actions.
The page provides a minimal voice console:
- single-round tap2talk button
- voice status display
## REST Examples
@@ -222,19 +203,6 @@ Request constraints:
- Request body limit: 4 MB
- Suggested image size: <= 3 MB when using direct PNG upload compatibility mode
### QR print
```bash
curl -X POST http://<esp-ip>/v1/print/qr \
-H 'Content-Type: application/json' \
-d '{
"text":"https://example.com/pay/123",
"ecc":"H",
"module_scale":0,
"margin_modules":2,
"density":"中等"
}'
```
### Text print
```bash
curl -X POST http://<esp-ip>/v1/print/text \
@@ -248,74 +216,10 @@ curl -X POST http://<esp-ip>/v1/print/text \
}'
```
### Receipt print
```bash
curl -X POST http://<esp-ip>/v1/print/receipt \
-H 'Content-Type: application/json' \
-d '{
"title":"TQ FOOD",
"density":"中等",
"footer":"Thanks!",
"items":[
{"name":"DishA","qty":2,"price":12.5},
{"name":"DishB","qty":1,"price":8.0}
]
}'
```
### Label print (with optional gap/offset)
```bash
curl -X POST http://<esp-ip>/v1/print/label \
-H 'Content-Type: application/json' \
-d '{
"width":384,
"height":260,
"encoding":"base64_msb_1bpp",
"data":"<BASE64_BYTES>",
"gap_move_before":true,
"offset_tenths_mm":128,
"density":"中等"
}'
```
### Jobs
```bash
curl http://<esp-ip>/v1/jobs
curl http://<esp-ip>/v1/jobs/1
curl -X DELETE http://<esp-ip>/v1/jobs/1
curl -X DELETE http://<esp-ip>/v1/jobs -d '{"include_success":true,"include_failed":true,"include_canceled":true}'
```
### Label control
```bash
curl -X POST http://<esp-ip>/v1/label/gap_move
curl http://<esp-ip>/v1/label/offset
curl -X POST http://<esp-ip>/v1/label/offset \
-H 'Content-Type: application/json' \
-d '{"offset_tenths_mm":128}'
```
### OTA primitives
```bash
curl http://<esp-ip>/v1/ota/version
curl -X POST http://<esp-ip>/v1/ota/jump_boot
curl -X POST http://<esp-ip>/v1/ota/erase_page -H 'Content-Type: application/json' -d '{"page_num":0}'
curl -X POST http://<esp-ip>/v1/ota/write_frame -H 'Content-Type: application/json' -d '{"packet_num":0,"is_last_frame":false,"data":"<BASE64_<=236_BYTES>"}'
curl -X POST http://<esp-ip>/v1/ota/jump_app
```
### OTA full upgrade
```bash
curl -X POST http://<esp-ip>/v1/ota/upgrade \
-H 'Content-Type: application/json' \
-d '{
"firmware":"<BASE64_FIRMWARE>",
"jump_boot":true,
"jump_app":true,
"page_size":1024,
"packet_size":236,
"timeout_ms_per_step":5000
}'
```
### Voice tap2talk
@@ -354,13 +258,12 @@ curl -X POST http://<esp-ip>/v1/voice/session/stop
- BLE side is central/client role, not printer peripheral role.
- `base64_msb_1bpp` uses Android-compatible bit order (MSB first).
- `/v1/print/image` supports two modes: JSON prompt generation (DashScope Z-Image) and raw `image/png` upload (no base64 wrapper).
- `/v1/print/text` supports UTF-8 Chinese via embedded 16x16 GB2312 glyphs.
- Characters outside embedded glyph set are rendered as square fallback boxes.
- Large buffers for image upload/decode prefer PSRAM first, then fallback to internal RAM.
- Partition table uses `partitions.csv` with a 4MB `factory` app partition on 16MB flash modules.
- `/v1/print/text` and `/v1/print/receipt` now support UTF-8 Chinese via embedded 16x16 GB2312 glyphs.
- Characters outside embedded glyph set are rendered as square fallback boxes.
- QR encoding uses embedded `qrcodegen` (Project Nayuki C implementation).
- Voice flow is now single-round: audio uplink stops after `SpeechEnded`, then `LocalRespondingEnded` and `Stop` are sent after local playback drain.
- Web UI blocks starting the next voice round while voice is Thinking/Responding, marker image generation is running, or printer queue is still busy.
- Voice flow blocks starting the next round while voice is Thinking/Responding, marker image generation is running, or printer queue is still busy.
## Font Assets