Advertisement
DeaD_EyE

udoo_advanced_plus_cpu_temp_python

May 27th, 2018
838
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement