Reply
Thread Tools
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:
Posts: 36 | Thanked: 42 times | Joined on Jan 2010
#22
@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.

Last edited by nbc; 2010-03-17 at 23:54.
 
Posts: 36 | Thanked: 42 times | Joined on Jan 2010
#23
Originally Posted by nbc View Post
@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 =
Attached Files
File Type: txt w32g.py.txt (2.3 KB, 191 views)
File Type: txt w32g.conf.txt (968 Bytes, 152 views)

Last edited by nbc; 2010-03-18 at 02:37.
 

The Following 3 Users Say Thank You to nbc For This Useful Post:
Posts: 183 | Thanked: 115 times | Joined on Nov 2007 @ Seattle, WA
#24
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.
 
Posts: 36 | Thanked: 42 times | Joined on Jan 2010
#25
Originally Posted by baksiidaa View Post
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

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
 
Posts: 56 | Thanked: 7 times | Joined on Dec 2009 @ Spokane, WA
#26
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?
 

The Following User Says Thank You to gregc2009 For This Useful Post:
Posts: 36 | Thanked: 42 times | Joined on Jan 2010
#27
Originally Posted by gregc2009 View Post
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's Avatar
Posts: 551 | Thanked: 507 times | Joined on Feb 2010 @ North West England
#28
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.
__________________
My websites: -
http://www.lefebvre.org.uk
http://www.lefebvre.ltd.uk
 
Posts: 156 | Thanked: 90 times | Joined on Jan 2010
#29
if [`ps | grep joiku` = ...]
exit

else
-script-

It's a very simple addition.
 
Posts: 267 | Thanked: 183 times | Joined on Jan 2010 @ Campinas, SP, Brazil
#30
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.
__________________
My nickname on freenode is ptl, that is, the consonants of my nickname here. Kind of a long story.
 
Reply


 
Forum Jump


All times are GMT. The time now is 20:05.