diff --git a/meter/modbus.go b/meter/modbus.go index 0e7a43767..e3f077395 100644 --- a/meter/modbus.go +++ b/meter/modbus.go @@ -105,7 +105,9 @@ func (m *Modbus) floatGetter(op modbus.Operation) (float64, error) { } } - if err == nil { + if err != nil { + m.conn.Close() // close connection in case of modbus error + } else { m.log.TRACE.Printf("%+v", res) } diff --git a/provider/modbus.go b/provider/modbus.go index 1ad0ac07f..7760bda25 100644 --- a/provider/modbus.go +++ b/provider/modbus.go @@ -124,6 +124,7 @@ func (m *Modbus) FloatGetter() (float64, error) { } if err != nil { + m.conn.Close() // close connection in case of modbus error return 0, errors.Wrap(err, "read failed") } @@ -144,7 +145,9 @@ func (m *Modbus) FloatGetter() (float64, error) { } } - if err == nil { + if err != nil { + m.conn.Close() // close connection in case of modbus error + } else { m.log.TRACE.Printf("%+v", res) }