From 4e5376df1cca8688a9b7b40f7592eaf417f9e7ed Mon Sep 17 00:00:00 2001 From: andig Date: Mon, 25 Jan 2021 17:23:42 +0100 Subject: [PATCH] Allow configuring modbus connection timeout (#613) --- meter/modbus.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/meter/modbus.go b/meter/modbus.go index 9aa5fb7f4..a08c6be3f 100644 --- a/meter/modbus.go +++ b/meter/modbus.go @@ -3,6 +3,7 @@ package meter import ( "errors" "fmt" + "time" "github.com/andig/evcc/api" "github.com/andig/evcc/util" @@ -34,6 +35,7 @@ func NewModbusFromConfig(other map[string]interface{}) (api.Meter, error) { Model string modbus.Settings `mapstructure:",squash"` Power, Energy, SoC string + Timeout time.Duration }{ Power: "Power", } @@ -55,6 +57,11 @@ func NewModbusFromConfig(other map[string]interface{}) (api.Meter, error) { return nil, err } + // set non-default timeout + if cc.Timeout > 0 { + conn.Timeout(cc.Timeout) + } + conn.Logger(log.TRACE) // prepare device