Skip to content

[Edge] Evcs.Ocpp.Server: fix meter values, StopTransaction and reconnect handling - #4151

Merged
sfeilmeier merged 2 commits into
OpenEMS:developfrom
scienceworks-germany:feature/ocpp-server-fixes
Nov 30, 2026
Merged

sfeilmeier merged 2 commits into
OpenEMS:developfrom
scienceworks-germany:feature/ocpp-server-fixes

Conversation

@scienceworks-germany

Copy link
Copy Markdown
Contributor

While running OCPP 1.6 charge points against Evcs.Ocpp.Server we ran into a few problems in CoreEventHandlerImpl and MyJsonServer. Each fix is covered by a unit test that fails on current develop. The bundle had no tests so far, so this also adds a small test setup (DummyOcppEvcs, MyConfig).

Voltage in millivolt

ElectricityMeter.ChannelId.VOLTAGE is in mV, but the OCPP Voltage measurand (V) was written unscaled, so 230 V showed up as 0.23 V. It is now multiplied by 1000. Note that recorded voltage values of OCPP charge points will be 1000 times higher from now on.

Frequency in millihertz

Same for ElectricityMeter.ChannelId.FREQUENCY (integer, mHz): the measurand (Hz) was passed on as the raw string, so a decimal value like 50.02 threw an IllegalArgumentException in setNextValue() and the whole MeterValues request failed. It is now converted to mHz.

Optional unit

unit is optional in an OCPP 1.6 SampledValue. For measurands other than energy the library then returns null, which threw a NullPointerException in Unit.valueOf(unitString.toUpperCase()) and also dropped the whole MeterValues request. Values without a unit are now taken as they are, i.e. in the base unit (W, A, var, ...).

Power calculated from energy

If an EVCS does not list Power.Active.Import as supported, the power is derived from Energy.Active.Import.Register. The arguments of Duration.between() were swapped, so the calculated power was negative. Two meter values with the same timestamp divided by zero. The arguments are now in the right order, and for a time difference of zero or less the last power value is kept.

StopTransaction for an unknown session

handleStopTransactionRequest() called _setStatus() without checking whether an EVCS was found for the session and connector, which threw a NullPointerException.

Reconnect before the old connection is closed

When a charge point reconnects (e.g. after a WiFi dropout) before its old WebSocket connection has timed out, the new session is registered first. When the old connection is closed later, lostSession() was still called on the EVCS components, although they already belonged to the new session. That cleared their session and server reference, so no more charging limits could be sent until the charge point reconnected again. lostSession() is now only called for components that are still bound to the closed session.

Tests

./gradlew :io.openems.edge.evcs.ocpp.server:test :io.openems.edge.evcs.ocpp.server:checkstyleMain :io.openems.edge.evcs.ocpp.server:checkstyleTest

Sönke Wessels and others added 2 commits November 30, 2026 01:18
…ect handling

- Voltage and Frequency are converted to mV/mHz as required by the channels
- SampledValues without unit no longer throw a NullPointerException
- Power calculated from energy had a swapped time difference and could divide by zero
- StopTransaction for an unknown session no longer throws a NullPointerException
- Closing an old connection no longer resets EVCS that are already bound to a new session
…in lostSession loop

- handleMeterValuesRequest: Unit.valueOf threw IllegalArgumentException on
  unknown units and aborted the whole MeterValues request; EnumUtils.toEnum
  returns null for missing or unknown units, so the value is treated as
  base unit (unit is optional in OCPP 1.6)
- MyJsonServer.lostSession: stop iterating ocppSessions after the matching
  entry was found
- ComponentManagerImplTest: remove unused JsonUtils import

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@codecov

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.11111% with 7 lines in your changes missing coverage. Please review.

❌ Your patch status has failed because the patch coverage (61.12%) is below the target coverage (75.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@              Coverage Diff               @@
##             develop    #4151       +/-   ##
==============================================
+ Coverage      30.98%   56.84%   +25.87%     
- Complexity         0    21321    +21321     
==============================================
  Files            577     4076     +3499     
  Lines          17906   186809   +168903     
  Branches        3208    15776    +12568     
==============================================
+ Hits            5547   106181   +100634     
- Misses         12113    76305    +64192     
- Partials         246     4323     +4077     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sfeilmeier sfeilmeier left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Please be aware that we are slowly deprecating EVCS in favour of EVSE; but your contribution will survice this transition.

@sfeilmeier
sfeilmeier merged commit 664a534 into OpenEMS:develop Nov 30, 2026
7 checks passed
@VolMax-Studio

Copy link
Copy Markdown

Hi, thanks for the fixes in #4151.

During an independent differential verification campaign, we observed an interesting state transition in the energy-derived power calculation for EVCS configurations without Power.Active.Import.

The diffseconds <= 0 guard preserves the previous power value, but setLastChargingProperty() still replaces the stored energy and timestamp reference.

Using synthetic test vectors:

  • A: 0 s, 10000 Wh
  • B: 60 s, 10100 Wh
  • C: 30 s, 10090 Wh (late arrival)
  • D: 120 s, 10200 Wh

The derived power at D is 4400 W using the replaced reference, compared with 6000 W if B remains the reference.

Both values correspond to different averaging windows.

Is this reference replacement intentional, or should non-newer samples preserve the existing reference?

We recognize the OCPP 1.6 chronological replay expectations for charge points. This is therefore a question about receiver-side robustness and sample-admission policy, not a protocol compliance finding.

Happy to share our JUnit test cases and execution evidence if useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants