View Single Post
Posts: 36 | Thanked: 42 times | Joined on Jan 2010
#21
Originally Posted by Aydan View Post
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'")
}

Last edited by nbc; 2010-03-17 at 23:45.
 

The Following 2 Users Say Thank You to nbc For This Useful Post: