Q: How can I change Settings/System/Location's behavior to have the GPS receiver always running when Location is enabled

Volla / SFOS and X10 / SFOS

Current behavior is: If Location setting is enabled, GPS receiver starts if some app demands position data, but not immediately and it needs additional startup time until position data is available. This is annoying. If no app demands GPS data, the GPS receiver is switched off to save power. Well known workaround to have quick access to GPS data is to let GPSInfo permanently run to keep GPS receiver alive.

How can I change / tweak the system files to let GPS receiver exactly follow the setting in Settings/System/Location, will say, on is on and off is off. The GPS receiver power control should not listen if any app demands data or not.

Many thanks for any hint!

1 Like

I don’t think there’s a setting for it, but you could have e.g. GPSinfo running, and toggle GPS location with that. That way you could keep the system location always on, and use the app to control it.

1 Like

Thanks for that hint @direc85 , at the moment I do so if necessary. But I really would like to modify the code in a way that the GPS on/off setting simply switches on or off the GPS receiver and doesn’t care for apps asking for GPS data or not.
This was its behavior long time and many SFOS versions ago. There must be an option to modify the code in a way that it doesn’t look if an app asks for GPS data or not.
I hope it’s possible by some tweak like comment out some code snippet or changing a variable to a fixed value or so. But I have no idea where to begin, therefore I asked.

Having location beeing updated does mean additional power cosumption, right? So, I wouldn’t go that route. Instead, I would look into scripting something with gpscon … But I’m no dev…

Yes, I think this was made to safe battery power, even if a user leaves the setting permanently on.

Do a search with @nephros as user and ‘gps’ and perhaps ‘script’, ‘command line’ or ‘terminal’.
He did give a trick to run gps from the command line but I don’t remember where.
This would allow you to make a service enabling the GPS every 15 mn, or so.
That way, you would not consume too much power but apps needing GPS would always have an updated gps.
Just an idea. Maybe…

I set up something like that using gpscon. Unfortunately it seems starting gpscon is not enough to actually activate the location services.

But for reference, this is what I use to submit location data to PhoneTrack (a Nextcloud app). It’s very crude and does more than @Seven.of.nine wants here, but maybe it’s useful.
All the magic is done by gpscon, so play around with that.

I manually trigger start of this service from Situation when it detects i am “Not At Home”, i.e. not in range of known Wifi networks:


Description=PhoneTrack Submission

ExecStart=/bin/bash %h/.local/bin/phonetrack/submit.sh


And the script:



NAME=pgxperiiia10 # device name in phonetrack

# check whether we're online
if [ $( /usr/bin/connmanctl state | grep -c 'State = online' ) -ne 1 ]; then
        echo "$0: Not online, doing nothing" > /dev/stderr
        exit 0


# [limit=integer]
# sets the limit of the needed horizontal/vertical accuracy value before print out.
# There will be only one print out and after this the app is closing
#POSITION_CLI_CMD="/usr/bin/gpscon --script --fout limit=250 interval=5000 tout=60"
POSITION_CLI_CMD="/usr/bin/gpscon --script --fout --posm=all limit=250 interval=5000 tout=60"
POSITION_CLI_FALLBACK_CMD="/usr/bin/gpscon --script --lknv runs=1"

export  QT_LOGGING_RULES="*.debug=false"
DATA=$($POSITION_CLI_CMD | sed 's/; /\n/g'  | awk '{print $NF}' | xargs echo )

if [ "$DATA" = "" ]; then
        echo "$0: falling back to last known location" > /dev/stderr
        DATA=$($POSITION_CLI_FALLBACK_CMD | sed 's/; /\n/g'  | awk '{print $NF}' | xargs echo )

# Latitude: 47.xxx
# Longitude: 15.xxx
# Altitude: 439.xxx
# Direction: nan
# Ground Speed: nan
# Vertical Speed: nan
# Horizontal Acc: 45.3756
# Vertical Acc: 35.9893
# run: 46

# --> 47.xxx 15.xxx 439.xxx nan nan nan 45.3756 35.9893 46
#     lat     lon     alt     dir spd vspd hacc   vacc
#     $1      $2      $3      $4  $5  $6   $7     $8

# OK=$(echo $DATA  | awk '{print $1}')
#echo dat: lat     lon     alt     dir spd vspd hacc   vacc runs
#echo dat: $DATA
LAT=$(echo $DATA | awk '{print $1}')
LON=$(echo $DATA | awk '{print $2}')
#ALT=$(echo $DATA | awk '{print $3}')
ALT=$(echo $DATA | awk '{printf("%d", $3)}')
DIR=$(echo $DATA | awk '{print $4}')
SPD=$(echo $DATA | awk '{print $5}')
ACC=$(echo $DATA | awk '{printf("%d", $7)}')

#if [ "$OK" != "yes" ]; then
#       echo "$0: GPS is invalid" > /dev/stderr
#       exit 75 # BSD EX_TEMPFAIL # https://freedesktop.org/software/systemd/man/systemd.exec.html#Process%20Exit%20Codes
if [ "$ACC" != "" ] && [ "$ACC" != "nan" ] && [ "$ACC" -gt 500 ]; then
        echo "$0: GPS accuracy bad." > /dev/stderr
        exit 0

if [ "$ALT" != "" ] && [ "$ALT" != "nan" ] ; then
        PAYLOAD=$(printf '%s&alt=%d' "${PAYLOAD}" "${ALT}")
if [ "$ACC" != "" ] && [ "$ACC" != "nan" ]; then
        PAYLOAD=$(printf '%s&acc=%d' "${PAYLOAD}" "${ACC}")
if [ "$SPD" != "" ] && [ "$SPD" != "nan" ]; then
        PAYLOAD=$(printf '%s&speed=%d' "${PAYLOAD}" "${SPD}")
if [ "$DIR" != "" ] && [ "$DIR" != "nan" ]; then
        PAYLOAD=$(printf '%s&bearing=%d' "${PAYLOAD}" "${DIR}")

PAYLOAD=$(printf '%s&useragent=%s' "${PAYLOAD}" "${UA}")
TIME=$(date +%s)
PAYLOAD=$(printf '%s&timestamp=%d' "${PAYLOAD}" "${TIME}")
#curl -s -L -I -X POST "$PAYLOAD" # HEAD request
echo pld: "${PAYLOAD}"
#echo url: "${POSTURL}"
RES=$(curl -s -k -L -X POST -o /dev/null -w "%{http_code}" -d "$PAYLOAD" "${POSTURL}")
if [ "$RES" = "200" ]; then
        echo "success."
        exit 0
        echo "$0: remote host answered $RES" > /dev/stderr
        echo "failed."
        exit 75 # BSD EX_TEMPFAIL # https://freedesktop.org/software/systemd/man/systemd.exec.html#Process%20Exit%20Codes


@Seven.of.nine I second the use of gpscon. I use it to track phone position and keep the gps active. It usually works pretty well, albeit slightly dodgy on my XA2 due to the antenna hardware issues on that device. Works very reliably on my wifes 10ii, my sons 10ii and my xperia 1i. Let me know if you’d like details on the implementation.

1 Like