try to work around timeouts

This commit is contained in:
Javier Peletier
2020-12-16 21:47:55 +01:00
parent 9c7b5313e3
commit d9edc624fe
5 changed files with 64 additions and 49 deletions

13
main.go
View File

@@ -143,9 +143,11 @@ func main() {
connOpts.OnConnect = func(c MQTT.Client) {
onConnect = true
}
var started bool
connOpts.OnConnectionLost = func(c MQTT.Client, err error) {
log.Printf("Connection to MQTT server lost: %s\n", err)
mqttClient = nil
started = false
}
connectMQTT := func() error {
@@ -160,8 +162,7 @@ func main() {
return nil
}
ticker := time.NewTicker(time.Second)
ticker := time.NewTicker(2 * time.Second)
go func() {
for range ticker.C {
if mqttClient == nil {
@@ -181,11 +182,15 @@ func main() {
log.Printf("Error starting bridge: %s\n", err)
client.Disconnect(100)
mqttClient = nil
} else {
started = true
}
}
} else {
for _, b := range bridges {
b.Tick()
if started {
for _, b := range bridges {
b.Tick()
}
}
}
}