diff --git a/device b/device new file mode 100755 index 0000000..93540b4 Binary files /dev/null and b/device differ diff --git a/src/main.rs b/src/main.rs index 9bb7cc3..c464930 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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()); diff --git a/src/system_values.rs b/src/system_values.rs index 000bd07..647c490 100644 --- a/src/system_values.rs +++ b/src/system_values.rs @@ -19,20 +19,18 @@ pub fn get_temperature() -> f32 { temperature = temperature_string.parse::().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::().unwrap(); } - println!("Temperature {}", temperature); - return temperature; } @@ -83,4 +81,4 @@ pub fn get_battery() -> i8 { } return battery; -} \ No newline at end of file +}