Shuffle and loop

This commit is contained in:
Josh Deprez 2023-01-23 09:39:28 +11:00
parent 097776962c
commit 079cd7efc9
Signed by: josh
SSH key fingerprint: SHA256:zZji7w1Ilh2RuUpbQcqkLPrqmRwpiCSycbF2EfKm6Kw

27
main.go
View file

@ -176,23 +176,18 @@ func scrape() error {
vals := make(map[uint16]float64)
start := time.Now()
scrapeStart.SetToCurrentTime()
if err := readRegs(vals, client, 5000, 24); err != nil {
return err
ranges := []struct{ start, qty uint16 }{
{5000, 24}, {5030, 7}, {5048, 1},
{5082, 18}, {5112, 1}, {5143, 6},
}
if err := readRegs(vals, client, 5030, 7); err != nil {
return err
}
if err := readRegs(vals, client, 5048, 1); err != nil {
return err
}
if err := readRegs(vals, client, 5082, 18); err != nil {
return err
}
if err := readRegs(vals, client, 5112, 1); err != nil {
return err
}
if err := readRegs(vals, client, 5143, 6); err != nil {
return err
rand.Shuffle(len(ranges), func(i, j int) {
ranges[i], ranges[j] = ranges[j], ranges[i]
})
for _, r := range ranges {
if err := readRegs(vals, client, r.start, r.qty); err != nil {
return err
}
}
lastValues = vals