![]() |
[Announce] Auto2G: A battery saver script for the N900
1 Attachment(s)
Hi guys, after a couple of months browsing these forums and learning all about my new device I've decided to share a little shell script with you that has extended my phone's running time.
It's nothing new, simply the putting together of snippets of information gleaned from various threads. Took me a few days to gather it all, write it, test it and get it to a point where I was happy it works properly. I've been running it for a while with no problems. This goes to show how open this platform is and the endless possibilities it could provide (and to anyone leaving the party early, you are missing out, I really believe that). Anyway, the script simply checks for an active WiFi connection, and if one is found, it changes the cellular mode from 3G to 2G. It can be made to automatically revert to 3G upon loss of WiFi if required. A little popup notification briefly appears to indicate a change. Here it is (there's a file to download at the bottom of this post - Note if you download this file you will need to run a chmod 755 auto2g.sh on it in Xterminal to make it an executable file.) Code:
#!/bin/sh The reason for the PING is that for some WiFi connections, such as public hotspots, the WiFi can be running but you don't get access until you click an agreement or pay a fee. That line checks the connection is actually working before disabling 3G. The second IF was required as without it, the N900 set 2G every minute and popped up the notification, which was quite annoying after a while! ;) The echo near the end is only required if the dbus commands are commented out as there needs to be something between the else and the fi. I used this with Fcron and scheduled it to run every minute. Fcron instructions can be found here. Note Fcron is in extras-devel only, and you will need to know how to use the Vi editor. Usual warnings apply. On my N900, the auto2g.sh file is in /home/user. My cron job was set up like so Code:
0-59 * * * * /home/user/auto2g.sh Thanks to everyone on these forums for the excellent help received, and to Rob1n who showed me the difference between backticks and brackets in shell scripts! One point to note: This script only deals with 2G and 3G modes, it does not deal with Dual mode as I don't use that myself - I will leave that as an exercise for the reader :D Enjoy, and please post back any improvements you make! |
Re: [Announce] Auto2G: A battery saver script for the N900
Id love this as an app with GUI, nice work
|
Re: [Announce] Auto2G: A battery saver script for the N900
hey!! good job!
|
Re: [Announce] Auto2G: A battery saver script for the N900
@f2thak
There is an applet app that gives you the opportunity to change 3G in2 2G |
Re: [Announce] Auto2G: A battery saver script for the N900
Really like the idea but could do with some spacing in your code and a few more comments to get a really good idea of what it is doing.
|
Re: [Announce] Auto2G: A battery saver script for the N900
Look at the attached zip file, it will be clearer - the text wrapping on the code above makes it look awful
Pseudo code: - Code:
if wlan0 running |
Re: [Announce] Auto2G: A battery saver script for the N900
Would be good to bundle into tweakr.
@JohnLF - Any estimations on battery life saved with this? Does the cronjob itself have much overhead? |
Re: [Announce] Auto2G: A battery saver script for the N900
Fcron is a proper implementation of cron - i.e. it puts itself to sleep when not in use. I've not done any scientific testing, but if it actually switches modes I see three bars on the CPU meter in the staus area for about a second, if it doesn't switch, I see a single bar for about a second. I figure that will be a lot less power use than having 3G, but again, nothing to back that up, other than the fact that I don't have to charge my N900 more than once a day now.
If you think it is too much, you could change the cron job to run every 5 minutes instead of every minute. To do that, use Code:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /home/user/auto2g.sh |
Re: [Announce] Auto2G: A battery saver script for the N900
Potentially handy script, thanks.
A slightly neater job for the 5-minutely cron though would be: Code:
*/5 * * * * /home/user/auto2g.sh |
Re: [Announce] Auto2G: A battery saver script for the N900
Just had an idea, not sure if it's practical or better than the above method BUT
You could add sleep 300 (5 mins) and then run-standalone.sh <path to script>. Add a .desktop icon in /usr/share/applications/hildon Run it, and it should keep looping. |
All times are GMT. The time now is 08:04. |
vBulletin® Version 3.8.8