# # PRTG Custom Sensor to read EAC-USB-Stick with 2xS0 and 1Wire-Device # # 20140520 Ver 1.0 Initial Version # 20140526 Ver 1.1 units and Normalization für S0 and temperature added # 20140530 Ver 1.2 Fix: S0 Counter was absolute and not "Difference" param ( [string]$comport = "COM4", [long]$bitrate = "9600", # default baud rate [long]$S0Afactor= 1000, # used to divide the [long]$S0Bfactor= 1000 # ) [hashtable]$1wirename = @{ "1016EEAC020800E8"="SensorRack1"; "1016EEAC020800E9"="SensorRack2" } $1wirelist=@{} [string]$prtgresult="" $prtgresult+="`r`n" $prtgresult+="`r`n" $port= new-Object System.IO.Ports.SerialPort $comport,$bitrate,None,8,one $port.ReadTimeout=5000 $port.WriteTimeout=5000 $port.open() $port.WriteLine('$?') write-host "Scanning 1-Wire on Port $comport" start-sleep -milliseconds 1000 while ($port.BytesToRead -ne 0) { $line = $port.ReadLine() if ($line.startswith('$S0')) { Write-host "Found S0-Line $line" $s0array = $line -split(';') write-host " S0-Counter1 = " $s0array[1] write-host " S0-Counter2 = " $s0array[2] $prtgresult+=" `r`n" $prtgresult+=" S0-A`r`n" $prtgresult+=" "+(([long]$s0array[1])/$S0Afactor)+"`r`n" $prtgresult+=" 1`r`n" $prtgresult+=" Difference" $prtgresult+=" `r`n" $prtgresult+=" `r`n" $prtgresult+=" S0-B`r`n" $prtgresult+=" "+(([long]$s0array[2])/$S0Bfactor)+"`r`n" $prtgresult+=" 1`r`n" $prtgresult+=" Difference" $prtgresult+=" `r`n" } else { Write-host "Found 1Wire-Device: $line" $1wirearray = $line -split(';') $1wirelist.add($1wirearray[0],$1wirearray[2]) } } if ($1wirelist.count -ne 0) { foreach ($key in $1wirelist.keys) { $port.WriteLine($key) start-sleep -milliseconds 100 $1wiredata = $port.ReadLine() write-host (" 1wireData: Device:" + $1wirelist.item($key)) write-host (" 1wireData: Data:" + $1wiredata) $1wiredataarray = $1wiredata.split(";") if ( ($1wirelist.item($key)).startswith("10") ) { $highbyte = [Convert]::ToInt32($1wiredataarray[3],16) $lowbyte = [Convert]::ToInt32($1wiredataarray[2],16) if ($HighByte -eq 00) { $Temperature = $LowByte * 0.5 } else { $Temperature = (256- $LowByte) * - 0.5 } $Temperature = [math]::round($Temperature*10)/10 # reduce the 1/10th digit to one write-host "Temperatur $Temperature" $prtgresult+=" `r`n" if ($1wirename.containskey($1wirelist.item($key))) { $prtgresult+=(" "+$1wirename.item($1wirelist.item($key))+"`r`n") } else { $prtgresult+=(" "+$1wirelist.item($key)+"`r`n") } $prtgresult+=" "+$Temperature+"`r`n" $prtgresult+=" 1`r`n" #$prtgresult+=" Grad C`r`n" #$prtgresult+=" Absolute`r`n" $prtgresult+=" `r`n" } } } $prtgresult+="" write-host "Sending PRTGRESuLT to STDOuT" $prtgresult $port.Close()