Editing User:Magick777/Opportunistic Power Saving

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
-
= Opportunistic Power Saving =
+
<source lang="text">
 +
#!/bin/sh
-
This page aims to set forth a design for opportunistic power saving on the Nokia N900. Existing power-saver scripts and applets allow the user to toggle settings manually and much has been written about automation of certain events through DBUS. This page is an attempt to tie it all together.
+
# Test the current radio mode and abort if in 3G or dual mode already
 +
TEST=`dbus-send --system --type=method_call --print-reply --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.get_selected_radio_access_technology | grep "byte [02]"`
 +
if [ ! -z "$TEST" ]
 +
then
 +
echo "Phone is already in either 3G or dual mode, aborting."
 +
exit 1
 +
fi
-
== CPU frequency scaling / underclocking ==
+
# Test whether the phone is on a call, if it is then don't mess with it
 +
TEST=`dbus-send --system --type=method_call --print-reply --dest=com.nokia.csd.Call /com/nokia/csd/call/1 com.nokia.csd.Call.Instance.GetStatus | grep "uint32 0"`
 +
#if phone is on call, grep filters out any call status but 0/idle, so we get a zero length output
 +
if [ -z "$TEST" ]
 +
then
 +
echo "Phone is making or receiving a call, aborting."
 +
exit 1
 +
fi
-
This is already documented on the [[Overclocking]] page and is my starting point for building an opportunistic power saving script, based on phone lock / unlock. Credits and thanks to Fecn for getting us this far.
+
#Before we change the radio mode, check that we're not on WiFi
 +
TEST=`grep 1 /tmp/onwifi`
-
== Maintain phone in GSM mode by default when on battery ==
+
if [ ! -z "$TEST" ]
 +
then
 +
echo "Phone is connected via WiFi, no point autoswitching to dual mode."
 +
exit 1
 +
fi
-
=== Status ===
 
-
* Switch to 2G on lock done, works for me, needs review for more blockers
+
# Make the change to 3G
-
* Switch back to 3G works for browser but needs some work
+
run-standalone.sh dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:0
-
** Move from detecting browser launch to a generic application launch handler
+
</source>
-
=== Function specification ===
+
==/usr/bin/set2g==
 +
<source lang="text">
 +
#!/bin/sh
-
* Switch to GSM mode opportunistically when all seems to be quiet
+
# This script is intended to be run indirectly from dbus-scripts and to be triggered on
-
** trigger analysis on phone locked
+
# phone lock. It will then attempt to determine whether it makes sense to change the radio
-
** first check for blockers, most common first
+
# mode to GSM in order to save battery life.
-
*** don't change anything if we're in the desired radio mode
+
-
*** don't change anything if we're on charge and not saving battery
+
-
*** don't change anything if we're on a GSM call
+
-
*** don't change anything if we have blocker applications or connections running
+
-
**** but blockers don't apply if we're on WiFi
+
-
**** if we're on 3G then check for following blockers
+
-
***** location-daemon active (GPS in use) NOT DONE YET
+
-
***** SIP / Skype / GTalk calls (VoIP in use) NOT DONE YET
+
-
*** don't change anything if the user didn't want the phone to lock anyway
+
-
**** cooling off period during which device unlock cancels radio switch
+
-
** perform any final sanity checks
+
-
*** recheck that we're still not on a call after our cooling off period
+
-
** then make the switch to GSM mode
+
 +
# Test the current radio mode and abort if we're in GSM mode already
-
* Switch automatically to 3G or dual mode (which?) when something requires it
+
TEST=`dbus-send --system --type=method_call --print-reply --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.get_selected_radio_access_technology | g$
-
** no sense in triggering on device unlock, wait until needed
+
if [ ! -z "$TEST" ]
-
** check for blockers
+
then
-
*** don't change anything if we're already in the target radio mode
+
echo "Phone is already in 2G mode, aborting."
-
*** don't change anything if we're already using WiFi
+
exit 1
-
*** don't change anything if we're on a voice call
+
fi
-
** trigger on events that may require a data connection i.e.
+
-
*** launch pplication (via hildon desktop) - which apps?
+
-
**** browser
+
-
**** SIP client
+
-
**** maps
+
-
*** set presence to Online
+
-
*** open Modest e-mail account
+
-
*** access Internet radio stream
+
-
== Disable WiFi when not needed ==
+
# If we're on charge, we don't need to save battery so don't downgrade.
 +
TEST=`grep 1 /tmp/oncharge`
 +
if [ ! -z "$TEST" ]
 +
then
 +
# it's a non-zero value so we're on charge, abort gracefully
 +
echo "Phone is on charge, no need to set 2G mode, aborting."
 +
exit 1
 +
fi
-
=== Take down WiFi when not needed ===
+
# Test whether the phone is on a call, if it is don't mess with it
 +
TEST=`dbus-send --system --type=method_call --print-reply --dest=com.nokia.csd.Call /com/nokia/csd/call/1 com.nokia.csd.Call.Instance.GetStatus | grep "uint$
 +
#if phone is on call, grep filters out any call status but 0/idle, so we get a zero length output
 +
if [ -z "$TEST" ]
 +
then
 +
echo "Phone is making or receiving a call, aborting."
 +
exit 1
 +
fi
 +
## Adding a 30 cooling off period means that if the device gets unlocked again within 30 seconds, we can
 +
## kill this script whilst it's sleeping and leave 3G intact.
-
=== Restore WiFi ===
+
echo "Scheduling switch to 2G in 30 seconds..."
 +
sleep 30
-
There are few circumstances in which I want the phone to decide for itself to reenable WiFi, however it would be helpful to do so when I arrive home and put it on charge.
 
-
So we need to
+
# Make the actual change to 2G radio mode
-
* trigger when the phone is placed on charge
+
run-standalone.sh dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:1
-
* enable WiFi interface
+
echo "Phone set to 2G mode."
-
* attempt autoconnect to home wireless network
+
exit 0
-
* consider whether to disable WiFi if not successful in reaching home network
+
 
 +
</source>

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)