Repository navigation
ocpp: OCPP 1.6J Central System for EV chargers (EV Unit 4/5) - #37
Conversation
Embeds a WebSocket OCPP 1.6J central system into 42W, so any OCPP-1.6J
charger (Easee Native OCPP, Wallbox, Alfen, Schrack, Mennekes, Keba,
go-e via OCPP) can connect directly without a per-vendor Lua driver.
Per-charger MeterValues + StatusNotification are translated into DerEV
readings in telemetry.Store. The dispatch clamp added in Unit 3 picks
those up automatically — when the EV draws power, home batteries stop
discharging into the car. Read-only (Phase 1): RemoteStartTransaction
and SetChargingProfile are deferred to Phase 2.
Backed by github.com/lorenzodonini/ocpp-go (the same library SteVe
uses). Pure Go, no CGo. ~290 LOC of our own code; the library handles
the WebSocket + JSON layer.
Config (all optional, disabled by default):
ocpp:
enabled: true
bind: 0.0.0.0
port: 8887
username: easee
password: <secret>
heartbeat_interval_s: 60
Charge points connect to ws://<bind>:<port>/<chargerId>. The chargerId
becomes the driver name in /api/devices and /api/status.drivers.
Tests:
- TestBootAndMeterValuesPushDerEV — boot + status + meter → DerEV
- TestStartStopTransactionTracksSession — session_wh accounting
- TestBasicAuthRejectsWrongCredentials — auth gate works
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5c3156aba2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "bind", cfg.Bind, "port", cfg.Port, "path", cfg.Path, | ||
| "basic_auth", cfg.Username != "") | ||
| // cs.Start blocks until cs.Stop is called. | ||
| s.cs.Start(cfg.Port, fmt.Sprintf("%s{ws}", cfg.Path)) |
There was a problem hiding this comment.
Honor configured bind address for OCPP listener
Start advertises cfg.Bind as a runtime setting, but listener startup ignores it and only passes cfg.Port and path to s.cs.Start(...). As written, ocpp.bind cannot constrain where the socket is exposed, so operators who set a specific bind address (for example loopback/LAN-only) do not get the behavior they configured. Please wire the bind address into server startup (or reject/remove the option) so configuration and network exposure match.
Useful? React with 👍 / 👎.
| case core.ChargePointStatusAvailable, core.ChargePointStatusUnavailable: | ||
| s.connected = false | ||
| s.charging = false | ||
| case core.ChargePointStatusPreparing, |
There was a problem hiding this comment.
Zero EV power on Available/Unavailable status updates
In OnStatusNotification, the Available/Unavailable branch flips connected/charging but leaves lastPowerW untouched before calling pushReading. If the previous meter sample was non-zero and the charger does not send a subsequent zero-power sample (or StopTransaction is missed), the control loop keeps subtracting stale EV watts and can continue clamping batteries unnecessarily. Reset lastPowerW when entering these non-charging statuses.
Useful? React with 👍 / 👎.
|
🎉 This PR is included in version 2.0.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
* refactor(control): remove the priority and weighted modes - #7 priority/weighted: remove ModePriority and ModeWeighted, State.PriorityOrder and Weights, distributePriority/distributeWeighted, their revision hashing, catalogue, contract registry and HA select entries, and the never-read batteries.<name>.weight setting and its Settings field. Priority held every battery at its measured power because nothing set its order. A stored priority or weighted mode boots as self_consumption, is saved back and logged once; the API, HA and the app refuse both. Their 60 golden records are dropped (611 -> 551, deletions only) and the e2e target-following step runs in self_consumption. - #34 HA mode: haCallbacks.SetMode now calls appModes.SetMode, so it goes through control.ApplyMode, only logs a failed save, still applies the export preference and replans without blocking the MQTT handler. - #36 UseCascade: delete the unread control.State field and its initializer. - #37 use_energy_dispatch: drop the deprecated key. Loading YAML or stored settings turns it into planner.legacy_dispatch (the old key still wins), DropRetiredSettings deletes it and battery weights from state.db, and one energyDispatchEnabled helper serves boot and hot reload, which no longer keeps the legacy path after the planner section is removed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MuerPFZFG88kgu8sWVHeq7 * chore: drop an accidental node_modules symlink Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MuerPFZFG88kgu8sWVHeq7 --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
42W now embeds an OCPP 1.6J Central System. Any OCPP-1.6J charger (Easee Native OCPP, Wallbox, Alfen, Schrack, Mennekes, Keba, go-e via OCPP) connects directly to `ws://<42w-ip>:8887/` and starts pushing telemetry. No per-vendor Lua driver needed.
This is the local-first answer to EV integration: the charger speaks to a local server on your LAN, not Easee Cloud.
What it does
Phase 1 boundaries (intentional)
Config
```yaml
ocpp:
enabled: true
bind: 0.0.0.0
port: 8887
username: easee
password:
heartbeat_interval_s: 60
```
Disabled by default (`cfg.OCPP` nil → server doesn't start).
Test plan
Builds on the merged plumbing in #34, #35, #36. Unit 5 (UI card + HA sensors) ships next.
🤖 Generated with Claude Code