import os
# Function to get the CPU temperature using ADB
def get_cpu_temperature():
try:
# Run the ADB command and redirect the output to a temporary file
os.system("adb shell cat /sys/class/thermal/thermal_zone0/temp > temp.txt")
# Read the temperature from the temporary file and convert to Celsius
with open("temp.txt", "r") as file:
temperature = int(file.read().strip()) / 1000.0
return temperature
except Exception as e:
print("Error:", e)
return None
finally:
# Remove the temporary file
os.remove("temp.txt")
# Function to check temperature and trigger alarm if necessary
def check_temperature_and_notify(threshold):
temperature = get_cpu_temperature()
if temperature is not None:
print(f"CPU Temperature: {temperature:.2f} °C")
if temperature > threshold:
print("CPU temperature is above the threshold!")
# Add your alarm/notification logic here
if __name__ == "__main__":
threshold = 40.0 # Set the temperature threshold here
check_temperature_and_notify(threshold)
Comments
Post a Comment