Skip to content

Commit 4e5376d

Browse files
authored
Allow configuring modbus connection timeout (evcc-io#613)
1 parent a0cafef commit 4e5376d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

meter/modbus.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package meter
33
import (
44
"errors"
55
"fmt"
6+
"time"
67

78
"github.com/andig/evcc/api"
89
"github.com/andig/evcc/util"
@@ -34,6 +35,7 @@ func NewModbusFromConfig(other map[string]interface{}) (api.Meter, error) {
3435
Model string
3536
modbus.Settings `mapstructure:",squash"`
3637
Power, Energy, SoC string
38+
Timeout time.Duration
3739
}{
3840
Power: "Power",
3941
}
@@ -55,6 +57,11 @@ func NewModbusFromConfig(other map[string]interface{}) (api.Meter, error) {
5557
return nil, err
5658
}
5759

60+
// set non-default timeout
61+
if cc.Timeout > 0 {
62+
conn.Timeout(cc.Timeout)
63+
}
64+
5865
conn.Logger(log.TRACE)
5966

6067
// prepare device

0 commit comments

Comments
 (0)