• 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.
    • C Offline
      c4pp4
      last edited by c4pp4 5 Apr 2022, 06:52 26 May 2021, 01:40

      What it does:

      1. Script I: Switch to 2G when screen is locked and switch back to 4G when screen is unlocked. TELEports or Dekko notifications work well.
      2. Alternative script II: Switch to 2G when screen is off and switch back to 4G when screen is on (regardless of screen lock). TELEports or Dekko notifications work well.
      3. Alternative script III: Turn off cellular data when screen is off and turn on cellular data again when screen is on (regardless of screen lock). No TELEports or Dekko notifications when screen is off.

      Precondition: Working 4G connection which drains battery when device is inactive (screen is locked or off).
      Originally made for Xiaomi Mi A2 and tested on it but can be useful for any device.


      Create a script "/home/phablet/lte-battery-saver"
      Script I:

      #!/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.canonical.UnityGreeter"* ]]; 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
      

      Make script executable

      chmod u+x /home/phablet/lte-battery-saver
      

      Create an upstart session job "/home/phablet/.config/upstart/lte-battery-saver.conf"

      description "LTE battery saver"
      
      start on started dbus
      stop on stopped dbus
      
      exec /home/phablet/lte-battery-saver
      

      Start the job

      start lte-battery-saver
      

      or reboot the phone.


      NOTES (Script I and Alternative script II):

      • Change "/ril_0" to "/ril_1" if your data SIM is in slot 2 (see sim_slot variable)
      • If switching back doesn't work, try to set primary_preference variable to "any"
      • To switch between 3G and 2G replace "lte" with "umts" (see primary_preference variable)
      • To switch between 4G and 3G replace "gsm" with "umts" (see saving_preference variable)

      To apply the changes, restart the job

      restart lte-battery-saver
      

      or reboot the phone.


      To remove all changes

      stop lte-battery-saver
      rm /home/phablet/.config/upstart/lte-battery-saver.conf
      rm /home/phablet/lte-battery-saver
      

      Alternative script II:

      #!/bin/bash
      
      primary_preference="lte"
      saving_preference="gsm"
      sim_slot="/ril_0"
      
      interface=com.canonical.Unity.Screen
      member=DisplayPowerStateChange
      
      dbus-monitor --system "type=signal,interface='${interface}',member='${member}'" |
      while read -r line; do
      	if [[ ${line} == *"int32 0" ]]; then
      		read
      		/usr/share/ofono/scripts/set-tech-preference "${sim_slot}" "${saving_preference}" 1>/dev/null
      	elif [[ ${line} == *"int32 1" ]]; then
      		read
      		/usr/share/ofono/scripts/set-tech-preference "${sim_slot}" "${primary_preference}" 1>/dev/null
      	fi
      done
      

      Alternative script III:

      #!/bin/bash
      
      interface=com.canonical.Unity.Screen
      member=DisplayPowerStateChange
      
      dbus-monitor --system "type=signal,interface='${interface}',member='${member}'" |
      while read -r line; do
      	if [[ ${line} == *"int32 0" ]]; then
      		read
      		dbus-send --type=method_call --dest=com.ubuntu.connectivity1 /com/ubuntu/connectivity1/Private org.freedesktop.DBus.Properties.Set string:com.ubuntu.connectivity1.Private string:MobileDataEnabled variant:boolean:false
      	elif [[ ${line} == *"int32 1" ]]; then
      		read
      		dbus-send --type=method_call --dest=com.ubuntu.connectivity1 /com/ubuntu/connectivity1/Private org.freedesktop.DBus.Properties.Set string:com.ubuntu.connectivity1.Private string:MobileDataEnabled variant:boolean:true
      	fi
      done
      
      D Y 2 Replies Last reply 26 May 2021, 06:22 Reply Quote 8
      • D Offline
        domubpkm @c4pp4
        last edited by domubpkm 26 May 2021, 06:22

        @c4pp4 Thank you!
        Could be useful for the Volla UT, which I find is currently a very large power consumer despite its 4700 mA battery. Recharges every 24 hours on average (I use the internet quite regularly but..).

        I installed it. Seems to work well. 👍

        But maybe it would be nice if you could make a .click of your procedure (if possible).

        1 Reply Last reply Reply Quote 0
        • D Offline
          domubpkm
          last edited by 26 May 2021, 06:42

          It makes me think now that it would be useful to have a direct switch accessible by the indicator bar (network or battery) to switch directly from 4g to 2g and vice versa.

          K 1 Reply Last reply 26 May 2021, 12:57 Reply Quote 0
          • K Offline
            Keneda @domubpkm
            last edited by Keneda 26 May 2021, 12:57

            @domubpkm
            I talked about that feature once, as i turn on 4G only when i need lot of bandwich to save battery when not needed, and got negative return...

            edit : https://forums.ubports.com/topic/4406/manually-choose-lte-only-wcdma-only-lte-and-wcdma-etc/7?_=1622034590341

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

            D 1 Reply Last reply 26 May 2021, 13:31 Reply Quote 1
            • D Offline
              domubpkm @Keneda
              last edited by 26 May 2021, 13:31

              @keneda Yes, I've read it and I still think it would be useful 😉 There is no obligation to use it.

              K 1 Reply Last reply 26 May 2021, 18:53 Reply Quote 0
              • K Offline
                Keneda @domubpkm
                last edited by Keneda 26 May 2021, 18:53

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

                I still think it would be useful

                I still think too ^^
                BTW @c4pp4 tweak is a good thing too.

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

                A 1 Reply Last reply 26 May 2021, 19:23 Reply Quote 0
                • A Offline
                  arubislander @Keneda
                  last edited by 26 May 2021, 19:23

                  @keneda Lots of things could be useful, and indeed, no one would be forcing anyone to use it if they didn't want to.

                  But: implementing the feature would take time and effort from some developer. The feature would have to be implemented, tests would have to be written to check that the implementation is correct, and more importantly, remains correct when changes are made to the feature. And from there on out both the feature and the tests would have to be maintained in perpetuity (not having a feature encourages workarounds, removing a feature incurs rage).

                  So yes, from the user's perspective, more features are better, since everyone need only use what they find useful. But the developers must maintain all the features equally, irrespective of their frequency of usage. So you can understand why "I think it would be useful" is not a sufficiently compelling argument to take on the burden of maintenance of a new feature.

                  🇦🇼 🇳🇱 🇺🇸 🇪🇸
                  Happily running Ubuntu Touch
                  Google Pixel 3a (20.04 DEV)
                  JingPad (24.04 preview)
                  Meizu Pro 5 (16.04 DEV)

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    domubpkm
                    last edited by 28 May 2021, 09:11

                    One way to save battery power, as seen with my Volla, is to turn off cellular data when not needed and turn it back on when needed. This does not prevent the use of phone and SMS functions.
                    It is the fact of being connected to a 4G, 3G or even 2G network that really drains the battery and even more so when the sky is not clear (inappropriate atmospheric conditions): there the overconsumption can get out of hand.

                    K 1 Reply Last reply 28 May 2021, 10:51 Reply Quote 1
                    • K Offline
                      Keneda @domubpkm
                      last edited by 28 May 2021, 10:51

                      @domubpkm Problem is that prevents from receiving MMS.

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

                      D 1 Reply Last reply 28 May 2021, 11:41 Reply Quote 0
                      • D Offline
                        domubpkm @Keneda
                        last edited by domubpkm 28 May 2021, 11:41

                        @keneda Yes, nothing is perfect! For mails, they arrive well once the cellular data has been reactivated. For MMS, when cellular data OFF, a SMS informs the recipient that the MMS could not be recovered.
                        screenshot20210528_133042098.png

                        J 1 Reply Last reply 28 May 2021, 14:38 Reply Quote 0
                        • J Offline
                          jezek @domubpkm
                          last edited by 28 May 2021, 14:38

                          @domubpkm There is a pull request waiting for approval, which handles all the trouble when receiving MMS while cellular data is off. Feel free to test and report. 😉

                          jEzEk

                          D 1 Reply Last reply 29 May 2021, 18:29 Reply Quote 1
                          • M Offline
                            Mario.CH
                            last edited by 28 May 2021, 16:57

                            Hello c4pp4,
                            thanks for your work on the topic of battery saving.
                            I did the test on my Sony Xperia X (F5121). The device switches to G2 as promised. However, when the device wakes up, it does not switch back to LTE.
                            Unfortunately for me, my network provider no longer supports G2, so I have no connection to the antenna, i.e. "The subscriber is currently unavailable".:beaming_face_with_smiling_eyes:
                            Now I want to remove the script or the changes I made.
                            Is that possible?
                            And how do I do that?
                            Could you support me.
                            Greetings Mario

                            Translated with www.DeepL.com/Translator (free version)

                            📱 Oneplus Nord N100 UT20.40 (OTA5); then Xperia X (since 2020) at last UT 20.04(OTA5), now out of service due to defective camera
                            🐎 When you realize you are riding a dead horse, get off!
                            My languages skill: 🇨🇭🇦🇹 🇩🇪, and only orally: 🇬🇧 🇹🇭

                            C 1 Reply Last reply 28 May 2021, 18:57 Reply Quote 0
                            • D Offline
                              domubpkm
                              last edited by 28 May 2021, 17:10

                              To do that, i deleted the script (lte-battery-saver) and the upstart session job (lte-battery-saver.conf) and rebooted the smartphone.

                              1 Reply Last reply Reply Quote 0
                              • C Offline
                                c4pp4 @Mario.CH
                                last edited by 28 May 2021, 18:57

                                @mario-ch Hello,
                                what kind of connections are available in your case? I can help you to tweak the script for your needs.

                                Anyway to take back the changes, remove both files:

                                rm /home/phablet/lte-battery-saver
                                rm /home/phablet/.config/upstart/lte-battery-saver.conf
                                
                                M 1 Reply Last reply 28 May 2021, 19:09 Reply Quote 1
                                • M Offline
                                  Mario.CH @c4pp4
                                  last edited by 28 May 2021, 19:09

                                  @c4pp4 As it seems, or rather I think 3G would work.

                                  📱 Oneplus Nord N100 UT20.40 (OTA5); then Xperia X (since 2020) at last UT 20.04(OTA5), now out of service due to defective camera
                                  🐎 When you realize you are riding a dead horse, get off!
                                  My languages skill: 🇨🇭🇦🇹 🇩🇪, and only orally: 🇬🇧 🇹🇭

                                  C 1 Reply Last reply 28 May 2021, 19:31 Reply Quote 0
                                  • C Offline
                                    c4pp4 @Mario.CH
                                    last edited by 28 May 2021, 19:31

                                    @mario-ch You mean switch to 3G when display is off and switch back to 4G when on?

                                    M 1 Reply Last reply 28 May 2021, 19:35 Reply Quote 0
                                    • M Offline
                                      Mario.CH @c4pp4
                                      last edited by 28 May 2021, 19:35

                                      @c4pp4 yep, that's exactly what i mean.

                                      📱 Oneplus Nord N100 UT20.40 (OTA5); then Xperia X (since 2020) at last UT 20.04(OTA5), now out of service due to defective camera
                                      🐎 When you realize you are riding a dead horse, get off!
                                      My languages skill: 🇨🇭🇦🇹 🇩🇪, and only orally: 🇬🇧 🇹🇭

                                      C 2 Replies Last reply 28 May 2021, 19:59 Reply Quote 0
                                      • C Offline
                                        c4pp4 @Mario.CH
                                        last edited by c4pp4 28 May 2021, 19:59

                                        @mario-ch Ok give me some time, I will test it on my xperia x and let you know.

                                        BTW you can try it on your own when you replace "gsm" with "umts".

                                        1 Reply Last reply Reply Quote 0
                                        • C Offline
                                          c4pp4 @Mario.CH
                                          last edited by c4pp4 12 May 2021, 16:47 28 May 2021, 20:51

                                          @mario-ch In case of Xperia X (maybe it's related to Halium 7.1) we have to set it to "lte" option instead of "any", so the script for your needs (3G<->4G) is here:

                                          #!/bin/bash
                                          
                                          interface=org.freedesktop.DBus.Properties
                                          member=PropertiesChanged
                                          
                                          dbus-monitor --session "type=signal,interface='${interface}',member='${member}'" |
                                          while read -r line; do
                                                  if [[ ${line} == *"com.canonical.UnityGreeter"* ]]; then
                                                          read && read && read -r line
                                                          if [[ ${line} == *"IsActive"* ]]; then
                                                                  read -r line
                                                                  [[ ${line} == *"true"* ]] && /usr/share/ofono/scripts/set-tech-preference /ril_0 umts 1>/dev/null
                                                                  [[ ${line} == *"false"* ]] && /usr/share/ofono/scripts/set-tech-preference /ril_0 lte 1>/dev/null
                                                          fi
                                                  fi
                                          done
                                          
                                          M 1 Reply Last reply 4 Jun 2021, 20:55 Reply Quote 2
                                          • D Offline
                                            domubpkm @jezek
                                            last edited by 29 May 2021, 18:29

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

                                            which handles all the trouble when receiving MMS while cellular data is off

                                            Hello. You done a huge work..! congratulations.

                                            Does it mean that the main purpose of the work is that MMS could be received normally with cellular data OFF ?

                                            K 1 Reply Last reply 29 May 2021, 20:15 Reply Quote 1
                                            7 out of 89
                                            • First post
                                              7/89
                                              Last post