kirby-ocpp 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026
3
+ Copyright (c) 2026 Kirill Belolipetsky
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -23,7 +23,7 @@ With Cargo (Rust 1.88 or newer):
23
23
  cargo install kirby-ocpp
24
24
  ```
25
25
 
26
- Or download a prebuilt binary for Linux, macOS or Windows from the [GitHub releases](https://github.com/archhaze24/kirby-ocpp/releases). To build from a checkout: `cargo install --path crates/kirby-ocpp`.
26
+ Or download a prebuilt binary for Linux (x86_64 glibc, aarch64 glibc, x86_64 static musl for Alpine and minimal containers), macOS or Windows from the [GitHub releases](https://github.com/archhaze24/kirby-ocpp/releases). To build from a checkout: `cargo install --path crates/kirby-ocpp`.
27
27
 
28
28
  ## Quick start
29
29
 
@@ -48,11 +48,14 @@ kirby-ocpp --url ws://localhost:9000/ocpp run --scenario charge-session
48
48
  | `-c, --connector` | | `1` | Initial connector |
49
49
  | `--connectors` | | `1` | Number of connectors |
50
50
  | `--heartbeat` | | `30` | Fallback heartbeat interval (s) |
51
+ | `--nominal-power-w` | | `7200` | Nominal charging power per connector (W); charging profiles can only lower it |
52
+ | `--voltage-v` | | `230` | Voltage per phase (V), used for A to W conversion and the `Voltage` reading |
53
+ | `--phases` | | `1` | Number of phases (1-3) |
51
54
  | `--ws-subprotocol` | `OCPP_WS_SUBPROTOCOL` | `ocpp1.6` | Requested subprotocol |
52
55
  | `--ws-ping` | `OCPP_WS_PING_INTERVAL` | `30` | WebSocket ping interval (s), `0` disables |
53
56
  | `--reconnect <BOOL>` | `OCPP_RECONNECT` | `true` | Auto-reconnect after unexpected disconnect |
54
57
  | `--no-reconnect` | | | Disable auto-reconnect (wins over `--reconnect`) |
55
- | `--reconnect-initial-ms` | `OCPP_RECONNECT_INITIAL_MS` | `1000` | Initial backoff |
58
+ | `--reconnect-initial-ms` | `OCPP_RECONNECT_INITIAL_MS` | `1000` | Initial backoff; `0` is rejected (exit 2) unless `--reconnect-max-attempts` is set or reconnect is off |
56
59
  | `--reconnect-max-ms` | `OCPP_RECONNECT_MAX_MS` | `30000` | Maximum backoff |
57
60
  | `--reconnect-max-attempts` | `OCPP_RECONNECT_MAX_ATTEMPTS` | `0` | `0` = unlimited |
58
61
  | `--call-timeout-ms` | `OCPP_CALL_TIMEOUT_MS` | `30000` | CALL response timeout |
@@ -62,6 +65,11 @@ kirby-ocpp --url ws://localhost:9000/ocpp run --scenario charge-session
62
65
  | `--tls-skip-verify` | `OCPP_TLS_SKIP_VERIFY` | off | Skip certificate verification (testing only) |
63
66
  | `--no-persist` | `KIRBY_OCPP_NO_PERSIST` | off | Do not load or save station state |
64
67
  | `--state-dir` | `KIRBY_OCPP_STATE_DIR` | `~/.kirby-ocpp/stations` | State directory (`%USERPROFILE%` on Windows) |
68
+ | `--count` | `OCPP_COUNT` | `1` | Number of stations (fleet mode, 1-1000), see [Fleet mode](#fleet-mode) |
69
+ | `--id-template` | `OCPP_ID_TEMPLATE` | the `--id` value | Charge point id template with `{n}` / `{n:03}` |
70
+ | `--first-index` | `OCPP_FIRST_INDEX` | `1` | Index of the first station |
71
+ | `--stagger-ms` | `OCPP_STAGGER_MS` | `0` | Delay between starting two stations (ms) |
72
+ | `--rule ACTION=BEHAVIOR[*N]` | `KIRBY_OCPP_RULES` (`;` separates rules) | none | Response rule for a CSMS command, repeatable; see [Response rules](#response-rules) |
65
73
  | `--print-config` | | | Print the effective configuration as JSON and exit |
66
74
  | `--no-tui` | | | Never start the TUI; log to stdout |
67
75
  | `--json` | | | JSON lines instead of text (events and the `run` report) |
@@ -77,7 +85,7 @@ Options are global and may be placed before or after a subcommand.
77
85
 
78
86
  ## State persistence
79
87
 
80
- Per charge point id, one JSON file `<state dir>/<id>.station.json` holds the local authorization list and its version, authorization cache, charging profiles, writable configuration values, availability, connector count and per-connector state (status, meter, reservation, transaction) and the offline transaction queue. Files are versioned and written atomically (temp file plus rename); a corrupt file or one belonging to another charge point is moved to `<file>.bak` and the station starts clean. `--no-persist` disables both loading and saving.
88
+ Per charge point id, one JSON file `<state dir>/<id>.station.json` holds the local authorization list and its version, authorization cache, charging profiles, writable configuration values, availability (including a `Scheduled` change waiting for a transaction to end), connector count and per-connector state (status, meter, reservation, transaction) and the offline transaction queue. Ids whose escaped name would exceed 100 bytes are shortened and get a hash suffix (`...~<16 hex>.station.json`) so the name always fits the filesystem limit. Files are versioned and written atomically (temp file plus rename, then the directory is fsynced); a corrupt file or one belonging to another charge point is moved to `<file>.bak` and the station starts clean. `--no-persist` disables both loading and saving.
81
89
 
82
90
  ## Terminal UI
83
91
 
@@ -94,7 +102,17 @@ Seven tabs, switched with `1`-`7` or `Tab`/`Shift-Tab`: Station, Connector, Tran
94
102
  | `?` | Help |
95
103
  | `q`, `Ctrl-C` | Quit |
96
104
 
97
- Actions: connect/disconnect/reconnect, BootNotification, Heartbeat, add connector; plug/unplug, set status, StatusNotification, fault toggle; Authorize, StartTransaction, StopTransaction (with reason), MeterValues; set diagnostics/firmware outcome and send their status notifications; DataTransfer, vendor ping and raw CALLs.
105
+ Actions: connect/disconnect/reconnect, BootNotification, Heartbeat, add connector, response rules (`m` adds one, `Action=off` removes one, `M` clears all; active rules are listed in the Station pane); plug/unplug, set status, StatusNotification, fault toggle; Authorize, StartTransaction, StopTransaction (with reason), MeterValues; set diagnostics/firmware outcome and send their status notifications; DataTransfer, vendor ping and raw CALLs.
106
+
107
+ Data browser (Station tab: `K` config keys, `L` local authorization list, `P` charging profiles; also in the palette): one popup with three pages, switched with `Tab`/`Shift-Tab`, `Left`/`Right` or `1`-`3`. `/` filters the rows fuzzily (`Enter` keeps the filter, `Esc` clears it), `Up/Down`/`j/k`/`PageUp/PageDown`/`g`/`G` move, `Esc`/`q` closes. Forms and confirmations opened from the browser return to it. Edits are local commands that behave like the CSMS-triggered ones, without a CSMS round trip:
108
+
109
+ | Page | Keys |
110
+ | --- | --- |
111
+ | Config keys | `Enter`/`e` edits the selected key (read-only keys are marked `(ro)` and refuse); the value is checked live with the station's own rules, as `ChangeConfiguration` would, and applied with the same side effects (heartbeat/metering timers) and persistence |
112
+ | Local auth list | `a` adds, `Enter`/`e` edits (idTag, status, expiry, parent), `d` removes, `c` clears (asks first). Each add/edit/remove is a differential update that bumps the list version by one; clear empties the list and resets the version to 0 |
113
+ | Charging profiles | `i` installs a profile from JSON (a template is prefilled; paste your own: `csChargingProfiles` object plus connector, validated against the `SetChargingProfile` schema and the station's profile rules), `e` edits the selected one (same id replaces it), `Enter` shows its JSON (`c` there copies), `d` deletes it, `c` clears all (asks first) |
114
+
115
+ The snapshot behind it (`Snapshot::config`, `local_list`, `charging_profiles`) is also available to API users; the local list view holds at most 500 entries (`total` has the real count).
98
116
 
99
117
  Log view (Logs tab): CALL/RESULT/ERROR correlation, filters (all, calls, errors, station, csms; `f`), search (`s`), pause/follow (`p`), jump to newest (`G`), detail view with scroll (`Enter`; `c`/`y` copies), copy row (`y`) or visible rows (`Y`), export as JSONL (`e`, default `./kirby-ocpp-<id>-<timestamp>.jsonl`), clear with confirmation (`c`). The buffer keeps the last 2000 entries. Copying tries external clipboard tools first and falls back to the terminal's OSC 52 sequence.
100
118
 
@@ -111,10 +129,36 @@ Without a TTY (or with `--no-tui`) the tool connects and prints events until SIG
111
129
  | 0 | Success (scenario passed, normal shutdown) |
112
130
  | 1 | Scenario failed or timed out, or a runtime error |
113
131
  | 2 | Usage or configuration error |
132
+ | 130 | `run` interrupted by SIGINT (Ctrl-C); SIGTERM still ends it with 1 |
133
+
134
+ ## Fleet mode
135
+
136
+ `--count N` runs N independent stations in one process against the same CSMS, for load and multi-station tests (terminal UI on a TTY, headless with `--no-tui` or without one).
137
+
138
+ ```
139
+ kirby-ocpp --url ws://localhost:9000/ocpp --id 'CP-{n:03}' --count 50 --stagger-ms 100 --no-tui
140
+ kirby-ocpp --url ws://localhost:9000/ocpp --id 'CP-{n}' --count 20 run --scenario charge-session
141
+ ```
142
+
143
+ - The id comes from `--id-template`, or from `--id` when no template is given. `{n}` is the station index, `{n:03}` the index zero-padded to 3 digits; `{{` and `}}` are literal braces. With `--count` above 1 the template needs a placeholder (otherwise exit 2). `--first-index` (default 1) is the index of the first station, so `--count 3 --first-index 10` gives `CP-10`, `CP-11`, `CP-12`. `--count 1` without `--id-template` uses `--id` as is; with an explicit template it is expanded too.
144
+ - Every station is a normal station (own connection, transactions, state file named after its id, so state files never collide). `--stagger-ms` waits that long between starting two stations.
145
+ - The terminal UI shows a selector row on top (`1 CP-001+* 2 CP-002- ...`: index, id, connection glyph `+` connected, `~` connecting/retrying, `-` offline, `*` a transaction is running) and the selected station below. Everything else (status, log, actions, `K`/`L`/`P` browsers, forms, scenarios) works on the selected station only; each station keeps its own log (last 500 rows), dialogs and scenario progress, and events of the other stations keep being recorded. `Alt` combinations may need "Option as Meta" in macOS terminals. With `--count 1` there is no selector and no extra keys. Quit stops the whole fleet.
146
+ - Output is tagged with the station id: `[CP-001] ...` in front of every human line, a `"station"` field in every JSON line, stdout and `--log-file` alike. With `--count 1` nothing is tagged.
147
+ - `run --scenario` runs the scenario on every station at the same time and prints one report per station (tagged), then one aggregate line: `fleet: 3/3 stations PASSED`, or `fleet: 2/3 stations passed, FAILED: CP-2`. With `--json` the aggregate is `{"type":"fleet_report","passed":bool,"total":n,"passed_count":n,"failed":[ids],"stations":[...]}`. `--timeout` covers the whole fleet, stagger included. `--report out.json` writes one file per station: `out.CP-001.json` (characters of the id other than letters, digits, `-` and `_` become `_`).
148
+
149
+ | Fleet key | Action |
150
+ |---|---|
151
+ | `<` `>` | Previous / next station |
152
+ | `Alt-1` .. `Alt-9` | Jump to station 1..9 |
153
+ | `Alt-c` / `Alt-d` | Connect / disconnect all stations |
154
+
155
+ Selector keys work in normal mode only (inside a dialog they are plain input).
156
+ - Exit codes: 0 only if every station passes, 1 if any fails or times out, 2 usage error, 130 SIGINT.
157
+ - `--print-config` with `--count > 1` prints `{"fleet": {...}, "config": {...}}` where `config` is the first station.
114
158
 
115
159
  ## Scenarios
116
160
 
117
- `kirby-ocpp scenarios list` lists the built-in scenarios (`charge-session`, `fault-recovery`, `finish-session`, `offline-sync`); `kirby-ocpp scenarios show <name>` prints one as TOML. Built-ins target connector 1 unless `--connector` is given.
161
+ `kirby-ocpp scenarios list` lists the built-in scenarios (`charge-session`, `fault-recovery`, `finish-session`, `offline-sync`); `kirby-ocpp scenarios show <name>` prints one as TOML. Built-ins target connector 1 unless `--connector` is given. `offline-sync` works on a stock station: `LocalAuthorizeOffline` and `AllowOfflineTxForUnknownId` default to `true` (switch them off with `ChangeConfiguration` to test the CSMS-side rejection path).
118
162
 
119
163
  ```toml
120
164
  name = "my-session"
@@ -146,7 +190,28 @@ reason = "Local"
146
190
  expect = { status = "Accepted" }
147
191
  ```
148
192
 
149
- Actions: `connect`, `disconnect`, `reconnect`, `boot`, `heartbeat`, `plug`, `unplug`, `authorize`, `start_tx`, `stop_tx`, `meter`, `status`, `fault`, `clear_fault`, `sleep`, `wait_for`, `expect_call` (`call`, optional `direction`, `match` payload subset), `send_raw` (`call`, `payload`, `validate`), `data_transfer`. Every step may have `name` and `expect` (`status`, `payload` subset, `error = true`). `wait_for` takes `condition = { kind = ... }` with kinds `connected`, `disconnected`, `registration`, `connector_status`, `tx_active`, `tx_idle`, `no_pending_messages`, and `timeout_ms` (default 5000). Unknown fields are rejected.
193
+ Actions: `connect`, `disconnect`, `reconnect`, `boot`, `heartbeat`, `plug`, `unplug`, `authorize`, `start_tx`, `stop_tx`, `meter`, `status`, `fault`, `clear_fault`, `sleep`, `wait_for`, `expect_call` (`call`, optional `direction`, `match` payload subset), `send_raw` (`call`, `payload`, `validate`), `data_transfer`, `set_rule` (`rule`), `clear_rules` (optional `call`). Every step may have `name` and `expect` (`status`, `payload` subset, `error = true`). `wait_for` takes `condition = { kind = ... }` with kinds `connected`, `disconnected`, `registration`, `connector_status`, `tx_active`, `tx_idle`, `no_pending_messages`, and `timeout_ms` (default 5000). Unknown fields are rejected.
194
+
195
+ ## Response rules
196
+
197
+ Response rules make the station misbehave on purpose, to test how a CSMS reacts. A rule overrides how one CSMS command (any of the 19 the station handles, e.g. `Reset`, `RemoteStartTransaction`, `ChangeConfiguration`) is answered. Form: `ACTION=BEHAVIOR[*COUNT]`, action names case-insensitive.
198
+
199
+ | Behavior | Effect |
200
+ | --- | --- |
201
+ | `reject` | The action's own rejection (`Rejected`; `NotSupported` for `SendLocalList` and `UnlockConnector`). `GetConfiguration`, `GetLocalListVersion`, `ClearChargingProfile`, `GetDiagnostics` and `UpdateFirmware` have no rejection status, so they get CALLERROR `NotSupported`. |
202
+ | `delay:MS` | The command is handled normally; only the reply is sent `MS` ms later (0 to 3600000). The station keeps working meanwhile. |
203
+ | `error:CODE[:TEXT]` | CALLERROR with an OCPP 1.6 code (`NotImplemented`, `NotSupported`, `InternalError`, `ProtocolError`, `SecurityError`, `FormationViolation`, `PropertyConstraintViolation`, `OccurenceConstraintViolation`, `TypeConstraintViolation`, `GenericError`). |
204
+ | `drop` | Close the WebSocket without replying; the normal reconnect lifecycle follows (disabled by `--no-reconnect`). |
205
+ | `ignore` | Never reply, so the CSMS call timeout fires. |
206
+
207
+ `*COUNT` applies the rule that many times and then removes it (default: unlimited). There is one rule per action; setting another replaces it. Except for `delay`, the command is **not executed** (no side effects). Rules are runtime only, never persisted. Set them with `--rule` (repeatable) or `KIRBY_OCPP_RULES`; in both, `;` separates several rules, so a rule (e.g. an `error:` text) must not contain `;`, in the TUI (Station tab, `m`), as scenario steps, or through `Command::SetResponseRule` / `ClearResponseRules` in the core API. Each application is logged (`response rule: Reset -> reject, 2 more`).
208
+
209
+ ```sh
210
+ kirby-ocpp --url ws://localhost:9000/ocpp --rule Reset=reject --rule GetConfiguration=delay:5000 \
211
+ --rule ChangeConfiguration=error:InternalError*3 --rule RemoteStartTransaction=ignore*1
212
+ ```
213
+
214
+ In scenarios: `action = "set_rule"` with `rule = "Reset=reject*2"`, and `action = "clear_rules"` with an optional `call = "Reset"` (all rules when omitted).
150
215
 
151
216
  ## Testing against a mock
152
217
 
@@ -166,4 +231,4 @@ Protocol coverage is documented in [docs/OCPP_1.6J_CONFORMANCE.md](docs/OCPP_1.6
166
231
 
167
232
  ## License
168
233
 
169
- MIT, see [LICENSE](LICENSE). The bundled OCPP JSON schemas belong to the Open Charge Alliance; see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) or run `kirby-ocpp --licenses`. Crate licences are recorded in `Cargo.lock` and the crates' metadata.
234
+ MIT, see [LICENSE](LICENSE). The bundled OCPP JSON schemas belong to the Open Charge Alliance; see [THIRD_PARTY_NOTICES.md](crates/kirby-ocpp/THIRD_PARTY_NOTICES.md) or run `kirby-ocpp --licenses`. Crate licences are recorded in `Cargo.lock` and the crates' metadata.
package/bin/kirby-ocpp.js CHANGED
@@ -5,34 +5,56 @@
5
5
  const { spawnSync } = require("node:child_process");
6
6
  const path = require("node:path");
7
7
 
8
+ // Candidate packages per platform, in order of preference. The musl build is fully static,
9
+ // so on Linux x64 it is also a valid fallback when the glibc package was not installed.
8
10
  const PLATFORMS = {
9
- "linux-x64": "@archhaze24/kirby-ocpp-linux-x64",
10
- "linux-arm64": "@archhaze24/kirby-ocpp-linux-arm64",
11
- "darwin-x64": "@archhaze24/kirby-ocpp-darwin-x64",
12
- "darwin-arm64": "@archhaze24/kirby-ocpp-darwin-arm64",
13
- "win32-x64": "@archhaze24/kirby-ocpp-win32-x64",
11
+ "linux-x64": ["@archhaze24/kirby-ocpp-linux-x64", "@archhaze24/kirby-ocpp-linux-x64-musl"],
12
+ "linux-arm64": ["@archhaze24/kirby-ocpp-linux-arm64"],
13
+ "darwin-x64": ["@archhaze24/kirby-ocpp-darwin-x64"],
14
+ "darwin-arm64": ["@archhaze24/kirby-ocpp-darwin-arm64"],
15
+ "win32-x64": ["@archhaze24/kirby-ocpp-win32-x64"],
14
16
  };
15
17
 
18
+ // True on a musl-based Linux (Alpine etc.): glibc reports its version, musl does not.
19
+ function isMusl() {
20
+ if (process.platform !== "linux") return false;
21
+ try {
22
+ const report = process.report.getReport();
23
+ const header = typeof report === "string" ? JSON.parse(report).header : report.header;
24
+ if (header && "glibcVersionRuntime" in header) return !header.glibcVersionRuntime;
25
+ } catch {
26
+ // fall through to the file check
27
+ }
28
+ try {
29
+ return require("node:fs").readdirSync("/lib").some((name) => name.startsWith("ld-musl-"));
30
+ } catch {
31
+ return false;
32
+ }
33
+ }
34
+
16
35
  function binaryPath() {
17
36
  const key = `${process.platform}-${process.arch}`;
18
- const pkg = PLATFORMS[key];
19
- if (!pkg) {
37
+ const candidates = PLATFORMS[key];
38
+ if (!candidates) {
20
39
  throw new Error(
21
40
  `kirby-ocpp has no prebuilt binary for ${key}. Supported: ${Object.keys(PLATFORMS).join(", ")}. ` +
22
41
  "Build from source instead: cargo install kirby-ocpp",
23
42
  );
24
43
  }
25
- let manifest;
26
- try {
27
- manifest = require.resolve(`${pkg}/package.json`);
28
- } catch {
29
- throw new Error(
30
- `The platform package ${pkg} is not installed (npm skipped the optional dependency). ` +
31
- "Reinstall without --omit=optional, or run: cargo install kirby-ocpp",
32
- );
33
- }
44
+ const ordered = key === "linux-x64" && isMusl() ? [...candidates].reverse() : candidates;
34
45
  const exe = process.platform === "win32" ? "kirby-ocpp.exe" : "kirby-ocpp";
35
- return path.join(path.dirname(manifest), "bin", exe);
46
+ for (const pkg of ordered) {
47
+ try {
48
+ const manifest = require.resolve(`${pkg}/package.json`);
49
+ return path.join(path.dirname(manifest), "bin", exe);
50
+ } catch {
51
+ // not installed, try the next candidate
52
+ }
53
+ }
54
+ throw new Error(
55
+ `The platform package ${ordered[0]} is not installed (npm skipped the optional dependency). ` +
56
+ "Reinstall without --omit=optional, or run: cargo install kirby-ocpp",
57
+ );
36
58
  }
37
59
 
38
60
  let binary;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kirby-ocpp",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Terminal OCPP 1.6J charge point emulator for testing a CSMS (TUI, headless and scenarios)",
5
5
  "keywords": [
6
6
  "ocpp",
@@ -31,10 +31,11 @@
31
31
  "node": ">=18"
32
32
  },
33
33
  "optionalDependencies": {
34
- "@archhaze24/kirby-ocpp-linux-x64": "0.2.0",
35
- "@archhaze24/kirby-ocpp-linux-arm64": "0.2.0",
36
- "@archhaze24/kirby-ocpp-darwin-x64": "0.2.0",
37
- "@archhaze24/kirby-ocpp-darwin-arm64": "0.2.0",
38
- "@archhaze24/kirby-ocpp-win32-x64": "0.2.0"
34
+ "@archhaze24/kirby-ocpp-linux-x64": "0.3.0",
35
+ "@archhaze24/kirby-ocpp-linux-x64-musl": "0.3.0",
36
+ "@archhaze24/kirby-ocpp-linux-arm64": "0.3.0",
37
+ "@archhaze24/kirby-ocpp-darwin-x64": "0.3.0",
38
+ "@archhaze24/kirby-ocpp-darwin-arm64": "0.3.0",
39
+ "@archhaze24/kirby-ocpp-win32-x64": "0.3.0"
39
40
  }
40
41
  }