fix:修改解析函数
This commit is contained in:
parent
cf13a05796
commit
7a42d03a98
@ -12,9 +12,16 @@ type SensorData struct {
|
|||||||
WindDirection360 int `json:"wind_direction_360"` // 360度风向
|
WindDirection360 int `json:"wind_direction_360"` // 360度风向
|
||||||
Humidity int `json:"humidity"` // 湿度
|
Humidity int `json:"humidity"` // 湿度
|
||||||
Temperature int `json:"temperature"` // 温度
|
Temperature int `json:"temperature"` // 温度
|
||||||
|
Noise int `json:"noise"` // 噪声
|
||||||
|
PM25 int `json:"pm25"` // PM2.5
|
||||||
|
PM10 int `json:"pm10"` // PM10
|
||||||
AtmPressure int `json:"atm_pressure"` // 大气压
|
AtmPressure int `json:"atm_pressure"` // 大气压
|
||||||
|
Lux20WH int `json:"lux_20w_h"` // 20W Lux值(高16位)
|
||||||
|
Lux20WL int `json:"lux_20w_l"` // 20W Lux值(低16位)
|
||||||
|
Light20W int `json:"light_20w"` // 20W光照
|
||||||
|
OpticalRain int `json:"optical_rain"` // 光学雨量
|
||||||
|
CompassAngle int `json:"compass_angle"` // 电子指南针角度
|
||||||
SolarRadiation int `json:"solar_radiation"` // 太阳辐射
|
SolarRadiation int `json:"solar_radiation"` // 太阳辐射
|
||||||
Rainfall int `json:"rainfall"` // 累计雨量
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AggregatedData 聚合数据结构
|
// AggregatedData 聚合数据结构
|
||||||
|
|||||||
@ -229,21 +229,35 @@ func (s *SensorComm) handleData(data []byte) *model.SensorData {
|
|||||||
WindDirection360: int(binary.BigEndian.Uint16(data[9:11])), // 360度风向
|
WindDirection360: int(binary.BigEndian.Uint16(data[9:11])), // 360度风向
|
||||||
Humidity: int(binary.BigEndian.Uint16(data[11:13])), // 湿度*10
|
Humidity: int(binary.BigEndian.Uint16(data[11:13])), // 湿度*10
|
||||||
Temperature: int(binary.BigEndian.Uint16(data[13:15])), // 温度*10
|
Temperature: int(binary.BigEndian.Uint16(data[13:15])), // 温度*10
|
||||||
|
Noise: int(binary.BigEndian.Uint16(data[15:17])), // 噪声*10
|
||||||
|
PM25: int(binary.BigEndian.Uint16(data[17:19])), // PM2.5
|
||||||
|
PM10: int(binary.BigEndian.Uint16(data[19:21])), // PM10
|
||||||
AtmPressure: int(binary.BigEndian.Uint16(data[21:23])), // 大气压*10
|
AtmPressure: int(binary.BigEndian.Uint16(data[21:23])), // 大气压*10
|
||||||
|
Lux20WH: int(binary.BigEndian.Uint16(data[23:25])), // 20W Lux值(高16位)
|
||||||
|
Lux20WL: int(binary.BigEndian.Uint16(data[25:27])), // 20W Lux值(低16位)
|
||||||
|
Light20W: int(binary.BigEndian.Uint16(data[27:29])), // 20W光照
|
||||||
|
OpticalRain: int(binary.BigEndian.Uint16(data[29:31])), // 光学雨量*10
|
||||||
|
CompassAngle: int(binary.BigEndian.Uint16(data[31:33])), // 电子指南针角度*100
|
||||||
SolarRadiation: int(binary.BigEndian.Uint16(data[33:35])), // 太阳辐射
|
SolarRadiation: int(binary.BigEndian.Uint16(data[33:35])), // 太阳辐射
|
||||||
Rainfall: int(binary.BigEndian.Uint16(data[15:17])), // 光学雨量*10
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 记录解析后的传感器数据,展示实际物理量
|
// 记录解析后的传感器数据,展示实际物理量
|
||||||
logger.Logger.Printf("传感器数据: 风速=%.2f m/s, 风力=%d级, 风向=%d°, 湿度=%.1f%%, 温度=%.1f℃, 大气压=%.1f kPa, 太阳辐射=%d W/m², 光学雨量=%.1f mm",
|
logger.Logger.Printf("传感器数据: 风速=%.2f m/s, 风力=%d级, 风向=%d°, 湿度=%.1f%%, 温度=%.1f℃, 噪声=%.1f dB, PM2.5=%d μg/m³, PM10=%d μg/m³, 大气压=%.1f kPa, 20W Lux值=%d/%d, 20W光照=%d 百Lux, 光学雨量=%.1f mm, 电子指南针角度=%.2f°, 太阳辐射=%d W/m²",
|
||||||
float64(sensorData.WindSpeed)/100.0,
|
float64(sensorData.WindSpeed)/100.0,
|
||||||
sensorData.WindForce,
|
sensorData.WindForce,
|
||||||
sensorData.WindDirection360,
|
sensorData.WindDirection360,
|
||||||
float64(sensorData.Humidity)/10.0,
|
float64(sensorData.Humidity)/10.0,
|
||||||
float64(sensorData.Temperature)/10.0,
|
float64(sensorData.Temperature)/10.0,
|
||||||
|
float64(sensorData.Noise)/10.0,
|
||||||
|
sensorData.PM25,
|
||||||
|
sensorData.PM10,
|
||||||
float64(sensorData.AtmPressure)/10.0,
|
float64(sensorData.AtmPressure)/10.0,
|
||||||
sensorData.SolarRadiation,
|
sensorData.Lux20WH,
|
||||||
float64(sensorData.Rainfall)/10.0)
|
sensorData.Lux20WL,
|
||||||
|
sensorData.Light20W,
|
||||||
|
float64(sensorData.OpticalRain)/10.0,
|
||||||
|
float64(sensorData.CompassAngle)/100.0,
|
||||||
|
sensorData.SolarRadiation)
|
||||||
|
|
||||||
// 保存数据到数据库
|
// 保存数据到数据库
|
||||||
if err := s.dao.Insert(sensorData); err != nil {
|
if err := s.dao.Insert(sensorData); err != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user