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