succd: Do not exit prematurely if modbus connections fails
All checks were successful
/ test (push) Successful in 10s
/ test (pull_request) Successful in 11s

This commit is contained in:
hmelder 2024-11-15 23:49:26 +01:00
parent 3b9c1ba912
commit 6bd2d18ce2
2 changed files with 14 additions and 25 deletions

View file

@ -6,7 +6,9 @@ import (
"net/http" "net/http"
"os" "os"
"os/signal" "os/signal"
"time"
"github.com/simonvetter/modbus"
"k8s.io/klog" "k8s.io/klog"
) )
@ -55,9 +57,19 @@ func main() {
} }
d.adcPirani = adc d.adcPirani = adc
err = d.modbusConnect() // Setup modbus client
d.modbusClient, err = modbus.NewClient(&modbus.ClientConfiguration{
URL: "tcp://10.250.241.20:8887",
Timeout: 1 * time.Second,
})
if err != nil { if err != nil {
klog.Exitf("Failed to connect to modbus %v", err) klog.Exitf("Failed to setup modbus client %v", err)
}
// Connect to modbus client
err = d.modbusClient.Open()
if err != nil {
klog.Warningf("Failed to connect to modbus TCP %v", err)
} }
} }

View file

@ -12,29 +12,6 @@ func modbusValuesToFloat(v uint16) float32 {
return float32(v) / 10.0 return float32(v) / 10.0
} }
func (d *daemon) modbusConnect() error {
var err error
d.mu.Lock()
defer d.mu.Unlock()
// Setup modbus client
d.modbusClient, err = modbus.NewClient(&modbus.ClientConfiguration{
URL: "tcp://10.250.241.20:8887",
Timeout: 1 * time.Second,
})
if err != nil {
return err
}
// Connect to modbus client
err = d.modbusClient.Open()
if err != nil {
return err
}
return nil
}
func (d *daemon) modbusRestart() error { func (d *daemon) modbusRestart() error {
d.modbusClient.Close() d.modbusClient.Close()
return d.modbusClient.Open() return d.modbusClient.Open()