File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,10 @@ import (
16
16
"github.com/kubaceg/sofar_g3_lsw3_logger_reader/ports"
17
17
)
18
18
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
+
19
23
var (
20
24
config * Config
21
25
port ports.CommunicationPort
@@ -55,6 +59,7 @@ func initialize() {
55
59
56
60
func main () {
57
61
initialize ()
62
+ failedConnections := 0
58
63
59
64
for {
60
65
log .Printf ("performing measurements" )
@@ -63,10 +68,17 @@ func main() {
63
68
measurements , err := device .Query ()
64
69
if err != nil {
65
70
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
+
67
77
continue
68
78
}
69
79
80
+ failedConnections = 0
81
+
70
82
if hasMQTT {
71
83
err = mqtt .InsertRecord (measurements )
72
84
if err != nil {
You can’t perform that action at this time.
0 commit comments