• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
UBports Robot Logo UBports Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

[HowTo] Alternate way of saving battery when using 4G/LTE

Scheduled Pinned Locked Moved Support
89 Posts 16 Posters 28.1k Views 9 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L Offline
      lkroll
      last edited by lkroll 29 Apr 2023, 18:02

      Battery drain on standby with 4G is still a problem on focal, so I updated the script and created a small systemd service to automatically run the script at startup. Maybe this will be useful for some.


      The greeter in focal is called "com.lomiri.LomiriGreeter" instead of "com.canonical.UnityGreeter". So i changed that in the script and tested that it indeed still works.

      I placed the updated script in:
      /home/phablet/.local/bin

      #!/bin/bash
      
      primary_preference="lte"
      saving_preference="gsm"
      sim_slot="/ril_0"
      
      interface=org.freedesktop.DBus.Properties
      member=PropertiesChanged
      
      dbus-monitor --session "type=signal,interface='${interface}',member='${member}'" |
      while read -r line; do
              if [[ ${line} == *"com.lomiri.LomiriGreeter"* ]]; then
                      read; read; read -r line
                      if [[ ${line} == *"IsActive"* ]]; then
                              read -r line
                              [[ ${line} == *"true"* ]] && /usr/share/ofono/scripts/set-tech-preference "${sim_slot}" "${saving_preference}" 1>/dev/null
                              [[ ${line} == *"false"* ]] && /usr/share/ofono/scripts/set-tech-preference "${sim_slot}" "${primary_preference}" 1>/dev/null
                      fi
              fi
      done
      

      Don't forget to make it executable:

      chmod u+x /home/phablet/.local/bin/lte-battery-saver.sh
      

      Ubuntu 20.04 uses systemd instead of upstart so I created a systemd user service in:
      /home/phablet/.config/systemd/user/lte-battery-saver.service

      [Unit]
      Description=LTE battery saver
      Requires=dbus.socket
      After=dbus.socket
      
      [Service]
      ExecStart=/home/phablet/.local/bin/lte-battery-saver.sh
      
      [Install]
      WantedBy=dbus.socket
      

      Now to enable the service:

      systemctl --user enable --now lte-battery-saver
      

      Verify that it is running and up:

      systemctl --user status lte-battery-saver
      

      It should return active and enabled:

      ● lte-battery-saver.service - LTE battery saver
           Loaded: loaded (/home/phablet/.config/systemd/user/lte-battery-saver.service; enabled; vendor preset: enabled)
           Active: active (running) since Sat 2023-04-29 18:44:27 CEST; 1h 11min ago
      

      That's it, now everytime the phone is locked the connection will drop to 2G and back to 4G/LTE once unlocked.
      I tested and verified it on my Oneplus 5T, but it should work on other devices running focal.

      A 1 Reply Last reply 19 Sept 2023, 14:47 Reply Quote 4
      • L Luksus referenced this topic on 22 May 2023, 07:55
      • L Offline
        lduboeuf
        last edited by lduboeuf 9 May 2023, 19:57 4 Sept 2023, 15:41

        [ Focal only ]
        If anyone want my dirty hack ( when cellular data off -> then use 2G , when data on -> switch to LTE)

        You must have a focal device on devel channel, then sudo ubports-qa install focal_-_PR_lomiri-system-settings-cellular_6

        This will auto toggle LTE when cellular data requested , and back to 2G when off,
        https://gitlab.com/ubports/development/core/lomiri-system-settings-cellular/-/merge_requests/6

        ( only work when toggled from the settings, not the indicator )

        A 1 Reply Last reply 15 Sept 2023, 06:10 Reply Quote 0
        • A Offline
          AmauryDBZ @lduboeuf
          last edited by AmauryDBZ 15 Sept 2023, 06:10

          @lduboeuf thanks for your 'dirty hack' !
          after installing it says I have to upgrade, but sudo apt upgrade returns

          Lecture des listes de paquets... Fait            
          Construction de l'arbre des dépendances          
          Lecture des informations d'état... Fait          
          Calcul de la mise à jour... Fait                 
          Get more security updates through Ubuntu Pro with 'esm-apps' enabled:                             
            libswresample3 libmediainfo0v5 libavcodec58 libavutil56 libopenexr24                            
            libsdl2-2.0-0                                  
          Learn more about Ubuntu Pro at https://ubuntu.com/pro                                             
          W: Verrou non utilisé pour le fichier /var/lib/dpkg/lock-frontend en lecture seule                
          W: Verrou non utilisé pour le fichier /var/lib/dpkg/lock en lecture seule                         
          E: Le répertoire d'archive /var/cache/apt/archives/partial n'existe pas. - Acquire (30: Read-only file system)
          

          Any idea how to resolve ?
          Moreover, is it possible to add an exception when hotspot is on ?

          L 1 Reply Last reply 15 Sept 2023, 07:16 Reply Quote 0
          • L Offline
            lduboeuf @AmauryDBZ
            last edited by 15 Sept 2023, 07:16

            @AmauryDBZ said in [HowTo] Alternate way of saving battery when using 4G/LTE:

            @lduboeuf thanks for your 'dirty hack' !
            after installing it says I have to upgrade, but sudo apt upgrade returns

            Lecture des listes de paquets... Fait            
            Construction de l'arbre des dépendances          
            Lecture des informations d'état... Fait          
            Calcul de la mise à jour... Fait                 
            Get more security updates through Ubuntu Pro with 'esm-apps' enabled:                             
              libswresample3 libmediainfo0v5 libavcodec58 libavutil56 libopenexr24                            
              libsdl2-2.0-0                                  
            Learn more about Ubuntu Pro at https://ubuntu.com/pro                                             
            W: Verrou non utilisé pour le fichier /var/lib/dpkg/lock-frontend en lecture seule                
            W: Verrou non utilisé pour le fichier /var/lib/dpkg/lock en lecture seule                         
            E: Le répertoire d'archive /var/cache/apt/archives/partial n'existe pas. - Acquire (30: Read-only file system)
            

            Any idea how to resolve ?
            Moreover, is it possible to add an exception when hotspot is on ?

            Well, your device must be up to date before doing any ubports-qa things.
            You can either reinstall UT or go by mouting rw the partition and then upgrade.

            A 1 Reply Last reply 15 Sept 2023, 07:27 Reply Quote 0
            • A Offline
              AmauryDBZ @lduboeuf
              last edited by 15 Sept 2023, 07:27

              @lduboeuf said in [HowTo] Alternate way of saving battery when using 4G/LTE:

              by mouting rw the partition and then upgrade.

              do you have a tutorial ?

              L 1 Reply Last reply 15 Sept 2023, 08:02 Reply Quote 0
              • L Offline
                lduboeuf @AmauryDBZ
                last edited by 15 Sept 2023, 08:02

                @AmauryDBZ said in [HowTo] Alternate way of saving battery when using 4G/LTE:

                @lduboeuf said in [HowTo] Alternate way of saving battery when using 4G/LTE:

                by mouting rw the partition and then upgrade.

                do you have a tutorial ?

                Well, if you ask, maybe you don't know the possible consequences ?
                If ok then remount rw the partition: sudo mount -o remount,rw /
                then sudo apt upgrade

                A 1 Reply Last reply 15 Sept 2023, 09:21 Reply Quote 0
                • A Offline
                  AmauryDBZ @lduboeuf
                  last edited by 15 Sept 2023, 09:21

                  @lduboeuf you're right I have no idea of what consequence it could have ! Thanks for your help !

                  To come back on the subject of this topic, would it be possible to add an exception when the hotspot is activated ?

                  L 1 Reply Last reply 15 Sept 2023, 09:35 Reply Quote 0
                  • L Offline
                    lduboeuf @AmauryDBZ
                    last edited by 15 Sept 2023, 09:35

                    @AmauryDBZ said in [HowTo] Alternate way of saving battery when using 4G/LTE:

                    @lduboeuf you're right I have no idea of what consequence it could have ! Thanks for your help !

                    To come back on the subject of this topic, would it be possible to add an exception when the hotspot is activated ?

                    Humm, what would be the bahavior for hotspot, if enable then auto switch to 4G ?

                    A 1 Reply Last reply 15 Sept 2023, 09:43 Reply Quote 0
                    • A Offline
                      AmauryDBZ @lduboeuf
                      last edited by 15 Sept 2023, 09:43

                      @lduboeuf I would have say if enable stay on 4G even if the screen shutsdown, but that's the idea.

                      L 1 Reply Last reply 15 Sept 2023, 10:34 Reply Quote 0
                      • L Offline
                        lduboeuf @AmauryDBZ
                        last edited by 15 Sept 2023, 10:34

                        @AmauryDBZ said in [HowTo] Alternate way of saving battery when using 4G/LTE:

                        @lduboeuf I would have say if enable stay on 4G even if the screen shutsdown, but that's the idea.

                        ah ok but might not be related to my work around. It only toggles on 4G when request data and toggle 2G when data off.

                        A 1 Reply Last reply 17 Sept 2023, 12:19 Reply Quote 0
                        • A Offline
                          AmauryDBZ @lduboeuf
                          last edited by 17 Sept 2023, 12:19

                          @lduboeuf sorry I didn't understand that the behavior of your hack was different from @lkroll's.

                          1 Reply Last reply Reply Quote 0
                          • A Offline
                            AmauryDBZ @lkroll
                            last edited by 19 Sept 2023, 14:47

                            @lkroll Thanks a lot for your script, works like a charm !
                            As I said to @lduboeuf , I was wondering if it could be possible to add some exceptions ?
                            For instance, 4G could be maintained when the device is charging, or when hotspot activated, or even when an specific app is running (Futify for me).

                            L 1 Reply Last reply 19 Sept 2023, 15:04 Reply Quote 1
                            • L Offline
                              lduboeuf @AmauryDBZ
                              last edited by 19 Sept 2023, 15:04

                              @AmauryDBZ said in [HowTo] Alternate way of saving battery when using 4G/LTE:

                              @lkroll Thanks a lot for your script, works like a charm !
                              As I said to @lduboeuf , I was wondering if it could be possible to add some exceptions ?
                              For instance, 4G could be maintained when the device is charging, or when hotspot activated, or even when an specific app is running (Futify for me).

                              Of course it should be possible but takes time. But would be better to look at the root cause, why LTE need so much battery. There are room for improvement, e.g we still don't manage the FastDormancy.

                              A 1 Reply Last reply 19 Sept 2023, 21:56 Reply Quote 0
                              • A Offline
                                AmauryDBZ @lduboeuf
                                last edited by AmauryDBZ 19 Sept 2023, 21:56

                                @lduboeuf I didn't knew about FastDormancy, make sense to priorise it.
                                Thank you for your answers and patience

                                1 Reply Last reply Reply Quote 0
                                • L Offline
                                  lduboeuf
                                  last edited by lduboeuf 27 Sept 2023, 16:09

                                  Hi all,
                                  [20.04 only]
                                  I've made an app to allow to auto toggle LTE (4G) when cellular data is requested, and back to GSM (2G) when no data.

                                  If anyone interested:
                                  https://gitlab.com/lduboeuf/battery-saver/-/artifacts

                                  source code:
                                  https://gitlab.com/lduboeuf/battery-saver

                                  the app can be closed after clicking "start" and if you see "Running...", it will create a background service

                                  Edit: don't know if it is related but connectivity tends to have issue on upgrading to 4G. Or maybe only an indicator issue.

                                  KenedaK 1 Reply Last reply 27 Sept 2023, 19:44 Reply Quote 4
                                  • KenedaK Offline
                                    Keneda @lduboeuf
                                    last edited by 27 Sept 2023, 19:44

                                    @lduboeuf

                                    Would you release it on openstore ?
                                    Is this for Xenial or Focal, or both ?

                                    2015-2023 : Meizu MX4 ☠️⚰️✝️
                                    2023-2024 : Nexus 5 ☠️⚰️✝️
                                    2024-***** : FPOS Fairphone 5 waiting UT for freedom 😉
                                    🇲🇫🇬🇧

                                    L 1 Reply Last reply 27 Sept 2023, 20:01 Reply Quote 0
                                    • L Offline
                                      lduboeuf @Keneda
                                      last edited by 27 Sept 2023, 20:01

                                      @Keneda said in [HowTo] Alternate way of saving battery when using 4G/LTE:

                                      @lduboeuf

                                      Would you release it on openstore ?

                                      Maybe in the future, the ideal would be to have it integrated, but much much work involved + the fact that upcoming volTE will probably conflict with.

                                      Is this for Xenial or Focal, or both ?

                                      Focal only, only 24h a day 🙂

                                      1 Reply Last reply Reply Quote 0
                                      • E Eric H referenced this topic on 26 Nov 2023, 01:32
                                      • D Offline
                                        domubpkm
                                        last edited by 16 Dec 2023, 14:41

                                        Hello @lduboeuf . When i saw https://open-store.io/app/batterysaver.lduboeuf , i thought first it was a GUI of this topic. Or could your app evolve towards this?

                                        L 1 Reply Last reply 16 Dec 2023, 16:39 Reply Quote 0
                                        • L Offline
                                          lduboeuf @domubpkm
                                          last edited by 16 Dec 2023, 16:39

                                          @domubpkm said in [HowTo] Alternate way of saving battery when using 4G/LTE:

                                          Hello @lduboeuf . When i saw https://open-store.io/app/batterysaver.lduboeuf , i thought first it was a GUI of this topic. Or could your app evolve towards this?

                                          A bit different yes than always switching 2g/4g according tp screen state. But if i have 100 notif a day, it means 100 times the screen will turn on, i doubt it would be efficient...
                                          But could be improved for sure

                                          D 1 Reply Last reply 16 Dec 2023, 21:51 Reply Quote 1
                                          • D Offline
                                            domubpkm @lduboeuf
                                            last edited by 16 Dec 2023, 21:51

                                            @lduboeuf Thanks for your new project. Well personally, in normal use, I generally completely turn off cellular data and activate it when necessary. I don't know how difficult it can be to develop, but I imagine an option that automatically turns on cellular data in case of one or more open apps or web-apps using it, and automatically turns off cellular data when apps or web-apps that used cellular data are all closed...

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post