HPRT CP4x printer bridge: UDP discover, connect, print JPEG, cancel, SSE status/logs, Wi-Fi diag
117
HTTP bridge for HPRT CP4x Wi‑Fi photo printers (CP4100 and family).
Web browsers cannot open raw TCP/UDP sockets, and these printers only speak a binary protocol over TCP and UDP. This service speaks that protocol for you and exposes a simple HTTP + SSE API, so a web app (like PhotoPrint) can find, connect to and print on the printer.
Web app ── HTTP + SSE ──► hprt-open-bridge ── TCP 9901 / 9100 · UDP 6000 ──► printer
docker stop closes the streams, waits for running requests and releases the printer.The container needs the host network: UDP discovery and the printer on your LAN cannot be reached through Docker's NAT network.
docker run -d --name hprt-open-bridge --network host andresramirez991228/hprt-open-bridge
curl http://localhost:8787/api/state
With the Wi‑Fi diagnostics (they talk to the NetworkManager of the host through D‑Bus):
docker run -d --name hprt-open-bridge --network host \
--security-opt apparmor=unconfined \
-v /run/dbus/system_bus_socket:/run/dbus/system_bus_socket \
andresramirez991228/hprt-open-bridge
bridge:
container_name: bridge
image: andresramirez991228/hprt-open-bridge:v1.1.0
network_mode: host # UDP discovery and the printer on the LAN need the host network
environment:
BRIDGE_APP_REST_ADDR: 0.0.0.0:8787
volumes:
# nmcli in the container asks the NetworkManager of the Raspberry through D-Bus (Wi-Fi scan, host Wi-Fi, hotspot gateway)
- /run/dbus/system_bus_socket:/run/dbus/system_bus_socket
security_opt:
# The default AppArmor profile of Docker blocks D-Bus (harmless where AppArmor is not active)
- apparmor:unconfined
restart: unless-stopped
Every setting can be changed with an environment variable BRIDGE_<SECTION>_<KEY>:
| Variable | Default | Description |
|---|---|---|
BRIDGE_APP_REST_ADDR | 0.0.0.0:8787 | Address and port of the API |
BRIDGE_APP_SHUTDOWN_TIMEOUT | 10s | Time to finish running requests on stop |
BRIDGE_LOGGER_LEVEL | info | debug also prints every protocol line |
BRIDGE_LOGGER_AS_JSON | false | JSON logs instead of text |
BRIDGE_CORS_ENABLED | true | Add CORS headers |
BRIDGE_CORS_ALLOWED_ORIGINS | * | Comma separated list of allowed origins |
BRIDGE_PRINTER_WAKE_WINDOW | 45s | How long to wait for a sleeping printer |
BRIDGE_PRINTER_HEARTBEAT_INTERVAL | 3s | Interval of the status heartbeat |
BRIDGE_PRINTER_PRINT_TIMEOUT | 240s | Longest time for a whole print job |
BRIDGE_PRINTER_RETRY_WAIT | 90s | How long an interrupted job waits for the reconnection |
BRIDGE_ACTIVITY_LOG_BUFFER | 200 | Protocol log lines kept in memory |
You can also mount your own file at /app/config.yaml.
| Method | Path | Description |
|---|---|---|
GET | /api/state | Connection snapshot: printer, status, link quality |
GET | /api/events | SSE stream with state, job and log events |
GET | /api/logs | Recent protocol log |
GET | /api/discover?timeout=&target= | Find printers on the LAN |
POST | /api/connect | Connect: {"ip": "192.168.1.50", "sn": "…", "wakeMs": 8000} |
POST | /api/disconnect | Close the session |
POST | /api/print | Print the JPEG in the body (image/jpeg); answers when the printer finishes |
POST | /api/cancel | Cancel the running job |
GET | /api/link?ip= | Ping test, Wi‑Fi of the host and heartbeat statistics |
GET | /api/gateway | Gateway of the host (the printer itself in hotspot mode) |
GET | /api/wifi/scan | Wi‑Fi networks seen by the host, 2.4 GHz first |
Example:
curl -X POST localhost:8787/api/connect -H 'Content-Type: application/json' -d '{"ip":"192.168.1.50"}'
curl -X POST localhost:8787/api/print -H 'Content-Type: image/jpeg' --data-binary @photo.jpg
The JPEG must already have the size of the page: 1232 × 1786 px (100 × 148 mm at 300 dpi). Most models expect the image rotated 180°.
Errors always have the same shape:
{"error": "No printer connected", "module": "printer", "internal_code": 1003, "message": "No printer connected", "http_code": 409}
network_mode: host).Content type
Image
Digest
sha256:7fa16e88c…
Size
17.4 MB
Last updated
17 days ago
docker pull andresramirez991228/hprt-open-bridge:v1.1.0