Skip to content

Commit 2257b9a

Browse files
author
kubaceg
committed
Exceeded reconnect timeout
1 parent ed02835 commit 2257b9a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

main.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import (
1616
"github.com/kubaceg/sofar_g3_lsw3_logger_reader/ports"
1717
)
1818

19+
// maximumFailedConnections maximum number failed logger connection, after this number will be exceeded reconnect
20+
// interval will be extended from 5s to readInterval defined in config file
21+
const maximumFailedConnections = 3
22+
1923
var (
2024
config *Config
2125
port ports.CommunicationPort
@@ -55,6 +59,7 @@ func initialize() {
5559

5660
func main() {
5761
initialize()
62+
failedConnections := 0
5863

5964
for {
6065
log.Printf("performing measurements")
@@ -63,10 +68,17 @@ func main() {
6368
measurements, err := device.Query()
6469
if err != nil {
6570
log.Printf("failed to perform measurements: %s", err)
66-
time.Sleep(5 * time.Second)
71+
failedConnections++
72+
73+
if failedConnections > maximumFailedConnections {
74+
time.Sleep(time.Duration(config.Inverter.ReadInterval) * time.Second)
75+
}
76+
6777
continue
6878
}
6979

80+
failedConnections = 0
81+
7082
if hasMQTT {
7183
err = mqtt.InsertRecord(measurements)
7284
if err != nil {

0 commit comments

Comments
 (0)