Compare commits

...

3 commits

3 changed files with 62 additions and 7 deletions

View file

@ -107,15 +107,34 @@ func handleMessage(from uint32, topic string, portNum generated.PortNum, payload
temperature := envMetrics.GetTemperature()
relativeHumidity := envMetrics.GetRelativeHumidity()
barometricPressure := envMetrics.GetBarometricPressure()
lux := envMetrics.GetLux()
windDirection := envMetrics.GetWindDirection()
windSpeed := envMetrics.GetWindSpeed()
windGust := envMetrics.GetWindGust()
radiation := envMetrics.GetRadiation()
rainfall1 := envMetrics.GetRainfall_1H()
rainfall24 := envMetrics.GetRainfall_24H()
log.Printf(
"[msg] %v (%v) %s: EnvironmentMetrics{temperature: %vC; humidity: %v%%; pressure: %vhPA}",
from, topic, portNum, temperature, relativeHumidity, barometricPressure,
"[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, rainfall1, rainfall24,
)
NodesMutex.Lock()
if Nodes[from] == nil {
Nodes[from] = meshtastic.NewNode(topic)
}
Nodes[from].UpdateEnvironmentMetrics(temperature, relativeHumidity, barometricPressure)
Nodes[from].UpdateEnvironmentMetrics(
temperature,
relativeHumidity,
barometricPressure,
lux,
windDirection,
windSpeed,
windGust,
radiation,
rainfall1,
rainfall24,
)
NodesMutex.Unlock()
}
case generated.PortNum_NEIGHBORINFO_APP:

View file

@ -54,6 +54,13 @@ type Node struct {
Temperature float32 `json:"temperature,omitempty"`
RelativeHumidity float32 `json:"relativeHumidity,omitempty"`
BarometricPressure float32 `json:"barometricPressure,omitempty"`
Lux float32 `json:"lux,omitempty"`
WindDirection uint32 `json:"windDirection,omitempty"`
WindSpeed float32 `json:"windSpeed,omitempty"`
WindGust float32 `json:"windGust,omitempty"`
Radiation float32 `json:"radiation,omitempty"`
Rainfall1 float32 `json:"rainfall1,omitempty"`
Rainfall24 float32 `json:"rainfall24,omitempty"`
LastEnvironmentMetrics int64 `json:"lastEnvironmentMetrics,omitempty"`
// NeighborInfo
Neighbors map[uint32]*NeighborInfo `json:"neighbors,omitempty"`
@ -80,6 +87,13 @@ func (node *Node) ClearEnvironmentMetrics() {
node.Temperature = 0
node.RelativeHumidity = 0
node.BarometricPressure = 0
node.Lux = 0
node.WindDirection = 0
node.WindSpeed = 0
node.WindGust = 0
node.Radiation = 0
node.Rainfall1 = 0
node.Rainfall24 = 0
node.LastEnvironmentMetrics = 0
}
@ -163,10 +177,17 @@ func (node *Node) UpdateDeviceMetrics(batteryLevel uint32, voltage, chUtil, airU
node.LastDeviceMetrics = time.Now().Unix()
}
func (node *Node) UpdateEnvironmentMetrics(temperature, relativeHumidity, barometricPressure 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)
node.Lux = cleanFloat(lux)
node.WindDirection = windDirection
node.WindSpeed = cleanFloat(windSpeed)
node.WindGust = cleanFloat(windGust)
node.Radiation = cleanFloat(radiation)
node.Rainfall1 = cleanFloat(rainfall1)
node.Rainfall24 = cleanFloat(rainfall24)
node.LastEnvironmentMetrics = time.Now().Unix()
}

View file

@ -216,7 +216,8 @@
fwVersion, region, modemPreset, hasDefaultCh, onlineLocalNodes,
latitude, longitude, altitude, precision,
batteryLevel, voltage, chUtil, airUtilTx, uptime,
temperature, relativeHumidity, barometricPressure,
temperature, relativeHumidity, barometricPressure, lux,
windDirection, windSpeed, windGust, radiation, rainfall1, rainfall24,
neighbors, seenBy
} = node
const id = `!${Number(nodeNum).toString(16)}`
@ -250,9 +251,23 @@
`${(temperature * 1.8 + 32).toFixed(1)}&#8457;</td></tr>` : ''}
${relativeHumidity ? `<tr><th>Relative Humidity</th><td>${Math.round(relativeHumidity)}%</td></tr>` : ''}
${barometricPressure ? `<tr><th>Barometric Pressure</th><td>${Math.round(barometricPressure)} hPa</td></tr>` : ''}
${lux ? `<tr><th>Lux</th><td>${Math.round(lux)} lx</td></tr>` : ''}
${windDirection || windSpeed ? `<tr><th>Wind</th><td>` +
(windDirection ? `${windDirection}&#176;` : '') +
(windDirection && windSpeed ? ' @ ' : '') +
(windSpeed ? `${(windSpeed * 3.6).toFixed(1)}` : '') +
(windSpeed && windGust ? ` G ${(windGust * 3.6).toFixed(1)}` : '') +
(windSpeed ? ' km/h' : '') +
`</td></tr>` : ''}
${radiation ? `<tr><th>Radiation</th><td>${radiation.toFixed(2)} µR/h</td></tr>` : ''}
${rainfall1 || rainfall24 ? `<tr><th>Rainfall</th><td>` +
(rainfall1 ? `${rainfall1.toFixed(2)} mm/h` : '') +
(rainfall1 && rainfall24 ? ', ' : '') +
(rainfall24 ? `${rainfall24.toFixed(2)} mm/24h` : '') +
`</td></tr>` : ''}
${altitude ? `<tr><th>Altitude</th><td>${altitude.toLocaleString()} m above MSL</td></tr>` : ''}
${precision && precisionMargins[precision-1] ? "<tr><th>Location precision</th><td>&#177;" +
`${precisionMargins[precision-1].toLocaleString()} m (orange circle)</td></tr>` : ''}
${precision && precisionMargins[precision-1] ? `<tr><th>Location precision</th><td>` +
`&#177;${precisionMargins[precision-1].toLocaleString()} m (orange circle)</td></tr>` : ''}
</tbody></table>
<table><thead>
<tr><th>Last seen</th><th>via</th><th>root topic</th><th>channel</th></tr>