GPS tracking in Background - Trick



  • Hello,

    As you know to track your activity there is the application Activity Tracker : https://open-store.io/app/activitytracker.cwayne18
    Unfortunately due to the Utouch security policy, GPS signal is not accessible when the screen is off or app is in background, that why the original developer force the screen to stay on, reducing significantly the battery life with no benefit.
    Issue is tracked there : https://github.com/ubports/ubuntu-touch/issues/1067

    In order to extend life of the phone for some long activities, i've made a wrapper of the test_gps command.
    It requires to be launched from a terminal with it "Prevent app suspension" activated in Tweak app.

    The GPS Utouch tracker is available there : https://framagit.org/ernesst/gps-utouch-tracker, still not polished yet.
    Just download the folder, place it somewhere in your homefolder.
    To start it, go to the folder and launch it with sudo ./GPS_tracking.py

    It will start to track your activity, to stop it just go back to the terminal and hit the virtual key "Ctrl+c" and it will create a gpx file.

    To visualize this file, you can import it in Activity Tracker.

    Enjoy.



  • @ernest So you mean this script will run even when the screen is locked and closed?
    If yes, then this is really cool and I would definitely try it.
    It would be cool if it works with some kinda of a UI so you can still check from time to time your location in the map 😉



  • @kugiigi yes it does, screen off and or terminal in background



  • Hello ernest,

    I started this reply as I was unable to run your script, but as I was writing and testing at the same time, I finally figured it out. 😄

    I'm leaving in a few hours for a 4-day 250 km bike trip, and I will try to test it.

    For those who may happen on this topic and are new to Ubuntu Touch (like me), a few things I struggled with:

    It requires to be launched from a terminal with it "Prevent app suspension" activated in Tweak app.

    You need to install UT Tweak Tool in the OpenStore, launch it, then tap on the menu icon at the top left and select Apps (not sure how it's worded in English, it's an apps list). Next find the Terminal and tap on its entry. It will open a Details window where you will find the "Prevent app suspension" toggle switch.

    The script will not start and makes an error because of line 29 of the GPS_tracking.py script:

    sys.path.insert(0, "/home/phablet/Project/gpxpy-1.3.5/")
    

    It is looking for a "Project" folder that does not exist. You need to change it to the actual name of the folder where the script and the "gpxpy-1.3.5" folder resides, which when downloaded from Gitlab and extracted is by default gps-utouch-tracker-master. For that I edited it in UT's terminal:

    cd gps-utouch-tracker-master
    nano GPS_tracking.py
    

    Another thing that's necessary to make the script run is to make it executable.

    chmod +x GPS_tracking.py
    

    A word of warning: if you forget to activate the terminal's "prevent app suspension" button, once the script is launched, there is no stopping it!!! The CTRL+C button at the bottom will not stop the script. The terminal prompt returns, but GPS points continue to be added. You will have no choice but to quit the terminal and of course no file will be saved.

    The gpx files are saved in the gps-utouch-tracker-master folder, or whatever name you gave it (might be a good idea to rename it 😁 ).

    It would be cool if it works with some kinda of a UI

    Or at least, a minimal GUI to launch, if possible avoid having to enter our password, then a button to stop it... I was thinking of creating a desktop launcher, but I'm out of time, I need to pack and get a few hours of sleep!

    Ernest, thanks for your work on Activity Tracker, and for this script! ☺



  • Thanks for the feedback,

    I've removed the hardcoded folder location for the python lib, no need to change name now.

    sys.path.insert(0, "./gpxpy-1.3.5/")
    

    I'm not sure why you need to perform a chmod, the file should already be executable :

    -rwxr-xr-x 1 phablet phablet 3248 Aug 20 23:12 GPS_tracking.py
    drwxrwxr-x 5 phablet phablet 4096 Aug 20 23:12 gpxpy-1.3.5
    -rw-rw-r-- 1 phablet phablet   22 Aug 20 23:12 README.md
    
    

    To simplify the start of the script, create an alias into ~/.bashrc something like

    alias GPS="cd /home/phablet/Project/ && sudo ./GPS_tracking.py"
    

    To acknowlegde the modification you need to close the terminal


Log in to reply