SHARE
TWEET

udoo_advanced_plus_cpu_temp_python

DeaD_EyE May 27th, 2018 (edited) 184 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """
  2. You have to run this script as adminstrator.
  3. PowerShell is used.
  4. I am not sure, if the temperature reading is right.
  5. """
  6.  
  7. import subprocess
  8. import os
  9. import datetime
  10.  
  11. psscript = """
  12. $t = Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace “root/wmi”
  13.  
  14. while (1) {$t.CurrentTemperature; sleep 5}
  15. """
  16.  
  17. si = subprocess.STARTUPINFO()
  18. si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
  19.  
  20. cmd = ['powershell.exe', '-Command',  psscript]
  21. proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, startupinfo=si)
  22.  
  23. with open(r'C:\Users\skyradar\Desktop\temp.txt', 'w') as fd:
  24.     while True:
  25.         tmp = proc.stdout.readline()
  26.         proc.stdout.readline() # hack to prevent output twice
  27.         celsius = int(tmp) / 10 - 273.15
  28.         celsius_str = f'{celsius:.2f};{datetime.datetime.now().isoformat()}'
  29.         print(celsius_str)
  30.         fd.write(celsius_str)
  31.         fd.write(os.linesep)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top