RCT: handle initial connection failing to read (#19362)

This commit is contained in:
andig 2025-03-03 11:31:56 +01:00 • committed by GitHub
parent 3ade50fcd1
commit 8b3deb21c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 13 additions and 3 deletions

2
go.mod
View file

@ -222,4 +222,4 @@ replace github.com/grid-x/modbus => github.com/evcc-io/modbus v0.0.0-20241027151
replace github.com/lorenzodonini/ocpp-go => github.com/evcc-io/ocpp-go v0.0.0-20241230132027-815870498cc3
replace github.com/mlnoga/rct => github.com/andig/rct v0.1.2-0.20250302110530-e1b03e640f26
replace github.com/mlnoga/rct => github.com/andig/rct v0.1.2-0.20250303102452-38b496bdd2c9

4
go.sum
View file

@ -39,8 +39,8 @@ github.com/andig/gosunspec v0.0.0-20240918203654-860ce51d602b h1:81UMfM949I7StrR
github.com/andig/gosunspec v0.0.0-20240918203654-860ce51d602b/go.mod h1:c6P6szcR+ROkqZruOR4f6qbDKFjZX6OitPpj+yJ/r8k=
github.com/andig/mbserver v0.0.0-20230310211055-1d29cbb5820e h1:m/NTP3JWpR7M0ljLxiQU4fzR25jjhe1LDtxLMNcoNJQ=
github.com/andig/mbserver v0.0.0-20230310211055-1d29cbb5820e/go.mod h1:4VtYzTm//oUipwvO3yh0g/udTE7pYJM+U/kyAuFDsgM=
github.com/andig/rct v0.1.2-0.20250302110530-e1b03e640f26 h1:Kqq17bxhK6TsBs54gf2Bk4pghBAAeJw1WN/RU0pgV1M=
github.com/andig/rct v0.1.2-0.20250302110530-e1b03e640f26/go.mod h1:KRjBDV8kuvGd2kJfN8/F0kjH8JjkFVpBpn7MhW+ACL8=
github.com/andig/rct v0.1.2-0.20250303102452-38b496bdd2c9 h1:hHUPfKTJlyHX0i5iZy7UNtIYoNDtcPH/Q1bbOe2OZ+g=
github.com/andig/rct v0.1.2-0.20250303102452-38b496bdd2c9/go.mod h1:KRjBDV8kuvGd2kJfN8/F0kjH8JjkFVpBpn7MhW+ACL8=
github.com/andig/yaml v0.0.0-20240531135838-1ff5761ab467 h1:JqIoHxsQSV39xaemvVRu3HOkSf5AbhQ1YEENJa2cL3Q=
github.com/andig/yaml v0.0.0-20240531135838-1ff5761ab467/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM=

View file

@ -6,7 +6,9 @@ import (
"errors"
"fmt"
"math"
"math/rand/v2"
"strings"
"sync"
"time"
"github.com/evcc-io/evcc/api"
@ -20,6 +22,8 @@ type RCT struct {
usage string // grid, pv, battery
}
var rctMu sync.Mutex
func init() {
registry.AddCtx("rct", NewRCTFromConfig)
}
@ -52,6 +56,11 @@ func NewRCTFromConfig(ctx context.Context, other map[string]interface{}) (api.Me
func NewRCT(ctx context.Context, uri, usage string, minSoc, maxSoc int, cache time.Duration, capacity func() float64) (api.Meter, error) {
log := util.NewLogger("rct")
// prevent concurrent connections
rctMu.Lock()
time.Sleep(time.Duration(rand.Uint64N(uint64(time.Second))))
rctMu.Unlock()
conn, err := rct.NewConnection(ctx, uri, rct.WithErrorCallback(func(err error) {
if err != nil {
log.ERROR.Println(err)

View file

@ -23,6 +23,7 @@ var acceptable = []string{
"connect: connection refused",
"connect: network is unreachable",
"i/o timeout",
"timeout", // RCT
"'sma': missing uri or serial", // SMA
"[1ESY1161052714 1ESY1161229249 1EMH0008842285 1ESY1161978584 1EMH0004864048 1ESY1161979033 7ELS8135823805]", // Discovergy
"can only have either uri or device", // modbus