Looking around for things related to a “find my phone” function, I came across these:
Which mentions two tools, position-cli
by Kimmoli, and gps.py
by slowcyclist:
- GitHub - kimmoli/position-cli
- GitHub - slowcyclist/gps: python script to get a gps fix on SailfishOS phones
Both still work, and could be a starting point for a background service.
Proof-of-concept:
#!/bin/sh
# turn off Qt logging output
export QT_LOGGING_RULES="*.debug=false"
# Nextcloud PhoneTrack settings:
BASEURL=https://nextcloud.example.org/apps/phonetrack/logGet
TOKEN=03219782grbf892hrpqb9pe8vbwe
NAME=sailfish
# PAYLOAD=lat=LAT&lon=LON&alt=ALT&acc=ACC&bat=BAT&sat=SAT&speed=SPD&bearing=DIR×tamp=TIME
# battery info
# valid for Xperia10, use other path for other devices
BATTINFO=/sys/class/power_supply/bms/uevent
eval $(grep POWER_SUPPLY_CAPACITY= ${BATTINFO})
# https://github.com/kimmoli/position-cli
POSITION_CLI_CMD="./position -v"
DATA=$($POSITION_CLI_CMD | awk '/^ / {print $NF}')
TIME=$(date +%s)
# valid lat lon alt speed accuracy
# yes 47.104517 15.400878 418.870605 -nan -nan
VALID=$(echo $DATA | awk '{print $1}')
LAT=$(echo $DATA | awk '{print $2}')
LON=$(echo $DATA | awk '{print $3}')
ALT=$(echo $DATA | awk '{print $4}')
ACC=$(echo $DATA | awk '{print $5}')
SPD=$(echo $DATA | awk '{print $6}')
if [ "$VALID" != "yes" ]; then
exit 0
fi
PAYLOAD="${BASEURL}/${TOKEN}/${NAME}?lat=${LAT}&lon=${LON}&bat=${POWER_SUPPLY_CAPACITY}×tamp=${TIME}"
if [ "$ALT" != "-nan" ]; then
PAYLOAD="${PAYLOAD}&alt=${ALT}"
fi
if [ "$ACC" != "-nan" ]; then
PAYLOAD="${PAYLOAD}&acc=${ACC}"
fi
if [ "$SPD" != "-nan" ]; then
PAYLOAD="${PAYLOAD}&speed=${SPD}"
fi
#echo payload: $PAYLOAD
#curl -s -L -I -X GET "$PAYLOAD" && curl -L -X GET -o /dev/null -w "%{http_code}" "$PAYLOAD"
RES=$(curl -s -L -X GET -o /dev/null -w "%{http_code}" "$PAYLOAD")
if [ "$RES" = "200" ]; then
echo "success."
else
echo "failed."
fi