3.1 KiB
3.1 KiB
Web UI & REST API
Server Architecture
- Router: gorilla/mux, strict slash
- Middleware: GZIP, CORS (
*), ETag caching, request logging, JSON headers, JWT auth - Timeouts: Read 5s, Write 10s, Idle 120s
- Static assets: embedded in binary (
fs.FS) - Default port: 7070
REST API (base /api/)
Site-level
POST /buffersoc/{value},/prioritysoc/{value},/residualpower/{value}etc.GET /tariff/{tariff}— tariff ratesGET /sessions— charging historyGET /state— complete system state (supports jq filtering)
Per-loadpoint (/loadpoints/{id}/...)
POST mode/{value}— off/now/minpv/pvPOST limitsoc/{value},limitenergy/{value}— charge limitsPOST mincurrent/{value},maxcurrent/{value}— current limitsPOST phases/{value}— phase configPOST priority/{value},batteryboost/{value}POST plan/energy/{value}/{time}— schedule planPOST vehicle/{name}— select vehiclePOST smartcostlimit/{value}— smart cost threshold
Configuration (/config/..., auth required)
- CRUD for devices (chargers, meters, vehicles, tariffs)
- Template browsing and testing
- Site, loadpoint, circuit, HEMS, messaging config
GET /config/evcc.yaml— YAML export
System (/system/..., auth required)
- Log viewing (
/log,/log/areas), cache clear, shutdown
Database (/db/..., auth + second factor required)
- Backup download, restore from file, selective reset
- Second factor: admin password in request body, or API key via Bearer token (bypasses password check)
Handler Pattern
Generic handler[T] with type conversion, setter, getter.
Specialized: floatHandler, intHandler, boolHandler, durationHandler.
WebSocket (/ws)
coder/websocket(RFC 6455)- Pub/sub via
SocketHub - Buffered channels (1024 per subscriber)
- Welcome message with full state snapshot
- Incremental updates as JSON key-value pairs with dot-notation keys:
{"loadpoints.1.mode": "solar", "site.gridPower": 1234} - Write timeout: 10s, compression (disabled for Safari)
State Flow
- WS connects -> receives welcome with full state
- App emits
util.Paramon changes - Hub broadcasts to subscribers
- Frontend
store.update(msg)merges via dot-notation - Components reactively re-render
Authentication
- JWT, 90-day lifetime
- HttpOnly cookie (
auth) withSameSite=Strict - Also accepts
Authorization: Bearer <token>header - Modes: Disabled, Locked (demo), Configured (password)
- Protects
/api/config,/api/system, and/api/db
MQTT Integration
- Publishes state changes to configurable broker
- Subscribes to control topics
- Retained messages for state persistence
Key Files
server/http.go— router setupserver/http_auth.go— authenticationserver/http_site_handler.go— state + request handlersserver/http_config_*.go— config endpointsserver/http_loadpoint_handler.go— per-loadpoint endpointsserver/socket.go— WebSocket pub/subassets/js/app.ts— Vue app entryassets/js/store.ts— reactive state storeassets/js/api.ts— Axios clientsassets/js/router.ts— route definitions