add raspbian temp
This commit is contained in:
@@ -10,8 +10,6 @@ fn main() {
|
||||
|
||||
device_var::read_env_var();
|
||||
|
||||
println!("Resp Temperature : {}", system_values::get_temperature());
|
||||
|
||||
let mut cli = mqtt_pub::init_cli();
|
||||
|
||||
cli = mqtt_pub::publish_message(cli, "temperature", &system_values::get_temperature().to_string());
|
||||
|
||||
@@ -19,20 +19,18 @@ pub fn get_temperature() -> f32 {
|
||||
temperature = temperature_string.parse::<f32>().unwrap();
|
||||
temperature = temperature / 1000.0;
|
||||
} else {
|
||||
let temperature_command = Command::new("cat")
|
||||
.arg("/sys/class/thermal/thermal_zone1/temp")
|
||||
let temperature_command = Command::new("sudo")
|
||||
.arg("/opt/vc/bin/vcgencmd")
|
||||
.arg("measure_temp")
|
||||
.output().unwrap_or_else(|e| {
|
||||
panic!("failed to execute process: {}", e)
|
||||
});
|
||||
|
||||
let temperature_string = &String::from_utf8_lossy(&temperature_command.stdout)[..9];
|
||||
println!("Raspi temp {:?}", temperature_string);
|
||||
|
||||
temperature += 1.0;
|
||||
let mut temperature_string = &String::from_utf8_lossy(&temperature_command.stdout)[5..];
|
||||
temperature_string = &temperature_string[..temperature_string.len() - 3];
|
||||
temperature += temperature_string.parse::<f32>().unwrap();
|
||||
}
|
||||
|
||||
println!("Temperature {}", temperature);
|
||||
|
||||
return temperature;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user