Skip to content

Instantly share code, notes, and snippets.

@juzam
Last active February 20, 2022 22:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juzam/e29c450202847e8f2fff452dcb5c28c7 to your computer and use it in GitHub Desktop.
Save juzam/e29c450202847e8f2fff452dcb5c28c7 to your computer and use it in GitHub Desktop.
Publish Win10 laptop position/battery to an http(s) Owntracks endpoint. a.k.a. poor man's laptop tracking (WSL and jo binary required)
Add-Type -AssemblyName System.Device #Required to access System.Device.Location namespace
[cultureinfo]::currentculture = 'en-US';
$GeoWatcher = New-Object System.Device.Location.GeoCoordinateWatcher #Create the required object
$GeoWatcher.Start() #Begin resolving current locaton
while (($GeoWatcher.Status -ne 'Ready') -and ($GeoWatcher.Permission -ne 'Denied')) {
Start-Sleep -Milliseconds 100 #Wait for discovery.
}
if ($GeoWatcher.Permission -eq 'Denied'){
Write-Error 'Access Denied for Location Information'
} else {
# $GeoWatcher.Position.Location | Select Latitude,Longitude #Select the relevent results.
$GeoWatcher.Position.Location.Latitude
$GeoWatcher.Position.Location.Longitude
}
$batt = (Get-WmiObject Win32_Battery)
$batt.EstimatedChargeRemaining
#!/bin/bash
# see http://owntracks.org/booklet/tech/http/
PUBLISH_URL=""
# binaries/helpers location
POWERSHELL="/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe"
# install from git: https://github.com/jpmens/jo
JO="/usr/local/bin/jo"
PSHELPER="C:\ot-getdata.ps1"
lat=-1
lon=-1
batt=-1
ps_output=$( $POWERSHELL -File "$PSHELPER" )
count=0
for line in $ps_output; do
line=$(echo -e ${line} | tr -d '[:space:]')
case $count in
0)
lat=$line
;;
1)
lon=$line
;;
2)
batt=$line
;;
esac
count=$(( $count + 1))
done
payload=$( $JO _type="location" lat=$lat lon=$lon batt=$batt tst=$(date +%s) )
echo $payload
curl --data "${payload}" $PUBLISH_URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment