Keep skipped values, split reads more

This commit is contained in:
Josh Deprez 2023-01-22 13:51:05 +11:00
parent 8408517b7d
commit 9fe38095fb
Signed by: josh
SSH key fingerprint: SHA256:zZji7w1Ilh2RuUpbQcqkLPrqmRwpiCSycbF2EfKm6Kw
2 changed files with 19 additions and 7 deletions

23
main.go
View file

@ -142,11 +142,11 @@ func readRegs(vals map[uint16]float64, client modbus.Client, start, qty uint16)
}
val, err := reg.read(data[(addr-start-1)*2:])
if err != nil {
if errors.Is(err, errSkippableRead) {
log.Printf("Couldn't parse input register data at %d, skipping: %v", addr, err)
continue
if !errors.Is(err, errSkippableRead) {
return fmt.Errorf("parse input register data at %d: %v", addr, err)
}
return fmt.Errorf("parse input register data at %d: %v", addr, err)
log.Printf("Couldn't parse input register data at %d, skipping: %v", addr, err)
val = lastValues[addr]
}
//fmt.Printf("%s: %v %s\n", reg.name, val, reg.unit)
vals[addr] = val
@ -171,13 +171,22 @@ func scrape() error {
vals := make(map[uint16]float64)
start := time.Now()
scrapeStart.SetToCurrentTime()
if err := readRegs(vals, client, 5000, 50); err != nil {
if err := readRegs(vals, client, 5001, 24); err != nil {
return err
}
if err := readRegs(vals, client, 5050, 50); err != nil {
if err := readRegs(vals, client, 5031, 7); err != nil {
return err
}
if err := readRegs(vals, client, 5100, 50); err != nil {
if err := readRegs(vals, client, 5049, 1); err != nil {
return err
}
if err := readRegs(vals, client, 5083, 18); err != nil {
return err
}
if err := readRegs(vals, client, 5113, 1); err != nil {
return err
}
if err := readRegs(vals, client, 5144, 6); err != nil {
return err
}

View file

@ -54,10 +54,12 @@ var sungrowInputRegs = map[uint16]*register{
5022: {"phase_a_current", u16req, 0.1, "A"},
5023: {"phase_b_current", u16opt, 0.1, "A"},
5024: {"phase_c_current", u16opt, 0.1, "A"},
5031: {"output_real_power", u32req, 1, "VA"},
5033: {"output_reactive_power", s32opt, 1, "VAr"},
5035: {"power_factor", s16opt, 0.001, ""},
5036: {"frequency", u16req, 0.1, "Hz"},
5049: {"nominal_reactive_power", s16opt, 0.1, "kVA"},
5083: {"meter_power", s32req, 1, "W"},
@ -71,6 +73,7 @@ var sungrowInputRegs = map[uint16]*register{
5099: {"total_import_energy", u32req, 0.1, "kWh"},
5113: {"daily_running_time", u16req, 1, "m"},
5144: {"total_power_yield_2", u32req, 0.1, "kWh"},
5148: {"frequency_2", frequency2, 0.01, "Hz"},
}