Sungrow: add heartbeat (#27388)
This commit is contained in:
parent
5738399a49
commit
0c1dcfc69a
1 changed files with 16 additions and 0 deletions
|
|
@ -21,6 +21,7 @@ import (
|
|||
"context"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
|
|
@ -95,9 +96,24 @@ func NewSungrow(ctx context.Context, uri, device, comset string, baudrate int, p
|
|||
curr: 60,
|
||||
}
|
||||
|
||||
go wb.heartbeat(ctx)
|
||||
|
||||
return wb, nil
|
||||
}
|
||||
|
||||
func (wb *Sungrow) heartbeat(ctx context.Context) {
|
||||
for tick := time.Tick(30 * time.Second); ; {
|
||||
select {
|
||||
case <-tick:
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
if _, err := wb.conn.ReadInputRegisters(sgRegState, 1); err != nil {
|
||||
wb.log.ERROR.Println("heartbeat:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// getPhaseValues returns 3 non-sequential register values
|
||||
func (wb *Sungrow) getPhaseValues(regs []uint16, divider float64) (float64, float64, float64, error) {
|
||||
var res [3]float64
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue