Log firmware and RSSI levels with powershell

cls

function Get-TimeStamp {
 
    return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
    
}

$udpobject = new-Object system.Net.Sockets.Udpclient(50222)
$udpobject.EnableBroadcast=$true
$a = new-object system.text.asciiencoding
$receivebytes.clear()
$Hub_Firmware=""
$Hub_RSSI=""
$Tempest_Firmware=""
$tempest_RSSI=""


#IPEndPoint object will allow us to read datagrams sent from any source.
$remoteendpoint = New-Object system.net.ipendpoint([system.net.ipaddress]::Any,50222)

#Blocks until a message returns on this socket from a remote host.
Do 
{
$receivebytes = $udpobject.Receive([ref]$remoteendpoint)
 
If ($receivebytes) {
    [string]$returndata = $a.GetString($receivebytes)
    $returndata
    if ($returndata.Contains("hub_status")) {
        $Hub_firmware=$returndata.Split(",")[2]
        $Hub_RSSI=$returndata.Split(",")[4]
        #$Hub_firmware
        }
    if ($returndata.Contains("device_status")) {
        $Tempest_firmware=$returndata.Split(",")[6]
        $Tempest_RSSI=$returndata.Split(",")[7]
        #$Tempest_firmware
        }
} Else {
    "No data received from {0} on port {1}" -f $Computername,$Port
}
} while (($Hub_Firmware -eq "") -or ($Tempest_Firmware -eq ""))
$udpobject.Close()




Write-Output "$(Get-TimeStamp) HUB $Hub_Firmware : Tempest $Tempest_Firmware : HUB-RSSI $hub_rssi : Tempest-RSSI $tempest_rssi" | Out-file "weatherflow.log" -append

#Convert returned data into string format
#[string]$returndata = $a.GetString($receivebytes)
 
#Uses the IPEndPoint object to show that the host responded.
#Write-Host "This is the message you received: $($returndata.ToString())"





2 Likes

Other than the Microsoft usage, pretty cool.

(just kidding - very cool !!!)

My first go at UDP
Figured it might be useful to someone else running Windows :relaxed:

updated to log RSSI levels as well