Reply
Thread Tools
Posts: 43 | Thanked: 32 times | Joined on Jan 2010
#101
Originally Posted by raily View Post
ok, good I was to lazy yesterday to set up the test
But is you Script in post #93 affecting packet connection over 3G, GPRS? I just want to disconnect WLAN, hence I don't think I can idle in ICQ when on 3G anymore if I use Script #93.
It is made to disconnect from any idle connection (3G, GPRS and wi-fi). I'm not sure how many bits do you receive per minute when idle on ICQ via 3G. If you receive less than 1000 bytes each 3 mins it will disconnect you. You can always play with that number. Try setting it to 500 instead of 1000 (line 8 in my script) or lower. If that's not what you are looking for you can always just change "lface" to "wlan0" in lines 6 and 12.

Last edited by azstunt; 2010-02-09 at 16:47. Reason: EDIT: I believe you'll have problems once again... sorry about that. Check the script at #93 again.
 
Posts: 3 | Thanked: 0 times | Joined on Feb 2010
#102
Just a small battery regarding notice: With a similar script I end the day with about 80% battery. Mails are updated automatically every two hours, I use all kind of widgets like omweather. It's true that I don't speak that much at the telephone.
Before coding that script my battery was almost drained at the end of the day. I didn't expect wlan controller to be _that_ power unfriendly.
 
Posts: 318 | Thanked: 49 times | Joined on Nov 2009
#103
Interesting, no wonder so many people are unsatisfied with the battery. It seems that the issue isn't the need for a larger battery but better power management...
 
Posts: 472 | Thanked: 442 times | Joined on Sep 2007
#104
Can we get a "latest and greatest" working version of that script slapped into a fresh thread or somewhere easily accessible in case modifcations/updates are made to it? I am interested in trying this out but would like to know which version is the one people are using with the most success at the moment.
__________________
If you don't know how to check your N900's uptime, you probably shouldn't own it.
 
Posts: 3 | Thanked: 0 times | Joined on Feb 2010
#105
well, this is what I'm using - based on a similar idea from his thread. Improvments are welcomed, I'm looking especially for "screen on" info in order to let he connection alive when screen is lit.

#!/bin/sh

while true; do
a=`tail -1 /proc/net/route | cut -f1`
b=`grep wlan0 /proc/net/dev | cut -c 9-18`

while [ "$a" = "wlan0" ]
do
c=`expr $b + 6000`
sleep 180
b=`grep wlan0 /proc/net/dev | cut -c 9-18`
d=`expr $b + 1`
a=`tail -1 /proc/net/route | cut -f1`
if [ "$d" -lt "$c" -a "$a" = "wlan0" ]; then
echo Disconnecting
dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
fi
done
sleep 180
done
 
qwerty12's Avatar
Posts: 4,274 | Thanked: 5,358 times | Joined on Sep 2007 @ Looking at y'all and sighing
#106
Originally Posted by kefren View Post
well, this is what I'm using - based on a similar idea from his thread. Improvments are welcomed, I'm looking especially for "screen on" info in order to let he connection alive when screen is lit.
That's broadcast over D-Bus as a signal: signal sender=:1.7 -> dest=(null destination) serial=3499 path=/com/nokia/mce/signal; interface=com.nokia.mce.signal; member=display_status_ind
string "on"

"on" can also be "dimmed" and "off". I guess you can use dbus-scripts or something similar to have something happen upon the display state changing.
 
Posts: 43 | Thanked: 32 times | Joined on Jan 2010
#107
Originally Posted by Laughingstok View Post
Can we get a "latest and greatest" working version of that script slapped into a fresh thread or somewhere easily accessible in case modifcations/updates are made to it? I am interested in trying this out but would like to know which version is the one people are using with the most success at the moment.
That's why I've been just updating the one at post #93. But anyway... Let this be the one that I'll be keeping updated.

How to disconnect automatically from idle networks (3g/2g/wi-fi)

UPDATED 09/02/10
SECOND UPDATE 09/02/10 - FIXED A FEW TYPOS
THIRD UPDATE 09/02/10 - MADE THE INSTRUCTIONS MORE USER FRIENDLY
UPDATED 10/02/10 - MADE IT START ONLY WHEN A CONNECTION IS ACTIVE
SECOND UPDATE 10/02/10 - FIXED A TYPO... HAD FORGOTTEN A LINE
THIRD UPDATE 10/02/10 - NO CHANGE TO THE SCRIPT OR MAIN INSTRUCTIONS, JUST TO THE EXTRA FUNCTIONALLITY INSTRUCTIONS


Before you start, you'll need to install vim and rootfsh, both found in the extras repository.

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 feel free to post here. Hope it works for you.

Last edited by azstunt; 2010-02-11 at 03:16.
 

The Following 4 Users Say Thank You to azstunt For This Useful Post:
Posts: 241 | Thanked: 69 times | Joined on Dec 2009 @ Germany
#108
Is it normal that two instances of the Script are running? I don't know how things in event.d work, so I am just curious.
Code:
Nokia-N900-42-11:~# ps |grep auto
 1288 root      2084 S    /bin/sh -e -c /usr/local/bin/autodisconnect  /bin/sh 
 1289 root      2084 S    /bin/sh /usr/local/bin/autodisconnect
I did the Internetradio test again it it works great! Couldn't test ICQ idling though because it doesn't connect me since yesterday on my N900. But thats a different story. I'll update you when my ICQ is working again.
 
Posts: 43 | Thanked: 32 times | Joined on Jan 2010
#109
Originally Posted by raily View Post
Is it normal that two instances of the Script are running? I don't know how things in event.d work, so I am just curious.
Code:
Nokia-N900-42-11:~# ps |grep auto
 1288 root      2084 S    /bin/sh -e -c /usr/local/bin/autodisconnect  /bin/sh 
 1289 root      2084 S    /bin/sh /usr/local/bin/autodisconnect
I did the Internetradio test again it it works great! Couldn't test ICQ idling though because it doesn't connect me since yesterday on my N900. But thats a different story. I'll update you when my ICQ is working again.
I also don't know how things in event.d work, in every instance I used PS I found the same as you did, but I believe it to be normal. And I think that it should work with most (if not all IM), if it doesn't, try reading above and lower the value in line 8.
 
calvin_42's Avatar
Posts: 286 | Thanked: 219 times | Joined on Feb 2010 @ France
#110
Hi there. I've been running the following script for now a week and it works pretty good on my device both with 3G and Wifi. Since it's the script I want to use in an application I am currently developping, if I could have some feedbacks, it would be great.

Thx!

Code:
#!/bin/sh
logentry()
{
	#SEND A STRING TO THIS FUNCTION TO APPEND IT TO THE LOG FILE
	echo -e "$1" >> ~/autoDCLog.txt
	echo "$1"
}

osnotify()
{
	#SEND A STRING TO THIS FUNCTION TO GENERATE A SYSTEM POPUP
	dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"$1"
}

disconnect()
{
	#DISCONNECT CURRENT CONNECTION
	dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
}

#PREPARE INITIAL VARIABLES FOR TEMPORAL MONITORING OF NETWORK INTERFACES
interface=`tail -1 /proc/net/route | cut -f1`
packets_before=`grep $interface /proc/net/dev | awk '{ print $10 }'`

#LOG MONITOR STARTUP TO FILE & NOTIFY USER VIA POPUP
logentry "\nIdle Monitor Startup $(date)\nEVENTS:\n"

#PERFORM MAIN MONITORING LOOPS
while true;
do
	#CHANGE THE NUMBER AFTER SLEEP TO SET THE NUMBER OF SECONDS BEFORE
	#THE INTERNET IS DISCONNECTED IF NO INTERNET ACTIVITY IS DETECTED
        sleep 300

	interface=`tail -1 /proc/net/route | cut -f1`

	logentry "Current connexion : $interface"

	if [ "$interface" != "Iface" ]; then

		packets_after=`grep $interface /proc/net/dev | awk '{ print $10 }'`
		logentry "Packets : $packets_before -> $packets_after"

		if [ "$packets_before" = "$packets_after" ]; then
			disconnect
			osnotify "Connection closed due to inactivity"
			logentry "[Connection closed @ $(date)]"
			packets_before=0
		else
			packets_before=$packets_after              
		fi
	fi

done

exit
 

The Following User Says Thank You to calvin_42 For This Useful Post:
Reply

Tags
automatic, connect, connect automatically, connect on activity, connect on demand, connect on use, data, data connection, disconnect, disconnect automatically, disconnect when idle, fremantle, gprs, internet, maemo, maemo 5, n900, on demand, on use

Thread Tools

 
Forum Jump


All times are GMT. The time now is 12:35.