From caf9e2a2dd985f072f85c11bc97e908f97f8d9d5 Mon Sep 17 00:00:00 2001 From: root <165865819+brianshea2@users.noreply.github.com> Date: Wed, 5 Feb 2025 22:49:37 +0000 Subject: [PATCH] collect and display rain over last hour metric (#34) --- cmd/meshobserv/meshobserv.go | 10 ++++++---- internal/meshtastic/node.go | 11 +++++++---- website/index.html | 9 +++++++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/cmd/meshobserv/meshobserv.go b/cmd/meshobserv/meshobserv.go index 5a38e00..26aba0d 100644 --- a/cmd/meshobserv/meshobserv.go +++ b/cmd/meshobserv/meshobserv.go @@ -112,11 +112,12 @@ func handleMessage(from uint32, topic string, portNum generated.PortNum, payload windSpeed := envMetrics.GetWindSpeed() windGust := envMetrics.GetWindGust() radiation := envMetrics.GetRadiation() - rainfall := envMetrics.GetRainfall_24H() + rainfall1 := envMetrics.GetRainfall_1H() + rainfall24 := envMetrics.GetRainfall_24H() log.Printf( - "[msg] %v (%v) %s: EnvironmentMetrics{temp: %v; hum: %v; pres: %v; lux: %v; wind: %v @ %v G %v; rad: %v; rain: %v}", + "[msg] %v (%v) %s: EnvironmentMetrics{temp: %v; hum: %v; pres: %v; lux: %v; wind: %v @ %v G %v; rad: %v; rain: %v %v}", from, topic, portNum, temperature, relativeHumidity, barometricPressure, lux, - windDirection, windSpeed, windGust, radiation, rainfall, + windDirection, windSpeed, windGust, radiation, rainfall1, rainfall24, ) NodesMutex.Lock() if Nodes[from] == nil { @@ -131,7 +132,8 @@ func handleMessage(from uint32, topic string, portNum generated.PortNum, payload windSpeed, windGust, radiation, - rainfall, + rainfall1, + rainfall24, ) NodesMutex.Unlock() } diff --git a/internal/meshtastic/node.go b/internal/meshtastic/node.go index 945e9b6..12a2a8f 100644 --- a/internal/meshtastic/node.go +++ b/internal/meshtastic/node.go @@ -59,7 +59,8 @@ type Node struct { WindSpeed float32 `json:"windSpeed,omitempty"` WindGust float32 `json:"windGust,omitempty"` Radiation float32 `json:"radiation,omitempty"` - Rainfall float32 `json:"rainfall,omitempty"` + Rainfall1 float32 `json:"rainfall1,omitempty"` + Rainfall24 float32 `json:"rainfall24,omitempty"` LastEnvironmentMetrics int64 `json:"lastEnvironmentMetrics,omitempty"` // NeighborInfo Neighbors map[uint32]*NeighborInfo `json:"neighbors,omitempty"` @@ -91,7 +92,8 @@ func (node *Node) ClearEnvironmentMetrics() { node.WindSpeed = 0 node.WindGust = 0 node.Radiation = 0 - node.Rainfall = 0 + node.Rainfall1 = 0 + node.Rainfall24 = 0 node.LastEnvironmentMetrics = 0 } @@ -175,7 +177,7 @@ func (node *Node) UpdateDeviceMetrics(batteryLevel uint32, voltage, chUtil, airU node.LastDeviceMetrics = time.Now().Unix() } -func (node *Node) UpdateEnvironmentMetrics(temperature, relativeHumidity, barometricPressure, lux float32, windDirection uint32, windSpeed, windGust, radiation, rainfall float32) { +func (node *Node) UpdateEnvironmentMetrics(temperature, relativeHumidity, barometricPressure, lux float32, windDirection uint32, windSpeed, windGust, radiation, rainfall1, rainfall24 float32) { node.Temperature = cleanFloat(temperature) node.RelativeHumidity = cleanFloat(relativeHumidity) node.BarometricPressure = cleanFloat(barometricPressure) @@ -184,7 +186,8 @@ func (node *Node) UpdateEnvironmentMetrics(temperature, relativeHumidity, barome node.WindSpeed = cleanFloat(windSpeed) node.WindGust = cleanFloat(windGust) node.Radiation = cleanFloat(radiation) - node.Rainfall = cleanFloat(rainfall) + node.Rainfall1 = cleanFloat(rainfall1) + node.Rainfall24 = cleanFloat(rainfall24) node.LastEnvironmentMetrics = time.Now().Unix() } diff --git a/website/index.html b/website/index.html index 4423a8e..fe7118f 100644 --- a/website/index.html +++ b/website/index.html @@ -216,7 +216,8 @@ fwVersion, region, modemPreset, hasDefaultCh, onlineLocalNodes, latitude, longitude, altitude, precision, batteryLevel, voltage, chUtil, airUtilTx, uptime, - temperature, relativeHumidity, barometricPressure, lux, windDirection, windSpeed, windGust, radiation, rainfall, + temperature, relativeHumidity, barometricPressure, lux, + windDirection, windSpeed, windGust, radiation, rainfall1, rainfall24, neighbors, seenBy } = node const id = `!${Number(nodeNum).toString(16)}` @@ -259,7 +260,11 @@ (windSpeed ? ' km/h' : '') + `` : ''} ${radiation ? `