# # Query OpenHardWareMonitor and dump interesting values to the Serial Port # # Author: Henryk Richter # # Date: 02-Jan-2016 # # License: GPLv2 # # Notes: # - my first powershell script, sorry if this is not too efficient # - set policy to allow scripts for current user in powershell: # Set-ExecutionPolicy remotesigned CurrentUser # # $serialport="COM2"; # ABCDEFGHIJ $serialconfig="@TcbzmffugT"; # keywords: t=text,c=cpu,f=fan,m=mem,g=gpu,u=clock face,z=cycles, uppercase=whole line, else two columns, enumerated in commands via A,B,... $hwstrings=@("\/intelcpu/0/temperature/0", "/intelcpu/0/load/0","\/intelcpu/0/clock/1",".*fan/0",".*fan/1","\/nvidiagpu/0/temperature/0", "/ram/load/0" ); $hwunits= @("``C", "", "", "", "", "``C", "%" ); $hwtargets=@("B", "C", "D", "F", "G", "I", "E" ); # sleep 20 # memory, text after clock # wait until we get the serial port $port= new-Object System.IO.Ports.SerialPort $serialport,9600,None,8,one $port.open() while( ! $port.IsOpen ) { sleep 5 $port.open() } $runcount = 0; while( 1 ) { if( $runcount -eq 0 ) { # configure LCD on serial port $port.WriteLine( "`r" + "`r" + "`r" + "`r" + "`r" + "`r" + "`r" + $serialconfig + "`r" ) Start-Sleep -milliseconds 100 } $runcount = $runcount+1 if( $runcount -gt 30 ) # re-init after a number of runs (about 5 minutes) { $runcount = 0 } # just keep IDs, Values and Type $sensors=Get-WmiObject -Namespace 'root/OpenHardwareMonitor' -Class Sensor | select Identifier, Value, SensorType # Sensor values for( $i=0 ; $i -lt $hwstrings.count ; $i++ ) { $s=$sensors | where {$_.Identifier -match $hwstrings[$i]} # $s=$sensors | where {$_.Identifier | findstr $hwstrings[$i]} $curcmd=$hwtargets[$i]+'{0:f0}' -f $s.Value + $hwunits[$i] $port.WriteLine( $curcmd + "`r" ) $curcmd Start-Sleep -milliseconds 20 } # Date/Time $dt=Get-Date $curcmd="H" + $dt.Hour + ":" + '{0:D2}' -f $dt.Minute $port.WriteLine( $curcmd + "`r" ) Start-Sleep -milliseconds 20 # IP Address, Hostname every if( $runcount -eq 1 ) { # Hostname in first line $curcmd="A"+[system.environment]::MachineName $port.WriteLine( $curcmd + "`r" ) Start-Sleep -milliseconds 20 # IP Address in last line (assume just one IPv4 int with DHCP) $ipaddr=Get-NetIPAddress –AddressFamily IPv4 | where {$_.PrefixOrigin -eq "Dhcp"} $curcmd="J"+$ipaddr.IPAddress $port.WriteLine( $curcmd + "`r" ) Start-Sleep -milliseconds 20 } Start-Sleep -seconds 10 } $port.Close()