View Single Post
Posts: 43 | Thanked: 32 times | Joined on Jan 2010
#625
How to disconnect automatically from idle networks (3g/2g/wi-fi)

Before you start, you'll need to install vim and rootsh, both found in the extras repository. (if you don't know how to use vim, google "vim manual")

1) In xterminal input
Code:
sudo gainroot
2) In xterminal input
Code:
vim /usr/local/bin/autodisconnect
3) Contents of /usr/local/bin/autodisconnect:
Code:
#!/bin/sh
sleep 180
a=`tail -1 /proc/net/route | cut -f1`
b=`ifconfig $a | grep RX.b | cut -d"(" -f1 | cut -d: -f2`
while [ "$a" != "Iface" ] 
do
       c=`expr $b + 1000`
       sleep 180
       b=`ifconfig $a | grep RX.b | cut -d"(" -f1 | cut -d: -f2`
       a=`tail -1 /proc/net/route | cut -f1`
       if [ "$b" -lt "$c" -a "$a" != "Iface" ]; then
              dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
              sleep 10
              a=`tail -1 /proc/net/route | cut -f1`
       fi
done

exit 0
4) In xterminal input
Code:
chmod a+x /usr/local/bin/autodisconnect
5) In xterminal input
Code:
vim /etc/network/if-up.d/00_autodisconnect
6) Contents of /etc/network/if-up.d/00_autodisconnect
Code:
!#/bin/sh
#Run a script to disconnect idle networks

console none

script
              /usr/local/bin/autodisconnect
end script

exit 0
7) In xterminal input
Code:
chmod a+x /etc/network/if-up.d/00_autodisconnect
8) Reboot device

9) Enjoy!

Extra instructions for those looking specific funcionallity:

a) If you want to disconnect only from wi-fi change line 5
Code:
while [ "$a" != "Iface" ]
to
Code:
while [ "$a" == "wlan0" ]
b) You can also play with two values:

i) The constant (1000 in this case) in line 7 is about how many bytes must be receiven in a given period of time (the sleep time in line 9) to consider the connection in use. Anything less than that is considered idle. I also recomend a low number because I still don't know exactly how does it get along with idling in IM (but you still want to stay "Avalaible"). If you get randomly disconnected when idling in IM lower the value.

ii) The sleep time in line 8 determines when you'll disconnect automatically. It will almost never be the exact time indicated. If you stop using your connection it should disconnect in a range of x to 2x seconds of the time set (x being the sleep time).

Any questions post here: http://talk.maemo.org/showthread.php...499#post518499 . Hope it works for you. Both posts will be kept updated (if I ever change anything else).

Last edited by azstunt; 2010-02-11 at 06:05.
 

The Following 8 Users Say Thank You to azstunt For This Useful Post: