Skip to content

Commit

Permalink
fix: add soil metrix
Browse files Browse the repository at this point in the history
  • Loading branch information
tonygilkerson committed Mar 23, 2024
1 parent fa34776 commit 1200cfa
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
48 changes: 45 additions & 3 deletions cmd/serial/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,33 @@ func serialServer(port *serial.Port) {
var mbxRoadMainLoopHeartbeatCount = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "mbx_road_main_loop_heartbeat_count",
Help: "Heartbeat counter for the main loop for the device down on the road ",
Help: "Heartbeat counter for the main loop for the device down on the road",
},
)
prometheus.MustRegister(mbxRoadMainLoopHeartbeatCount)

//
// Soil Temperature
//
var soilTemperatureFahrenheit = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "soil_temperature_fahrenheit",
Help: "The temperature reading in fahrenheit from the device in the goat field",
},
)
prometheus.MustRegister(soilTemperatureFahrenheit)

//
// Soil Moisture
//
var soilMoisture = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "soil_moisture",
Help: "The moisture reading from the device in the goat field, can range from about 300 to 1,000",
},
)
prometheus.MustRegister(soilMoisture)

//
// Monitor the serial port forever
//
Expand Down Expand Up @@ -205,7 +227,7 @@ func serialServer(port *serial.Port) {
log.Printf("Error converting temperature reading to a float, original input message: %v, error: %v", msg, err)
} else {
mbxTemperatureFahrenheit.Set(f)
log.Printf("set MailboxTemperature to: %v", f)
log.Printf("ACTION: set MailboxTemperature to: %v", f)
}

case msg == iot.MbxMuleAlarm:
Expand All @@ -214,7 +236,7 @@ func serialServer(port *serial.Port) {

case msg == iot.MbxDoorOpened:
mbxMailboxDoorOpenedCount.Inc()
log.Println("increment mbxMailboxDoorOpenedCount")
log.Println("ACTION: increment mbxMailboxDoorOpenedCount")

case msg == iot.MbxChargerChargeStatusOn:
mbxChargerChargeStatus.Set(1)
Expand All @@ -236,6 +258,26 @@ func serialServer(port *serial.Port) {
mbxRoadMainLoopHeartbeatCount.Inc()
log.Println("ACTION: increment mbxRoadMainLoopHeartbeatCount")

case strings.Contains(msg, string(iot.SoilTemperature)):
parts := strings.Split(msg, ":")
f, err := strconv.ParseFloat(parts[1], 64)
if err != nil {
log.Printf("Error converting soil temperature reading to a float, original input message: %v, error: %v", msg, err)
} else {
soilTemperatureFahrenheit.Set(f)
log.Printf("ACTION: set soilTemperatureFahrenheit to: %v", f)
}

case strings.Contains(msg, string(iot.SoilMoisture)):
parts := strings.Split(msg, ":")
f, err := strconv.ParseFloat(parts[1], 64)
if err != nil {
log.Printf("Error converting soil moisture reading to a float, original input message: %v, error: %v", msg, err)
} else {
soilMoisture.Set(f)
log.Printf("ACTION: set soilMoisture to: %v", f)
}

case msg == "":
// eat whitespace

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ require (
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/tonygilkerson/mbx-iot v0.0.6
github.com/tonygilkerson/mbx-iot v0.0.7
golang.org/x/sys v0.6.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
)

// DEVTODO - Remove me when done with development
//replace github.com/tonygilkerson/mbx-iot v0.0.6 => ../mbx-iot
//replace github.com/tonygilkerson/mbx-iot v0.0.7 => ../mbx-iot
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJf
github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 h1:UyzmZLoiDWMRywV4DUYb9Fbt8uiOSooupjTq10vpvnU=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/tonygilkerson/mbx-iot v0.0.6 h1:SeXdhbnOCuaeW8sevWwZocAvOFl+rHWohfALYRqUCRo=
github.com/tonygilkerson/mbx-iot v0.0.6/go.mod h1:V4xbyihcHPMVecJDbXeY21w5OCt/iuIteUlkz9oCwy8=
github.com/tonygilkerson/mbx-iot v0.0.7 h1:qmTL0DhEM03aWRua2xKgJBaX/mAPGvLa8eArXTq7LbQ=
github.com/tonygilkerson/mbx-iot v0.0.7/go.mod h1:V4xbyihcHPMVecJDbXeY21w5OCt/iuIteUlkz9oCwy8=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down

0 comments on commit 1200cfa

Please sign in to comment.