Modbus: fix wrong sunspec reading retrieved
Some checks failed
Release / call-build-workflow (push) Has been cancelled
Release / Publish Docker :release (push) Has been cancelled
Release / Github & APT (push) Has been cancelled
Release / Hassio Addon (push) Has been cancelled

This commit is contained in:
andig 2022-09-16 23:59:13 +02:00
parent 5e6dc44ba8
commit 5a7e9fa56d
5 changed files with 12 additions and 23 deletions

4
go.mod
View file

@ -72,10 +72,10 @@ require (
github.com/spf13/cobra v1.5.0 github.com/spf13/cobra v1.5.0
github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/jwalterweatherman v1.1.0
github.com/spf13/pflag v1.0.5 github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.12.0 github.com/spf13/viper v1.13.0
github.com/stretchr/testify v1.8.0 github.com/stretchr/testify v1.8.0
github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c
github.com/volkszaehler/mbmd v0.0.0-20220907155933-f715cedbb789 github.com/volkszaehler/mbmd v0.0.0-20220916215221-af29846c997e
github.com/writeas/go-strip-markdown v2.0.1+incompatible github.com/writeas/go-strip-markdown v2.0.1+incompatible
gitlab.com/bboehmke/sunny v0.15.1-0.20211022160056-2fba1c86ade6 gitlab.com/bboehmke/sunny v0.15.1-0.20211022160056-2fba1c86ade6
golang.org/x/exp v0.0.0-20220827204233-334a2380cb91 golang.org/x/exp v0.0.0-20220827204233-334a2380cb91

8
go.sum
View file

@ -818,8 +818,8 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.6.3/go.mod h1:jUMtyi0/lB5yZH/FjyGAoH7IMNrIhlBf6pXZmbMDvzw= github.com/spf13/viper v1.6.3/go.mod h1:jUMtyi0/lB5yZH/FjyGAoH7IMNrIhlBf6pXZmbMDvzw=
github.com/spf13/viper v1.12.0 h1:CZ7eSOd3kZoaYDLbXnmzgQI5RlciuXBMA+18HwHRfZQ= github.com/spf13/viper v1.13.0 h1:BWSJ/M+f+3nmdz9bxB+bWX28kkALN2ok11D0rSo8EJU=
github.com/spf13/viper v1.12.0/go.mod h1:b6COn30jlNxbm/V2IqWiNWkJ+vZNiMNksliPCiuKtSI= github.com/spf13/viper v1.13.0/go.mod h1:Icm2xNL3/8uyh/wFuB1jI7TiTNKp8632Nwegu+zgdYw=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
@ -863,8 +863,8 @@ github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/volkszaehler/mbmd v0.0.0-20220907155933-f715cedbb789 h1:H1Yk8BJuoiIhBfng+FODF1NESzi1kNjw6jOHLFEyfrI= github.com/volkszaehler/mbmd v0.0.0-20220916215221-af29846c997e h1:munBQ097V2Vup78oxz/alxro+5Y9BFDrqZ52/E+jhVI=
github.com/volkszaehler/mbmd v0.0.0-20220907155933-f715cedbb789/go.mod h1:eOent2+2rOEzi9hLB5gXM4Vfq4Yr1BM/uJDGtOBBqLs= github.com/volkszaehler/mbmd v0.0.0-20220916215221-af29846c997e/go.mod h1:/vT7enSAahS3dQiDF4unUeiOGrikhe6AllhVIEBjtNg=
github.com/writeas/go-strip-markdown v2.0.1+incompatible h1:IIqxTM5Jr7RzhigcL6FkrCNfXkvbR+Nbu1ls48pXYcw= github.com/writeas/go-strip-markdown v2.0.1+incompatible h1:IIqxTM5Jr7RzhigcL6FkrCNfXkvbR+Nbu1ls48pXYcw=
github.com/writeas/go-strip-markdown v2.0.1+incompatible/go.mod h1:Rsyu10ZhbEK9pXdk8V6MVnZmTzRG0alMNLMwa0J01fE= github.com/writeas/go-strip-markdown v2.0.1+incompatible/go.mod h1:Rsyu10ZhbEK9pXdk8V6MVnZmTzRG0alMNLMwa0J01fE=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=

View file

@ -3,6 +3,7 @@ package meter
import ( import (
"errors" "errors"
"fmt" "fmt"
"strings"
"time" "time"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
@ -93,16 +94,14 @@ func NewModbusFromConfig(other map[string]interface{}) (api.Meter, error) {
device: device, device: device,
} }
cc.Power = modbus.ReadingName(cc.Power) if err := modbus.ParseOperation(device, strings.ToLower(cc.Power), &m.opPower); err != nil {
if err := modbus.ParseOperation(device, cc.Power, &m.opPower); err != nil {
return nil, fmt.Errorf("invalid measurement for power: %s", cc.Power) return nil, fmt.Errorf("invalid measurement for power: %s", cc.Power)
} }
// decorate energy reading // decorate energy reading
var totalEnergy func() (float64, error) var totalEnergy func() (float64, error)
if cc.Energy != "" { if cc.Energy != "" {
cc.Energy = modbus.ReadingName(cc.Energy) if err := modbus.ParseOperation(device, strings.ToLower(cc.Energy), &m.opEnergy); err != nil {
if err := modbus.ParseOperation(device, cc.Energy, &m.opEnergy); err != nil {
return nil, fmt.Errorf("invalid measurement for energy: %s", cc.Energy) return nil, fmt.Errorf("invalid measurement for energy: %s", cc.Energy)
} }
@ -120,8 +119,7 @@ func NewModbusFromConfig(other map[string]interface{}) (api.Meter, error) {
for _, cc := range cc.Currents { for _, cc := range cc.Currents {
var opCurrent modbus.Operation var opCurrent modbus.Operation
cc = modbus.ReadingName(cc) if err := modbus.ParseOperation(device, strings.ToLower(cc), &opCurrent); err != nil {
if err := modbus.ParseOperation(device, cc, &opCurrent); err != nil {
return nil, fmt.Errorf("invalid measurement for current: %s", cc) return nil, fmt.Errorf("invalid measurement for current: %s", cc)
} }
@ -138,8 +136,7 @@ func NewModbusFromConfig(other map[string]interface{}) (api.Meter, error) {
// decorate soc reading // decorate soc reading
var soc func() (float64, error) var soc func() (float64, error)
if cc.SoC != "" { if cc.SoC != "" {
cc.SoC = modbus.ReadingName(cc.SoC) if err := modbus.ParseOperation(device, strings.ToLower(cc.SoC), &m.opSoC); err != nil {
if err := modbus.ParseOperation(device, cc.SoC, &m.opSoC); err != nil {
return nil, fmt.Errorf("invalid measurement for soc: %s", cc.SoC) return nil, fmt.Errorf("invalid measurement for soc: %s", cc.SoC)
} }

View file

@ -114,8 +114,7 @@ func NewModbusFromConfig(other map[string]interface{}) (IntProvider, error) {
// model + value configured // model + value configured
if cc.Value != "" { if cc.Value != "" {
cc.Value = modbus.ReadingName(cc.Value) if err := modbus.ParseOperation(device, strings.ToLower(cc.Value), &op); err != nil {
if err := modbus.ParseOperation(device, cc.Value, &op); err != nil {
return nil, fmt.Errorf("invalid value %s", cc.Value) return nil, fmt.Errorf("invalid value %s", cc.Value)
} }
} }
@ -174,7 +173,6 @@ func (m *Modbus) floatGetter() (f float64, err error) {
// if funccode is not configured, try find the reading on sunspec // if funccode is not configured, try find the reading on sunspec
if dev, ok := m.device.(*sunspec.SunSpec); ok { if dev, ok := m.device.(*sunspec.SunSpec); ok {
if m.op.MBMD.IEC61850 != 0 { if m.op.MBMD.IEC61850 != 0 {
// client := m.conn.ModbusClient()
res, err = dev.QueryOp(m.conn, m.op.MBMD.IEC61850) res, err = dev.QueryOp(m.conn, m.op.MBMD.IEC61850)
} else { } else {
if res.Value, err = dev.QueryPoint( if res.Value, err = dev.QueryPoint(

View file

@ -9,12 +9,6 @@ import (
"strings" "strings"
) )
// ReadingName formats MBMD reading names
func ReadingName(val string) string {
//lint:ignore SA1019 as Title is safe on ascii
return strings.Title(val)
}
func RTUFloat64ToFloat64(b []byte) float64 { func RTUFloat64ToFloat64(b []byte) float64 {
bits := binary.BigEndian.Uint64(b) bits := binary.BigEndian.Uint64(b)
return math.Float64frombits(bits) return math.Float64frombits(bits)