Location API for remote device tracking

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:

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&timestamp=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}&timestamp=${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
3 Likes

isn’t this restricted for apps? I mean that apps that has daemons can’t end up in official Jolla apps shop??

I’m using gpscon from Openrepos for that purpose.

This is true. And while I haven’t looked into harbour-compatability a lot, it’s probably possible to generate e.g. a systemd user service from the app, i.e. after installation rather than shipping anything.

This is very interesting (related or even not to ‘find lost device’ thema) and would deserve an own thread.
I even have a question ready for this thread :slight_smile:

probably that’s doable a bit overkill imho instead of just ship the systemd service config but yeah.
Still you need some binary that will fork itself etc so it’s running as a real deamon or you think about just using it normally and use systemd functionalities for that?

please make new thread, we can continue there. I think @nephros will agree.
Just leave a link here.

1 Like

Ok.
Is subject more:
-Find lost device
-Command line GPS usage
-Systemd Programmed GPS use
Or?

Edit: Isn’t there a function to kinda fork a thread, for the author? This might be the best solution.

More like: Location API for remote device tracking.

The funny thing is, all that is needed is already implemented in the core OS, because of AML.
.

so we just need this to be exposed to be available from the outside.
So on the phone, there must be a service running in the background that will take:

  • host
  • login
  • password

and authenticate to the service and provide data.
Actually this is probably related to MDM as the phone should just join to MDM server and that server should control that.

Now, do we have some OpenSource MDM server with nice GUI api?:slight_smile:

Hm, I wonder if a reverse ssh tunnel (and autossh) could replace that function? Autostart that with a passwordless ssh key, and establish a reverse tunnel to some server you own.

Forward some device ports if needed to that home server via the tunnel.

Thanks for having split that thread :slight_smile:

Jeeez, what you guys are saying is over my head!
My abilities are more limited to tinkering scripts and tolerating using sudo to achieve some tasks.
But what you elaborate smell more useful to all and usable by any user in the future, after some elaboration.

Anyway,
I git-cloned following the second link you gave, @nephros.
Trying to then run the script, I hit my nose on a:

defaultuser@XperiaXA2-DualSIM ~% python3 ./Downloads/slowcyclist/gps/gps.py
Traceback (most recent call last):
File “./Downloads/slowcyclist/gps/gps.py”, line 3, in
from gi.repository import GLib
ModuleNotFoundError: No module named ‘gi’

I did some short searches but … thought wou would know on instant.
Does this ring a bell to you?
If not, don’t loose time, I’ll continue searching deeper.

could be, depends what you need. Imho for avg Joe it’s easier to just enter these details. For others ssh may be better option.

Edit: maybe adding option to paste ssh password less key? Or even key with pw stored in sfos secret store would be ok? But then tbh there’s a lot of problems to setup revers ssh and to maintain it. Personally I’d prefer the option to provide the data as above.
We can’t also forget about some Nextcloud functionality that we could glue together. Someone mentioned that, do you have any ideas how does it work/what’s needed to get it working?

pkcon install python3-gobject. Careful, the script tries to sudo and change location.conf. This is safe (it’ll just fail) it you’re not root and have not configured sudo.

If you have sudo enabled, this may do things you do not want… check the script.

Thank you @nephros for the package info + warning.
Indeed, sudoers is now set to allow the user to modify location.conf. But this file only. So it’s not so a big problem, I believe.

The script is now running but not able to enable location.
Even by changing location.conf, the gps seems not to be ON.
In contrary, if I enable it with the GUI Button, then, it is working.

Something in GPS triggering perhaps has changed since the script was made?
As I was saying there, we now have /etc/location/location.conf and /var/lib/location/location.conf which are identical… strange…