Skip to content

Commit

Permalink
Modbus: fix wrong sunspec reading retrieved
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Sep 16, 2022
1 parent 5e6dc44 commit 5a7e9fa
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 23 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ require (
github.com/spf13/cobra v1.5.0
github.com/spf13/jwalterweatherman v1.1.0
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/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
gitlab.com/bboehmke/sunny v0.15.1-0.20211022160056-2fba1c86ade6
golang.org/x/exp v0.0.0-20220827204233-334a2380cb91
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
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.12.0/go.mod h1:b6COn30jlNxbm/V2IqWiNWkJ+vZNiMNksliPCiuKtSI=
github.com/spf13/viper v1.13.0 h1:BWSJ/M+f+3nmdz9bxB+bWX28kkALN2ok11D0rSo8EJU=
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-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
Expand Down Expand Up @@ -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/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/volkszaehler/mbmd v0.0.0-20220907155933-f715cedbb789 h1:H1Yk8BJuoiIhBfng+FODF1NESzi1kNjw6jOHLFEyfrI=
github.com/volkszaehler/mbmd v0.0.0-20220907155933-f715cedbb789/go.mod h1:eOent2+2rOEzi9hLB5gXM4Vfq4Yr1BM/uJDGtOBBqLs=
github.com/volkszaehler/mbmd v0.0.0-20220916215221-af29846c997e h1:munBQ097V2Vup78oxz/alxro+5Y9BFDrqZ52/E+jhVI=
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/go.mod h1:Rsyu10ZhbEK9pXdk8V6MVnZmTzRG0alMNLMwa0J01fE=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
Expand Down
13 changes: 5 additions & 8 deletions meter/modbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package meter
import (
"errors"
"fmt"
"strings"
"time"

"github.com/evcc-io/evcc/api"
Expand Down Expand Up @@ -93,16 +94,14 @@ func NewModbusFromConfig(other map[string]interface{}) (api.Meter, error) {
device: device,
}

cc.Power = modbus.ReadingName(cc.Power)
if err := modbus.ParseOperation(device, cc.Power, &m.opPower); err != nil {
if err := modbus.ParseOperation(device, strings.ToLower(cc.Power), &m.opPower); err != nil {
return nil, fmt.Errorf("invalid measurement for power: %s", cc.Power)
}

// decorate energy reading
var totalEnergy func() (float64, error)
if cc.Energy != "" {
cc.Energy = modbus.ReadingName(cc.Energy)
if err := modbus.ParseOperation(device, cc.Energy, &m.opEnergy); err != nil {
if err := modbus.ParseOperation(device, strings.ToLower(cc.Energy), &m.opEnergy); err != nil {
return nil, fmt.Errorf("invalid measurement for energy: %s", cc.Energy)
}

Expand All @@ -120,8 +119,7 @@ func NewModbusFromConfig(other map[string]interface{}) (api.Meter, error) {
for _, cc := range cc.Currents {
var opCurrent modbus.Operation

cc = modbus.ReadingName(cc)
if err := modbus.ParseOperation(device, cc, &opCurrent); err != nil {
if err := modbus.ParseOperation(device, strings.ToLower(cc), &opCurrent); err != nil {
return nil, fmt.Errorf("invalid measurement for current: %s", cc)
}

Expand All @@ -138,8 +136,7 @@ func NewModbusFromConfig(other map[string]interface{}) (api.Meter, error) {
// decorate soc reading
var soc func() (float64, error)
if cc.SoC != "" {
cc.SoC = modbus.ReadingName(cc.SoC)
if err := modbus.ParseOperation(device, cc.SoC, &m.opSoC); err != nil {
if err := modbus.ParseOperation(device, strings.ToLower(cc.SoC), &m.opSoC); err != nil {
return nil, fmt.Errorf("invalid measurement for soc: %s", cc.SoC)
}

Expand Down
4 changes: 1 addition & 3 deletions provider/modbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ func NewModbusFromConfig(other map[string]interface{}) (IntProvider, error) {

// model + value configured
if cc.Value != "" {
cc.Value = modbus.ReadingName(cc.Value)
if err := modbus.ParseOperation(device, cc.Value, &op); err != nil {
if err := modbus.ParseOperation(device, strings.ToLower(cc.Value), &op); err != nil {
return nil, fmt.Errorf("invalid value %s", cc.Value)
}
}
Expand Down Expand Up @@ -174,7 +173,6 @@ func (m *Modbus) floatGetter() (f float64, err error) {
// if funccode is not configured, try find the reading on sunspec
if dev, ok := m.device.(*sunspec.SunSpec); ok {
if m.op.MBMD.IEC61850 != 0 {
// client := m.conn.ModbusClient()
res, err = dev.QueryOp(m.conn, m.op.MBMD.IEC61850)
} else {
if res.Value, err = dev.QueryPoint(
Expand Down
6 changes: 0 additions & 6 deletions util/modbus/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ import (
"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 {
bits := binary.BigEndian.Uint64(b)
return math.Float64frombits(bits)
Expand Down

2 comments on commit 5a7e9fa

@thierolm
Copy link
Contributor

@thierolm thierolm commented on 5a7e9fa Sep 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hallo @andig , Hab den fix ausprobiert. Jetzt passt der SoC, aber der Power Wert hat ein Problem:
Auch grid und pv bekommen jetzt keine Werte mehr:

thierolm@accffmmt:~/evcc$ ./evcc -c ./evcc_fritzdecttest.yaml -l debug meter
[main  ] INFO 2022/09/17 08:21:05 evcc 0.101.1 (5a7e9fa5)
[main  ] INFO 2022/09/17 08:21:05 using config file ./evcc_fritzdecttest.yaml
pv
--
Power: add[0]: model 160 block 1 point dcw: no such point

battery
-------
Power: add[0]: model 160 block 3 point dcw: no such point
SoC:   6%

grid
----
Power:          no such point
Current L1..L3: no such point

Meine Config dazu:

- type: template
  template: fronius-gen24
  usage: grid
  host: 213.157.xxx.xxx
  port: 502
  integer: false
  name: grid

- type: template
  template: fronius-gen24
  usage: pv
  host: 213.157.xxx.xxx
  port: 502
  integer: false
  name: pv

- type: template
  template: fronius-gen24
  usage: battery
  host: 213.157.xxx.xxx
  port: 502
  integer: false
  name: battery

@DEH309
Copy link

@DEH309 DEH309 commented on 5a7e9fa Sep 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auch grid und pv bekommen jetzt keine Werte mehr:

Kann ich bestätigen

Please sign in to comment.