Skip to content

Commit

Permalink
Add RSSI series and graphs; deduplicate series
Browse files Browse the repository at this point in the history
  • Loading branch information
suurkivi committed Apr 12, 2024
1 parent d08b491 commit 2bcce2d
Showing 3 changed files with 43 additions and 10 deletions.
26 changes: 22 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import (
"github.com/minor-industries/bbqueue/radio"
"github.com/minor-industries/rtgraph"
"github.com/minor-industries/rtgraph/database"
"github.com/minor-industries/rtgraph/schema"
"github.com/pkg/errors"
"os"
"strings"
@@ -39,6 +40,7 @@ func Run() error {
"bbqueue_bbq01_bbq",
"bbqueue_bbq01_meat",
"bbqueue_bbq01_voltage",
"bbqueue_bbq01_rssi",
},
)
if err != nil {
@@ -54,13 +56,29 @@ func Run() error {
errCh <- graph.RunServer("0.0.0.0:8076")
}()

t0 := time.Now()
go func() {
lastSeen := map[string]schema.Value{}
for {
err := radio.Poll(func(probeName string, temp float64) error {
//fmt.Println("callback", probeName, temp)
err := radio.Poll(func(seriesName string, value float64) error {
now := time.Now()
name := strings.ReplaceAll(probeName, "-", "_")
err := graph.CreateValue("bbqueue_"+name, now, temp)
fullName := "bbqueue_" + strings.ReplaceAll(seriesName, "-", "_")

last, ok := lastSeen[fullName]
lastSeen[fullName] = schema.Value{
Timestamp: now,
Value: value,
}
if ok {
dt := now.Sub(last.Timestamp)
if dt < time.Second {
fmt.Printf(" %s %0.02f %f\n", fullName, now.Sub(t0).Seconds(), value)
return nil
}
}

fmt.Printf("add %s %0.02f %f\n", fullName, now.Sub(t0).Seconds(), value)
err := graph.CreateValue(fullName, now, value)
return errors.Wrap(err, "create")
})

14 changes: 14 additions & 0 deletions html/index.html
Original file line number Diff line number Diff line change
@@ -105,6 +105,19 @@
windowSize: 24 * hour,
maxGapMs: 10 * second
});

new Graph(document.getElementById("graphdiv5"), {
seriesNames: [
"bbqueue_bbq01_rssi",
],
title: "bbq01 RSSI (24 hr view): {value}",
ylabel: "dBm",
labels: ["x", "y1"],
includeZero: true,
height: 150,
windowSize: 24 * hour,
maxGapMs: 10 * second
});
});
</script>
</head>
@@ -135,6 +148,7 @@
<div id="graphdiv2" class="wide"></div>
<div id="graphdiv3" class="wide"></div>
<div id="graphdiv4" class="wide"></div>
<div id="graphdiv5" class="wide"></div>

</body>
</html>
13 changes: 7 additions & 6 deletions radio/serial.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ import (
"bytes"
"encoding/base64"
"encoding/binary"
"encoding/hex"
"fmt"
"github.com/minor-industries/bbqueue/schema"
"github.com/minor-industries/rfm69"
@@ -127,8 +126,6 @@ func processPacket(cb Callback, p *rfm69.Packet) error {
cmd := p.Payload[0]
data := p.Payload[1:]

fmt.Println(time.Now(), p.RSSI, cmd, p.Src, p.Dst, hex.EncodeToString(data))

switch cmd {
case 0x02:
//fmt.Println(cmd, hex.Dump(data))
@@ -141,15 +138,19 @@ func processPacket(cb Callback, p *rfm69.Packet) error {
if err := cb(probeName, float64(tcData.Temperature)); err != nil {
return errors.Wrap(err, "callback")
}
// TODO: figure out a way to report also RSSI here. Unfortunately we have
// something like bbq01_meat instead of bbq01 to work with here
case 0x03:
tcData := &schema.PowerData{}
err := binary.Read(bytes.NewBuffer(data), binary.LittleEndian, tcData)
if err != nil {
return errors.Wrap(err, "parse power data")
}
probeName := nullTerminatedBytesToString(tcData.Description[:])
probeName += "_voltage"
if err := cb(probeName, float64(tcData.Voltage)); err != nil {
description := nullTerminatedBytesToString(tcData.Description[:])
if err := cb(description+"_voltage", float64(tcData.Voltage)); err != nil {
return errors.Wrap(err, "callback")
}
if err := cb(description+"_rssi", float64(p.RSSI)); err != nil {
return errors.Wrap(err, "callback")
}
}

0 comments on commit 2bcce2d

Please sign in to comment.