maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Nokia N900 (https://talk.maemo.org/forumdisplay.php?f=44)
-   -   [Announce] Auto2G: A battery saver script for the N900 (https://talk.maemo.org/showthread.php?t=47601)

nbc 2010-03-17 23:42

Re: [Announce] Auto2G: A battery saver script for the N900
 
Quote:

Originally Posted by Aydan (Post 570779)
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.

I've played a bit with your idea, I like it far more than the cron way and it's not so hard (even if harder than the cron script I think).

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

#
# You need to install dbus-scripts (BE CAREFUL, it's a devel package)
#
# as root you need to create a file /etc/sudoers.d/w32g
# with this line :
#  user ALL = NOPASSWD: /bin/ping
# and run the command update-sudoers because only root can use ping
#
# always as root and you need to create another file
# /etc/dbus-scripts/w32g with one of the following line :
#
#  to only change to 2g on connection (on one line) :
#  /home/user/bin/w32g * * com.nokia.icd status_changed * WLAN_INFRA CONNECTED
#
#  to change to 2g on connection and 3g on deconnection
#  /home/user/bin/w32g * * com.nokia.icd status_changed * WLAN_INFRA *
#
# if you want to change to 2g only with some wifi networks, put their maemo wifi id separated by |
# my $wifi = '91f493fb-7c89-4fc6-ac2c-b822923dde45|...';
# you can find the wifi id with the command gconftool-2 -R /system/osso/connectivity/IAP
my $wifi = '';


# if you don't want to test connection, change the ping string by "/bin/true"
my $connection_test = "sudo /bin/ping -c 1 www.google.com";

### end of documentation/configuration

my ($wifi_id,$state) = @ARGV[4,6];

# if we are not on the good wifi network we do nothing and exit
exit if $wifi and not $wifi eq $wifi_id;

my $dbus_wifi = "dbus-send --system --type=method_call --print-reply " .
    "--dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology";

my $dbus_notif = "dbus-send --system --type=method_call --print-reply " .
    "--dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint";

if ($state eq 'CONNECTED') {
    # we verified that the connection works
    my $ret = system($connection_test);
    if ($ret == 0) {
        system("$dbus_wifi byte:1");
        system("$dbus_notif string:'2G (GSM) cellular mode set'")
    }
} elsif ($state eq 'IDLE') {
    # to change to 3g instead of dual, use 2 instead of 0 in the line below
    system("$dbus_wifi byte:0");
    system("$dbus_notif string:'3G cellular mode set'")
}


nbc 2010-03-17 23:49

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.

nbc 2010-03-18 02:17

Re: [Announce] Auto2G: A battery saver script for the N900
 
2 Attachment(s)
Quote:

Originally Posted by nbc (Post 571281)
@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

Ok, I've done a python script that use a config file so it's easy to add a GUI. If I have time and some people ask for it I can try to build a package and why not a GUI.

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]

### the comment reflect the default configuration
### true is true (case insensitive), everything else is false

### the command used to test the wifi connection before downgrading to 2g
### if you don't want to do test just delete after =
connection_test = sudo /bin/ping -c 1 www.google.com

### notification message when going to 3g
message_on_idle = 3G cellular mode set
### notification message when going to 2g
message_on_connected = 2G (GSM) cellular mode set

### shall we go back to 3g when wlan disconnect ?
#### if you want to have false just delete after =
change_on_idle = true
### shall we go back to dual or 3g ?
change_to_dual = true

### if you want go to 2g only when connected to some wlan you can add their wlan id here
### you can find the wlan id using the command
### gconftool-2 -R /system/osso/connectivity/IAP
### For example :
### wifi = 91f493fb-7c89-4fc6-ac2c-b822923dde45 9ee5dd55-9a32-4ee9-9131-c464ad31d907
# wifi =


baksiidaa 2010-03-18 23:14

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.

nbc 2010-03-19 00:22

Re: [Announce] Auto2G: A battery saver script for the N900
 
Quote:

Originally Posted by baksiidaa (Post 572599)
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.

It's doable but using ifup to enable fcron pulling seems to me like using a sledgehammer to crack a nut while dbus signal is like a groom knocking on your door to wake you up :D

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 :)

gregc2009 2010-03-19 15:39

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?

nbc 2010-03-23 21:11

Re: [Announce] Auto2G: A battery saver script for the N900
 
Quote:

Originally Posted by gregc2009 (Post 573486)
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?

Ok, I've searched a bit and found a solution. You can check if there's a call with this code :
Code:

dbus-send --system --dest=com.nokia.csd.Call --print-reply=literal /com/nokia/csd/call/1 com.nokia.csd.Call.Instance.GetStatus
It will return "uint32 0" if no call

So I've modified the script to test this before . You can find it on this wiki page User:Nbc/W32g

JohnLF 2010-04-07 22:21

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.

rooted 2010-04-07 22:27

Re: [Announce] Auto2G: A battery saver script for the N900
 
if [`ps | grep joiku` = ...]
exit

else
-script-

It's a very simple addition.

Patola 2010-04-07 23:33

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.


All times are GMT. The time now is 03:41.

vBulletin® Version 3.8.8