![]() |
[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. |
Re: [Announce] Auto2G: A battery saver script for the N900
@MohammadAG
Did consider that originally but wasn't sure if the scripts would ever end and so would nest forever eventually running out of memory. Big lack of Linux knowledge on my part there, hence the cron method. @nidO, thanks, that's much neater! |
Re: [Announce] Auto2G: A battery saver script for the N900
If you could make that into a demon with dbus messaging it would be perfect. :)
It might even be more energy efficient because you wouldn't need polling. You could just listen for the "wifi (dis)connect event" from dbus. |
Re: [Announce] Auto2G: A battery saver script for the N900
I didn't do that because of the hotspot issue. You could automatically connect to a hotspot with a valid IP address, but it wouldn't necessarily be active unless you clicked agree or put your card details in to buy time or logged in with an account.
It would be very annoying if you didn't want to use WiFi in a hotspot area and the phone kept changing your 3G connection to a 2G ! There could be any amount of time between connecting to a hotspot and getting a working connection, hence the polling. |
Re: [Announce] Auto2G: A battery saver script for the N900
Excellent idea JohnLF! This should help me a ton.
What CPU meter are you using that is shown in the status area? |
Re: [Announce] Auto2G: A battery saver script for the N900
Would it be possible to switch to 3g when the phone is charging?
|
Re: [Announce] Auto2G: A battery saver script for the N900
Quote:
|
Re: [Announce] Auto2G: A battery saver script for the N900
Very nice idea indeed.
However, just a little warning for those who started using their N900 on WindMobile in Canada. As I had a chance to confirm, N900 relies on the 3G based data connection for voice as well. Switching to 2G turns off the cellular connection on Wind automatically. :( |
Re: [Announce] Auto2G: A battery saver script for the N900
Works like a champ. The only thing I'd add to your first post is the need to do a chown and chmod to auto2g.sh after you get it where you need it.
|
Re: [Announce] Auto2G: A battery saver script for the N900
Quote:
Even if you want it to keep polling I think it would be nicer as a properly packaged demon, so the noobs can use it too. |
Re: [Announce] Auto2G: A battery saver script for the N900
Good idea, I'll look into it but out of my level of knowledge here. Any takers on moving this forward to a packaged daemon?
I did think about a GUI for it, that allowed you to select
I may have to have a crash course in Python / Qt :D |
Re: [Announce] Auto2G: A battery saver script for the N900
Quote:
I use dbus-scripts, it's a daemon a bit like cron but for dbus. So I add a rule to dbus-scripts, that rule watch for a wifi connection or deconnection signal. Just follow the instructions of the install/configuration doc at the beginning of the following script and copy the script in a file /home/user/bin/w32g : Code:
#!/usr/bin/perl |
Re: [Announce] Auto2G: A battery saver script for the N900
@JohnLF
Hum yes, I'm more a perl guy but that's a good idea, I could try to do that in python. Could be fun. And to add a GUI, you can just create a conf file and the script called by dbus-scripts can read that file And this is very easy to package. |
Re: [Announce] Auto2G: A battery saver script for the N900
2 Attachment(s)
Quote:
You must copy the file w32g.py.txt (see below attached files) in /home/user/bin/w32g and follow the instruction at the beginning of this file to install it. If you want a different configuration you can copy the file w32g.conf.txt to /home/user/.w32g.conf. If you don't want a different configuration there's no need to copy it now. For information, the default configuration is : Code:
[w32g] |
Re: [Announce] Auto2G: A battery saver script for the N900
An alternative to fcron and dbus would be to put a script in /etc/network/if-up.d (and in if-down.d). If you want to keep doing the polling, put a script there that enables fcron-managed polling.
|
Re: [Announce] Auto2G: A battery saver script for the N900
Quote:
Using if-up.d/if-down.d is quite easy to use but limited to network automation. dbus allow me to automatize many things. I like dbus :) |
Re: [Announce] Auto2G: A battery saver script for the N900
Ran into a problem with it last night. I was on a work call and when I got home, it was dumped as the phone switched to the home wifi and then dropped to 2G. Called him back and then I was leaving home and after I lost my wifi, the script brought me back to 3G and dumped the call. Anyway to add a provision for it not to do anything if there is an active call?
|
Re: [Announce] Auto2G: A battery saver script for the N900
Quote:
Code:
dbus-send --system --dest=com.nokia.csd.Call --print-reply=literal /com/nokia/csd/call/1 com.nokia.csd.Call.Instance.GetStatus So I've modified the script to test this before . You can find it on this wiki page User:Nbc/W32g |
Re: [Announce] Auto2G: A battery saver script for the N900
Update on this: found a problem. For the first time I'm using Joikuspot in a hotel to get my laptop online. Whenever I connect, because Joikuspot is using WiFi to share the 3G signal, it disconnects and drops down to 2G. Very annoying - when I eventually realised what was happening I had to rename the script temporarily to stop it running!
If anyone packages this, there will have to be way to stop this or perhaps just have a way to turn it off manually. |
Re: [Announce] Auto2G: A battery saver script for the N900
if [`ps | grep joiku` = ...]
exit else -script- It's a very simple addition. |
joikuspot and call during network connect/disconnect
A truly complete program, besides checking for these two conditions (ongoing call and joikuspot sharing), should also wait for these two events to finish before switching to 2G/3G, and when doing that, first check if the condition hasn't changed again.
The logic starts to become complicated here. We would have to use some threads for that? BTW, if a packaged script with some user interface is done, I'd recommend using the regular if-up.d and if-down.d networkmanager scripts, because it is not very good to depend on dbus-scripts because it's still in extras-devel, not extras. This way you get only the interface being connected/disconnected, but you can get the remaining details with iwconfig and the like. |
Re: [Announce] Auto2G: A battery saver script for the N900
Hope this will be in the repos (with a gui) soon! :)
Very handy script!!! :) |
Re: [Announce] Auto2G: A battery saver script for the N900
Quote:
Any ideas how to fix this? I have the 3G 2G status bar applet installed, may this interfere with the dbus-script? Thanks a lot in advance for your help! Update: Using the script from http://wiki.maemo.org/User:Nbc/W32g I got it to work, however I had to disable the connection test although w32g is in sudoers.. Strange. |
Re: [Announce] Auto2G: A battery saver script for the N900
Can anyone help out with an easy script that switches too 3G (if available) when i open a data connection (tethering), and switches back to GSM when i close the connection?
Tried messing with dbus-scripts-settings a little, but i got no response on the n900. |
Re: [Announce] Auto2G: A battery saver script for the N900
I was just looking for this.
Would love to see it with a GUI, though. Any intentions on programming it? |
Re: [Announce] Auto2G: A battery saver script for the N900
Quote:
|
Re: [Announce] Auto2G: A battery saver script for the N900
Well, it's not exactly the same thing, but it'll do. Thank you HtheB :)
|
All times are GMT. The time now is 09:05. |
vBulletin® Version 3.8.8