mirror of
				https://github.com/brianshea2/meshmap.net.git
				synced 2025-03-05 21:00:01 -08:00 
			
		
		
		
	collect some additional EnvironmentMetrics (#34)
This commit is contained in:
		
							parent
							
								
									ca2b7b3dd1
								
							
						
					
					
						commit
						547e76a6e2
					
				|  | @ -107,15 +107,32 @@ 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() | ||||
| 			rainfall := 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}", | ||||
| 				from, topic, portNum, temperature, relativeHumidity, barometricPressure, lux, | ||||
| 				windDirection, windSpeed, windGust, radiation, rainfall, | ||||
| 			) | ||||
| 			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, | ||||
| 				rainfall, | ||||
| 			) | ||||
| 			NodesMutex.Unlock() | ||||
| 		} | ||||
| 	case generated.PortNum_NEIGHBORINFO_APP: | ||||
|  |  | |||
|  | @ -54,6 +54,12 @@ 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"` | ||||
| 	Rainfall               float32 `json:"rainfall,omitempty"` | ||||
| 	LastEnvironmentMetrics int64   `json:"lastEnvironmentMetrics,omitempty"` | ||||
| 	// NeighborInfo
 | ||||
| 	Neighbors map[uint32]*NeighborInfo `json:"neighbors,omitempty"` | ||||
|  | @ -80,6 +86,12 @@ 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.Rainfall = 0 | ||||
| 	node.LastEnvironmentMetrics = 0 | ||||
| } | ||||
| 
 | ||||
|  | @ -163,10 +175,16 @@ 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, rainfall 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.Rainfall = cleanFloat(rainfall) | ||||
| 	node.LastEnvironmentMetrics = time.Now().Unix() | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue