evcc icon indicating copy to clipboard operation
evcc copied to clipboard

UX: Setup fails with "chargeStatus: EOF" for Mennekes AMTRON 4Business 780 due to optional Modbus registers 730/740

Open daffy5693 opened this issue 4 months ago • 7 comments

Describe the bug

When setting up a Mennekes AMTRON 4Business 780 via the web interface, the status check fails with:

Status: failed - chargeStatus: EOF

Image

Despite this error, saving the configuration anyway works fine — all relevant data can be read from the wallbox via Modbus without issues.

Image

A network analysis of the Modbus traffic during the setup status check revealed that EVCC probes the optional Modbus registers 730 and 740 as part of the check.

The AMTRON 4Business 780 responds to these registers with a Modbus exception (Illegal Data Address), since it does not support them.

Functionally, the integration works correctly even without these registers, and everything operates normally once the setup error is ignored and the configuration is saved. However, this results in poor user experience during setup, since users are led to believe there is a configuration or connectivity problem when in fact the device simply doesn't support these two optional registers.

If needed I can also provide the relevant pcap files with the modbus traffic.

Steps to reproduce

  1. Configure charging point Mennekes AMTRON 4Business 700 with an AMTRON 4Business 780
  2. Click check in setup wizard

Configuration details

[main  ] INFO 2026/07/24 10:06:35 using config file: /etc/evcc.yaml
[main  ] INFO 2026/07/24 10:06:35 using sqlite database: /root/.evcc/evcc.db?_pragma=busy_timeout(5000)&_pragma=foreign_keys(1)&_pragma=auto_vacuum(INCREMENTAL)
charger
---
db:12 {Type:template Title: Icon: Product:Mennekes AMTRON 4Business 700} map[baudrate:9600 comset:8N1 host:192.168.60.168 id:1 modbus:tcpip port:502 template:bender-icc]

Log details

n/a

What type of operating system or environment does evcc run on?

Docker container

External automation

  • [x] I have made sure that no external automation like HomeAssistant or Node-RED is active or accessing any of the mentioned devices when this issue occurs.

Nightly build

  • [x] I have verified that the issue is reproducible with the latest nightly build

Version

evcc version 0.312.1 (e3a48e42f)

daffy5693 avatar Jul 24 '26 08:07 daffy5693

Root cause

The device behaves correctly and the wallbox integration itself is fine — this is a bug in how evcc's Modbus layer interacts with concurrent capability probes during the setup-wizard check.

bender.go (BenderCC) reads several optional registers (e.g. bendRegEVBatteryState = 730 in soc(), bendRegSmartVehicleDetected = 740 in identify()/soc()) that are expected to fail gracefully with a Modbus exception ("Illegal Data Address") on devices that don't implement them — the code already handles that via if _, err := ...; err == nil.

The problem is in util/modbus/connection.go:53-63 (Connection.exec):

func (c *Connection) exec(fun func() ([]byte, error)) ([]byte, error) {
	return c.WithLogger(c.logical, func() ([]byte, error) {
		time.Sleep(c.delay)

		b, err := fun()
		if err != nil {
			c.Connection.Close()
		}
		return b, err
	})
}

Any error — including a benign "unsupported register" Modbus exception — closes the underlying physical TCP connection, not just that one logical call. During the setup-wizard's device check (server/http_config_helper.go), several capability probes (Status(), Enabled(), Soc(), Currents(), etc.) run concurrently (wg.Go(...)) against the same shared *modbus.Connection. When the soc()/identify() goroutine hits the expected exception on register 730/740 and closes the socket, any other goroutine with an in-flight request on that same TCP connection (e.g. the Status() call reading register 122 for chargeStatus) gets an abrupt EOF, which is what's shown as Status: failed - chargeStatus: EOF in the UI.

So the two "optional register" probes aren't wrong per se — the real issue is that a single failed/exception Modbus request closes a connection that's shared and used concurrently by other in-flight probes, causing collateral EOF failures.

Affected files

  • util/modbus/connection.go (Connection.exec, closes the shared connection on any error)
  • charger/bender.go (concurrent-safe read paths that trigger the optional-register probes)
  • server/http_config_helper.go (runs capability probes concurrently against the same device connection)

This looks fixable, but the correct fix (avoiding premature/collateral connection closes for concurrently-shared Modbus connections, while still allowing reconnect-on-error for genuinely broken connections) needs a bit of care to not affect other chargers/meters relying on the same reconnect-on-error behavior, so I'm not opening a PR for it here.

🤖 Generated with Claude Code

github-actions[bot] avatar Jul 24 '26 08:07 github-actions[bot]

@premultiply can we solve this by moving the probes to startup rather than time of request?

andig avatar Jul 26 '26 12:07 andig

ping @premultiply

andig avatar Aug 04 '26 15:08 andig

Fixed with 0df2610 in nightly v0.313.0 (44b8a5c). Tested sucessful. Setupprocess works as expected now.

daffy5693 avatar Aug 07 '26 06:08 daffy5693

Thanks for confirming

andig avatar Aug 07 '26 07:08 andig

Closed with 0.314.1

daffy5693 avatar Aug 17 '26 07:08 daffy5693

Nice, thank you!

andig avatar Aug 17 '26 09:08 andig