Document some more the UI protocol
[e-mobility-charging-stations-simulator.git] / README.md
1 # [e-mobility charging stations simulator](https://github.com/sap/e-mobility-charging-stations-simulator)
2
3 [![REUSE status](https://api.reuse.software/badge/github.com/SAP/e-mobility-charging-stations-simulator)](https://api.reuse.software/info/github.com/SAP/e-mobility-charging-stations-simulator)
4
5 ## Summary
6
7 Simple [node.js](https://nodejs.org/) software to simulate a set of charging stations based on the OCPP-J 1.6 protocol as part of SAP e-Mobility solution.
8
9 ## Prerequisites
10
11 Install the [node.js](https://nodejs.org/) LTS runtime environment:
12
13 ### Windows
14
15 - [Chocolatey](https://chocolatey.org/):
16
17 ```powershell
18 choco install -y nodejs-lts
19 ```
20
21 ### MacOSX
22
23 - [Homebrew](https://brew.sh/):
24
25 ```shell
26 brew install node@16
27 ```
28
29 ### GNU/Linux:
30
31 - [NodeSource](https://github.com/nodesource/distributions) Node.js Binary Distributions for version >= 16.X
32
33 ## Installation
34
35 In the repository root, run the following command:
36
37 ```shell
38 npm install
39 ```
40
41 ## Initial configuration
42
43 Copy the configuration template file [src/assets/config-template.json](src/assets/config-template.json) to [src/assets/config.json](src/assets/config.json).
44 Copy the authorization RFID tags template file [src/assets/authorization-tags-template.json](src/assets/authorization-tags-template.json) to [src/assets/authorization-tags.json](src/assets/authorization-tags.json).
45
46 Tweak them to your needs by following the section [configuration files syntax](README.md#configuration-files-syntax).
47
48 ## Start
49
50 To start the program, run: `npm start`.
51
52 ## Start Web UI
53
54 ## Configuration files syntax
55
56 All configuration files are in the JSON standard format.
57
58 **Configuration files locations**:
59
60 - charging stations simulator configuration: [src/assets/config.json](src/assets/config.json);
61 - charging station configuration templates: [src/assets/station-templates](src/assets/station-templates);
62 - charging station configurations: [dist/assets/configurations](dist/assets/configurations);
63 - charging station RFID tags lists: [src/assets](src/assets).
64
65 The charging stations simulator's configuration parameters must be within the `src/assets/config.json` file. A charging station simulator configuration template file is available at [src/assets/config-template.json](src/assets/config-template.json).
66
67 All charging station configuration templates are in the directory [src/assets/station-templates](src/assets/station-templates).
68
69 A list of RFID tags must be defined for the automatic transaction generator with a default location and name: `src/assets/authorization-tags.json`. A template file is available at [src/assets/authorization-tags-template.json](src/assets/authorization-tags-template.json).
70
71 **Configuration files hierarchy and priority**:
72
73 1. charging station configuration: [dist/assets/configurations](dist/assets/configurations);
74 2. charging station configuration template: [src/assets/station-templates](src/assets/station-templates);
75 3. charging stations simulator configuration: [src/assets/config.json](src/assets/config.json).
76
77 The charging stations simulator have an automatic configuration files reload feature at change for:
78
79 - charging stations simulator configuration;
80 - charging station configuration templates;
81 - charging station authorization RFID tags lists.
82
83 But the modifications to test have to be done to the files in the build target directory [dist/assets](dist/assets). Once the modifications are finished, they have to be reported or copied to the matching files in the build source directory [src/assets](src/assets) to ensure they will be taken into account at next build.
84
85 ### Charging stations simulator configuration
86
87 **src/assets/config.json**:
88
89 | Key | Value(s) | Default Value | Value type | Description |
90 | -------------------------- | ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
91 | supervisionUrls | | [] | string \| string[] | string or array of global connection URIs to OCPP-J servers |
92 | supervisionUrlDistribution | round-robin/random/sequential | round-robin | boolean | supervision urls distribution policy to simulated charging stations |
93 | logStatisticsInterval | | 60 | integer | seconds between charging stations statistics output in the logs |
94 | logConsole | true/false | false | boolean | output logs on the console |
95 | logFormat | | simple | string | winston log format |
96 | logRotate | true/false | true | boolean | enable daily log files rotation |
97 | logMaxFiles | | 7 | integer | maximum number of log files to keep |
98 | logLevel | emerg/alert/crit/error/warning/notice/info/debug | info | string | winston logging level |
99 | logFile | | combined.log | string | log file relative path |
100 | logErrorFile | | error.log | string | error log file relative path |
101 | worker | | {<br />"processType": "workerSet",<br />"startDelay": 500,<br />"elementStartDelay": 0,<br />"elementsPerWorker": 1,<br />"poolMinSize": 4,<br />"poolMaxSize": 16,<br />"poolStrategy": "ROUND_ROBBIN"<br />} | {<br />processType: WorkerProcessType;<br />startDelay: number;<br />elementStartDelay: number;<br />elementsPerWorker: number;<br />poolMinSize: number;<br />poolMaxSize: number;<br />poolStrategy: WorkerChoiceStrategy;<br />} | Worker configuration section:<br />- processType: worker threads process type (workerSet/staticPool/dynamicPool)<br />- startDelay: milliseconds to wait at worker threads startup (only for workerSet threads process type)<br />- elementStartDelay: milliseconds to wait at charging station startup<br />- elementsPerWorker: number of charging stations per worker threads for the `workerSet` process type<br />- poolMinSize: worker threads pool minimum number of threads</br >- poolMaxSize: worker threads pool maximum number of threads<br />- poolStrategy: worker threads pool [poolifier](https://github.com/poolifier/poolifier) worker choice strategy |
102 | uiServer | | {<br />"enabled": true,<br />"options": {<br />"host: "localhost",<br />"port": 8080<br />}<br />} | {<br />enabled: boolean;<br />options: ServerOptions;<br />} | UI WebSocket server configuration section |
103 | performanceStorage | | {<br />"enabled": false,<br />"type": "jsonfile",<br />"file:///performanceRecords.json"<br />} | {<br />enabled: boolean;<br />type: string;<br />URI: string;<br />}<br />where type can be 'jsonfile' or 'mongodb' | performance storage configuration section |
104 | stationTemplateUrls | | {}[] | {<br />file: string;<br />numberOfStations: number;<br />}[] | array of charging station configuration templates URIs configuration section (charging station configuration template file name and number of stations) |
105
106 #### Worker process model:
107
108 - **workerSet**:
109 Worker set executing each a static number (elementsPerWorker) of simulated charging stations from the total
110
111 - **staticPool**:
112 Statically sized worker pool executing a static total number of simulated charging stations
113
114 - **dynamicPool**:
115 Dynamically sized worker pool executing a static total number of simulated charging stations
116
117 ### Charging station configuration template
118
119 **src/assets/station-templates/\<name\>.json**:
120
121 | Key | Value(s) | Default Value | Value type | Description |
122 | ---------------------------------- | ---------- | ----------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
123 | supervisionUrls | | '' | string \| string[] | string or array of connection URIs to OCPP-J servers |
124 | supervisionUser | | '' | string | basic HTTP authentication user to OCPP-J server |
125 | supervisionPassword | | '' | string | basic HTTP authentication password to OCPP-J server |
126 | supervisionUrlOcppConfiguration | true/false | false | boolean | allow supervision URL configuration via a vendor OCPP parameter key |
127 | supervisionUrlOcppKey | | 'ConnectionUrl' | string | the vendor string that will be used as a vendor OCPP parameter key to set the supervision URL |
128 | ocppVersion | 1.6 | 1.6 | string | OCPP version |
129 | ocppProtocol | json | json | string | OCPP protocol |
130 | ocppStrictCompliance | true/false | false | boolean | strict adherence to the OCPP version and protocol specifications |
131 | ocppPersistentConfiguration | true/false | true | boolean | enable persistent OCPP parameters storage by charging stations 'hashId'. The persistency is ensured by the charging stations configuration files in dist/assets/configurations |
132 | stationInfoPersistentConfiguration | true/false | true | boolean | enable persistent station information and specifications storage by charging stations 'hashId'. The persistency is ensured by the charging stations configuration files in dist/assets/configurations |
133 | wsOptions | | {} | ClientOptions & ClientRequestArgs | [ws](https://github.com/websockets/ws) and node.js [http](https://nodejs.org/api/http.html) clients options intersection |
134 | authorizationFile | | '' | string | RFID tags list file relative to src/assets path |
135 | baseName | | '' | string | base name to build charging stations id |
136 | nameSuffix | | '' | string | name suffix to build charging stations id |
137 | fixedName | true/false | false | boolean | use the baseName as the charging stations unique name |
138 | chargePointModel | | '' | string | charging stations model |
139 | chargePointVendor | | '' | string | charging stations vendor |
140 | chargePointSerialNumberPrefix | | '' | string | charge point serial number prefix |
141 | chargeBoxSerialNumberPrefix | | '' | string | charge box serial number prefix (deprecated in OCPP 1.6) |
142 | firmwareVersion | | '' | string | charging stations firmware version |
143 | power | | | float \| float[] | charging stations maximum power value(s) |
144 | powerSharedByConnectors | true/false | false | boolean | charging stations power shared by its connectors |
145 | powerUnit | W/kW | W | string | charging stations power unit |
146 | currentOutType | AC/DC | AC | string | charging stations current out type |
147 | voltageOut | | AC:230/DC:400 | integer | charging stations voltage out |
148 | numberOfPhases | 0/1/3 | AC:3/DC:0 | integer | charging stations number of phase(s) |
149 | numberOfConnectors | | | integer \| integer[] | charging stations number of connector(s) |
150 | useConnectorId0 | true/false | true | boolean | use connector id 0 definition from the charging station configuration template |
151 | randomConnectors | true/false | false | boolean | randomize runtime connector id affectation from the connector id definition in charging station configuration template |
152 | resetTime | | 60 | integer | seconds to wait before the charging stations come back at reset |
153 | autoRegister | true/false | false | boolean | set charging stations as registered at boot notification for testing purpose |
154 | autoReconnectMaxRetries | | -1 (unlimited) | integer | connection retries to the OCPP-J server |
155 | reconnectExponentialDelay | true/false | false | boolean | connection delay retry to the OCPP-J server |
156 | registrationMaxRetries | | -1 (unlimited) | integer | charging stations boot notification retries |
157 | amperageLimitationOcppKey | | undefined | string | charging stations OCPP parameter key used to set the amperage limit, per phase for each connector on AC and global for DC |
158 | amperageLimitationUnit | A/cA/dA/mA | A | string | charging stations amperage limit unit |
159 | enableStatistics | true/false | true | boolean | enable charging stations statistics |
160 | mayAuthorizeAtRemoteStart | true/false | true | boolean | always send authorize at remote start transaction when AuthorizeRemoteTxRequests is enabled |
161 | payloadSchemaValidation | true/false | true | boolean | validate OCPP commands PDU against OCA JSON schemas |
162 | beginEndMeterValues | true/false | false | boolean | enable Transaction.{Begin,End} MeterValues |
163 | outOfOrderEndMeterValues | true/false | false | boolean | send Transaction.End MeterValues out of order. Need to relax OCPP specifications strict compliance ('ocppStrictCompliance' parameter) |
164 | meteringPerTransaction | true/false | true | boolean | enable metering history on a per transaction basis |
165 | transactionDataMeterValues | true/false | false | boolean | enable transaction data MeterValues at stop transaction |
166 | mainVoltageMeterValues | true/false | true | boolean | include charging stations main voltage MeterValues on three phased charging stations |
167 | phaseLineToLineVoltageMeterValues | true/false | true | boolean | include charging stations line to line voltage MeterValues on three phased charging stations |
168 | customValueLimitationMeterValues | true/false | true | boolean | enable limitation on custom fluctuated value in MeterValues |
169 | commandsSupport | | {<br />"incomingCommands": {},<br />"outgoingCommands": {}<br />} | {<br /> incomingCommands: Record<IncomingRequestCommand, boolean>;<br />outgoingCommands?: Record<RequestCommand, boolean>;<br />} | Configuration section for OCPP commands support. Empty section or subsections means all implemented commands are supported |
170 | Configuration | | | ChargingStationConfiguration | charging stations OCPP parameters configuration section |
171 | AutomaticTransactionGenerator | | | AutomaticTransactionGenerator | charging stations ATG configuration section |
172 | Connectors | | | Connectors | charging stations connectors configuration section |
173
174 #### Configuration section
175
176 ```json
177 "Configuration": {
178 "configurationKey": [
179 ...
180 {
181 "key": "StandardKey",
182 "readonly": false,
183 "value": "StandardValue",
184 "visible": true,
185 "reboot": false
186 },
187 ...
188 {
189 "key": "VendorKey",
190 "readonly": false,
191 "value": "VendorValue",
192 "visible": false,
193 "reboot": true
194 },
195 ...
196 ]
197 }
198 ```
199
200 #### AutomaticTransactionGenerator section
201
202 ```json
203 "AutomaticTransactionGenerator": {
204 "enable": false,
205 "minDuration": 60,
206 "maxDuration": 80,
207 "minDelayBetweenTwoTransactions": 15,
208 "maxDelayBetweenTwoTransactions": 30,
209 "probabilityOfStart": 1,
210 "stopAfterHours": 0.3,
211 "stopOnConnectionFailure": true,
212 "requireAuthorize": true
213 }
214 ```
215
216 #### Connectors section
217
218 ```json
219 "Connectors": {
220 "0": {},
221 "1": {
222 "bootStatus": "Available",
223 "MeterValues": [
224 ...
225 {
226 "unit": "W",
227 "measurand": "Power.Active.Import",
228 "phase": "L1-N",
229 "value": "5000",
230 "fluctuationPercent": "10"
231 },
232 ...
233 {
234 "unit": "A",
235 "measurand": "Current.Import"
236 },
237 ...
238 {
239 "unit": "Wh"
240 },
241 ...
242 ]
243 }
244 },
245 ```
246
247 ### Charging station configuration
248
249 **dist/assets/configurations/\<hashId\>.json**:
250
251 The charging station configuration file is automatically generated at startup from the charging station configuration template file and is persistent.
252
253 The charging station configuration file content can be regenerated partially on matching charging station configuration template file changes. The charging station serial number is kept unchanged.
254
255 #### stationInfo section
256
257 The syntax is similar to charging station configuration template with some added fields like the charging station id (name) and the 'Configuration' section removed.
258
259 #### configurationKey section
260
261 The syntax is similar to the charging station configuration template 'Configuration' section.
262
263 ## Docker
264
265 In the [docker](./docker) folder:
266
267 ```bash
268 make
269 ```
270
271 Or with the optional git submodules:
272
273 ```bash
274 make SUBMODULES_INIT=true
275 ```
276
277 ## OCPP-J commands supported
278
279 ### Version 1.6
280
281 #### Core Profile
282
283 - :white_check_mark: Authorize
284 - :white_check_mark: BootNotification
285 - :white_check_mark: ChangeAvailability
286 - :white_check_mark: ChangeConfiguration
287 - :white_check_mark: ClearCache
288 - :x: DataTransfer
289 - :white_check_mark: GetConfiguration
290 - :white_check_mark: Heartbeat
291 - :white_check_mark: MeterValues
292 - :white_check_mark: RemoteStartTransaction
293 - :white_check_mark: RemoteStopTransaction
294 - :white_check_mark: Reset
295 - :white_check_mark: StartTransaction
296 - :white_check_mark: StatusNotification
297 - :white_check_mark: StopTransaction
298 - :white_check_mark: UnlockConnector
299
300 #### Firmware Management Profile
301
302 - :white_check_mark: GetDiagnostics
303 - :white_check_mark: DiagnosticsStatusNotification
304 - :x: FirmwareStatusNotification
305 - :x: UpdateFirmware
306
307 #### Local Auth List Management Profile
308
309 - :x: GetLocalListVersion
310 - :x: SendLocalList
311
312 #### Reservation Profile
313
314 - :x: CancelReservation
315 - :x: ReserveNow
316
317 #### Smart Charging Profile
318
319 - :white_check_mark: ClearChargingProfile
320 - :x: GetCompositeSchedule
321 - :white_check_mark: SetChargingProfile
322
323 #### Remote Trigger Profile
324
325 - :white_check_mark: TriggerMessage
326
327 ## OCPP-J standard parameters supported
328
329 All kind of OCPP parameters are supported in a charging station configuration or a charging station configuration template file. The list here mention the standard ones also handled automatically in the simulator.
330
331 ### Version 1.6
332
333 #### Core Profile
334
335 - :white_check_mark: AuthorizeRemoteTxRequests (type: boolean) (units: -)
336 - :x: ClockAlignedDataInterval (type: integer) (units: seconds)
337 - :white_check_mark: ConnectionTimeOut (type: integer) (units: seconds)
338 - :x: GetConfigurationMaxKeys (type: integer) (units: -)
339 - :white_check_mark: HeartbeatInterval (type: integer) (units: seconds)
340 - :x: LocalAuthorizeOffline (type: boolean) (units: -)
341 - :x: LocalPreAuthorize (type: boolean) (units: -)
342 - :x: MeterValuesAlignedData (type: CSL) (units: -)
343 - :white_check_mark: MeterValuesSampledData (type: CSL) (units: -)
344 - :white_check_mark: MeterValueSampleInterval (type: integer) (units: seconds)
345 - :white_check_mark: NumberOfConnectors (type: integer) (units: -)
346 - :x: ResetRetries (type: integer) (units: times)
347 - :white_check_mark: ConnectorPhaseRotation (type: CSL) (units: -)
348 - :x: StopTransactionOnEVSideDisconnect (type: boolean) (units: -)
349 - :x: StopTransactionOnInvalidId (type: boolean) (units: -)
350 - :x: StopTxnAlignedData (type: CSL) (units: -)
351 - :x: StopTxnSampledData (type: CSL) (units: -)
352 - :white_check_mark: SupportedFeatureProfiles (type: CSL) (units: -)
353 - :x: TransactionMessageAttempts (type: integer) (units: times)
354 - :x: TransactionMessageRetryInterval (type: integer) (units: seconds)
355 - :x: UnlockConnectorOnEVSideDisconnect (type: boolean) (units: -)
356 - :white_check_mark: WebSocketPingInterval (type: integer) (units: seconds)
357
358 #### Firmware Management Profile
359
360 - _none_
361
362 #### Local Auth List Management Profile
363
364 - :white_check_mark: LocalAuthListEnabled (type: boolean) (units: -)
365 - :x: LocalAuthListMaxLength (type: integer) (units: -)
366 - :x: SendLocalListMaxLength (type: integer) (units: -)
367
368 #### Reservation Profile
369
370 - _none_
371
372 #### Smart Charging Profile
373
374 - :x: ChargeProfileMaxStackLevel (type: integer) (units: -)
375 - :x: ChargingScheduleAllowedChargingRateUnit (type: CSL) (units: -)
376 - :x: ChargingScheduleMaxPeriods (type: integer) (units: -)
377 - :x: MaxChargingProfilesInstalled (type: integer) (units: -)
378
379 #### Remote Trigger Profile
380
381 - _none_
382
383 ## UI protocol
384
385 Protocol to control the simulator via a Websocket
386
387 ### Protocol
388
389 PDU stands for Protocol Data Unit
390
391 Request:
392 [`uuid`, `ProcedureName`, `PDU`]
393
394 `uuid`: String uniquely representing this request
395 `ProcedureName`: The procedure to run on the simulator
396 `PDU`: The parameters (if any) for said procedure
397
398 Response:
399 [`uuid`, `PDU`]
400
401 `uuid`: String uniquely linking the response to the request
402 `PDU`: Response data to requested procedure
403
404 ### Version 0.0.1
405
406 Set the HTTP header _Sec-Websocket-Protocol_ to `ui0.0.1`
407
408 #### Procedures
409
410 ##### List Charging stations
411
412 Request:
413 `ProcedureName`: 'listChargingStations'
414 `PDU`: {}
415
416 Response:
417 `PDU`: {
418 `status`,
419 `index`: ChargingStationData,
420 ...
421 `index`: ChargingStationData
422 }
423
424 ##### Start Transaction
425
426 Request:
427 `ProcedureName`: 'startTransaction'
428 `PDU`: {
429 `hashId`: the unique identifier of a charging station
430 `connectorId`: the id of the connector (start at 1)
431 `idTag`: An allowed badge authetification ID
432 }
433
434 Response:
435 `PDU`: {
436 `status`
437 }
438
439 ##### Stop Transaction
440
441 Request:
442 `ProcedureName`: 'stopTransaction'
443 `PDU`: {
444 `hashId`: the unique identifier of a charging station
445 `transactionId`: the id of the transaction
446 }
447
448 Response:
449 `PDU`: {
450 `status`
451 }
452
453 ##### Start Charging Station
454
455 Request:
456 `ProcedureName`: 'startChargingStation'
457 `PDU`: {
458 `hashId`: the unique identifier of a charging station
459 }
460
461 Response:
462 `PDU`: {
463 `status`
464 }
465
466 ##### Stop Charging Station
467
468 Request:
469 `ProcedureName`: 'stopChargingStation'
470 `PDU`: {
471 `hashId`: the unique identifier of a charging station
472 }
473
474 Response:
475 `PDU`: {
476 `status`
477 }
478
479 ## Support, Feedback, Contributing
480
481 This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/SAP/e-mobility-charging-stations-simulator/issues). Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our [Contribution Guidelines](CONTRIBUTING.md).
482
483 ## Code of Conduct
484
485 We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its [Code of Conduct](CODE_OF_CONDUCT.md) at all times.
486
487 ## Licensing
488
489 Copyright 2020-2022 SAP SE or an SAP affiliate company and e-mobility-charging-stations-simulator contributors. Please see our [LICENSE](LICENSE) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/SAP/e-mobility-charging-stations-simulator).