From: Jérôme Benoit Date: Fri, 13 Mar 2026 18:58:05 +0000 (+0100) Subject: docs(ocpp-server): restructure README with logical section hierarchy X-Git-Tag: ocpp-server@v3.1.0~45 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=2287dc087ffb396b487c2cdecb011938c4506d52;p=e-mobility-charging-stations-simulator.git docs(ocpp-server): restructure README with logical section hierarchy --- diff --git a/tests/ocpp-server/README.md b/tests/ocpp-server/README.md index d703a2a4..0367af1e 100644 --- a/tests/ocpp-server/README.md +++ b/tests/ocpp-server/README.md @@ -36,37 +36,82 @@ poetry run python server.py The server will start listening for connections on `127.0.0.1:9000` by default. -### Server Configuration +## Configuration + +### Server ```shell poetry run python server.py --host --port ``` -**Options:** - - `--host `: Server bind address (default: `127.0.0.1`) - `--port `: Server port (default: `9000`) -## Running the server with OCPP command sending +### Charging Station Behavior -### Command Line Interface +```shell +poetry run python server.py --boot-status --total-cost +``` + +- `--boot-status `: BootNotification response status (`accepted`, `pending`, `rejected`; default: `accepted`) +- `--total-cost `: Total cost returned in TransactionEvent.Updated responses (default: `10.0`) + +**Examples:** ```shell -poetry run task server --command --period +poetry run python server.py --boot-status rejected +poetry run python server.py --total-cost 25.50 ``` -**Options:** +### Authorization Modes + +The server supports configurable authorization behavior for testing OCPP 2.0.1 authentication scenarios: -- `--command `: The OCPP command to send (see available commands below) -- `--period `: Interval in seconds between command sends +```shell +poetry run python server.py --auth-mode [--whitelist TOKEN1 TOKEN2 ...] [--blacklist TOKEN1 TOKEN2 ...] [--offline] +``` + +- `--auth-mode `: Authorization mode (default: `normal`) + - `normal` - Accept all authorization requests (default) + - `whitelist` - Only accept tokens in the whitelist + - `blacklist` - Block tokens in the blacklist, accept all others + - `rate_limit` - Reject all requests with `NotAtThisTime` (simulates rate limiting) + - `offline` - Not used directly (use `--offline` flag instead) +- `--whitelist TOKEN1 TOKEN2 ...`: Space-separated list of authorized tokens (default: `valid_token test_token authorized_user`) +- `--blacklist TOKEN1 TOKEN2 ...`: Space-separated list of blocked tokens (default: `blocked_token invalid_user`) +- `--offline`: Simulate network failure (raises InternalError on Authorize requests) + +**Examples:** + +```shell +poetry run python server.py --auth-mode whitelist --whitelist valid_token test_token +poetry run python server.py --auth-mode blacklist --blacklist blocked_token invalid_user +poetry run python server.py --offline +poetry run python server.py --auth-mode rate_limit +``` + +### OCPP Command Sending + +The server can periodically send outgoing OCPP commands to connected charging stations: + +```shell +poetry run python server.py --command --period +poetry run python server.py --command --delay +``` + +- `--command `: The OCPP command to send (see supported commands below) +- `--period `: Interval in seconds between repeated command sends (mutually exclusive with `--delay`) +- `--delay `: One-shot delay in seconds before sending the command (mutually exclusive with `--period`) **Example:** ```shell -poetry run task server --command GetBaseReport --period 5 +poetry run python server.py --command GetBaseReport --period 5 ``` -### Available Outgoing Commands +## Supported OCPP Messages + +### Outgoing Commands (CSMS → CS) - `CertificateSigned` - Send a signed certificate to the charging station - `ChangeAvailability` - Change connector availability @@ -89,7 +134,7 @@ poetry run task server --command GetBaseReport --period 5 - `UnlockConnector` - Unlock a specific connector - `UpdateFirmware` - Request firmware update on the charging station -### Handled Incoming Messages +### Incoming Handlers (CS → CSMS) - `Authorize` - Handle authorization requests (with configurable auth modes) - `BootNotification` - Handle boot notification from charging station @@ -107,88 +152,12 @@ poetry run task server --command GetBaseReport --period 5 - `StatusNotification` - Handle status notifications - `TransactionEvent` - Handle transaction events (Started/Updated/Ended) -## Charging Behavior Configuration - -```shell -poetry run python server.py --boot-status --total-cost -``` - -**Options:** - -- `--boot-status `: BootNotification response status (`accepted`, `pending`, `rejected`; default: `accepted`) -- `--total-cost `: Total cost returned in TransactionEvent.Updated responses (default: `10.0`) - -**Examples:** - -```shell -poetry run python server.py --boot-status rejected -poetry run python server.py --total-cost 25.50 -``` - -## Authorization Testing Modes - -The server supports configurable authorization behavior for testing OCPP 2.0 authentication scenarios: - -### Command Line Options - -```shell -poetry run python server.py --auth-mode [--whitelist TOKEN1 TOKEN2 ...] [--blacklist TOKEN1 TOKEN2 ...] [--offline] -``` - -**Auth Options:** - -- `--auth-mode `: Authorization mode (default: `normal`) - - `normal` - Accept all authorization requests (default) - - `whitelist` - Only accept tokens in the whitelist - - `blacklist` - Block tokens in the blacklist, accept all others - - `rate_limit` - Reject all requests with `NotAtThisTime` (simulates rate limiting) - - `offline` - Not used directly (use `--offline` flag instead) -- `--whitelist TOKEN1 TOKEN2 ...`: Space-separated list of authorized tokens (default: `valid_token test_token authorized_user`) -- `--blacklist TOKEN1 TOKEN2 ...`: Space-separated list of blocked tokens (default: `blocked_token invalid_user`) -- `--offline`: Simulate network failure (raises ConnectionError on Authorize requests) - -### Examples - -**Whitelist mode** (only accept specific tokens): - -```shell -poetry run python server.py --auth-mode whitelist --whitelist valid_token test_token -``` - -**Blacklist mode** (block specific tokens): - -```shell -poetry run python server.py --auth-mode blacklist --blacklist blocked_token invalid_user -``` - -**Offline mode** (simulate network failure): - -```shell -poetry run python server.py --offline -``` - -**Rate limit simulation**: - -```shell -poetry run python server.py --auth-mode rate_limit -``` - -### Testing the Server - -To run the test suite and validate all implemented commands: +## Testing ```shell poetry run task test ``` -## Overview of the Server Scripts - -### Server.py - -The server script waits for connections from clients. When a client connects, the server creates a new instance of the `ChargePoint` class. This class includes methods for handling various OCPP messages, most of which return a dummy response. - -The server script uses the `websockets` and `ocpp` libraries to facilitate the implementation. - ## Development ### Code formatting @@ -203,9 +172,6 @@ poetry run task format poetry run task lint ``` -## Note - -Primarily, this software is intended for testing applications. The server script don't adhere to the full OCPP specifications and it is advised not to use them in a production environment without additional development. +## Reference -For reference: -https://github.com/mobilityhouse/ocpp +- [mobilityhouse/ocpp](https://github.com/mobilityhouse/ocpp) - Python OCPP library