maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Maemo 5 / Fremantle (https://talk.maemo.org/forumdisplay.php?f=40)
-   -   Connect to Internet on demand & disconnect automatically, particularly for GPRS? (https://talk.maemo.org/showthread.php?t=38832)

#9370 2009-12-30 20:14

Connect to Internet on demand & disconnect automatically, particularly for GPRS?
 
Hello,

is it somehow possible that internet connections are only established on demand? -> i.e. when email sync starts or the browser launches.
After the task completes, the connection should be automatically closed again.
On my Symbian phone this was the default setting and I liked it.
I do no want to manually connect/disconnect all the time nor a permanent connection.

Thanks,
#9370

HoellP 2010-01-01 14:34

Re: internet connection on demand
 
I'd like that too. To be precise i'd like a staged connection, meaning i'm always connected to 2g network for im/mail, if i open an app which needs more bandwidth (browser, netradio, etc...) it first looks for known wifi and if none available connects via 3g. After i close the app it should automaticall switch back to 2g.
That's kinda how i do it now manually to get the most out of the battery and am still online most of the time, but that's kinda invonvenient.

lardman 2010-01-01 14:49

Re: internet connection on demand
 
This used to be the way things worked in Diablo, auto-connect then disconnect after some period of inactivity.

I'd also like this to be a possibility on Fremantle, however I think the designers' idea is that it should always be connected, not sure if we'll be able to do much to change their minds (other than install and use our own program/daemon to monitor network activity and perform the disconnection for us)

inzimam 2010-01-01 15:13

Re: internet connection on demand
 
Well at least make it so that if an application you are going to use wants to access the internet, it comes up with 'Establish internet connection' just like S60v5 does.

It is annoying to have to go to connection each time, open the connection and then open the application.

Matan 2010-01-01 15:26

Re: internet connection on demand
 
You can find out when an application starts and stops, by listening to NameOwnerChanged signal on dbus, so it is really easy to use dbus-scripts to start a specific connection when an application starts, and disconnect from network when the application stops. Adding reference counting is less trivial, but not too hard.

For applications that keep running but need to connect only once in a while (such as mail) it is harder, probably needing some ip tricks - have a default route to some dummy interface when not connected, and initiate a real connection when something uses this interface, for example.

geneven 2010-01-01 15:28

Re: internet connection on demand
 
I was in some application (zoutube? evernote mobile?) and when I tried to use it it said that I had to be on the Internet. I knew that, but I am in my house and my WiFi is always on, my setting is Always Connect to WiFi.

So to fix it I opened up a browser or something and it then figured out I was on the Internet and let me run the application!

fpp 2010-01-01 16:25

Re: internet connection on demand
 
There are at least two bugs open to bring back disconnect-on-inactivity. Go vote for one !

paulkoan 2010-01-02 10:50

Re: internet connection on demand
 
I wonder what would be considered inactivity? It seems like better control is needed over the packet network connection for sure.

But I have IM, RSS, email, weather, sip all wanting to access the internet, and so triggering "activity".

None of these require 3g most of the time. The ideal management tool would allow you to define the networks that each application could run on.

Wifi only, wifi+gsm, wifi+3g. This doesn't seem likely to happen so I would settle for a manual switch between packer data off, packet data gsm only, and packet data 3g (from an icon on the desktop or via status).

Can this be changed from the command line - perhaps via dbus?

#9370 2010-01-02 11:52

Re: internet connection on demand
 
Quote:

Originally Posted by fpp (Post 448937)
There are at least two bugs open to bring back disconnect-on-inactivity. Go vote for one !

do you have a link for the bugs?

Thanks,
#9370

joppu 2010-01-02 11:58

Re: internet connection on demand
 
Just set the "always ask" in the Internet connection settings and I'll ask you when you start and application that needs to be connected. You'll still need to manually disconnect.

2gDSM 2010-01-02 22:44

Re: internet connection on demand
 
I would be very interested in this feature as well, if only on GSM/3G. Battery life takes a huge hit when I remain connected to the network, likely due to the radio constantly searching for signal.

woodyear99 2010-01-07 06:26

Allow widgets/apps to automatically connect and then automatically disconnect internet connection. Possible?
 
Hi

I noticed that leaving my GPRS (2G EDGE, no 3G) connection on all the time drains the battery faster than when it is always off. For the widgets such as the weather application, it will only update every 4 hours when there is an active internet connection. Is there a way to set the phone to auto connect to gprs when a widget/app requests it and then automatically disconnect after transfer is complete?

This would significantly improve my battery life instead of leaving gprs connected all day when it is not in use.

bandora 2010-01-07 06:54

Re: How to connect to the internet only when needed?
 
As far as I know.. There's no such thing.. I might be wrong though! :/

HugoSon 2010-01-07 07:00

Re: How to connect to the internet only when needed?
 
This does not seem to be a usecase - and for sure our battery life would improve a lot or we had to click less - Nokia had in mind with this communication/facebook/youtube/flash enabled device.
But now being in the hands of real world users taking care about connection costs/battery life they might re-thing - hopefully...

Bugslife 2010-01-07 07:39

Re: How to connect to the internet only when needed?
 
Quote:

Originally Posted by woodyear99 (Post 456811)
Hi

I noticed that leaving my gprs connection on all the time drains the battery faster than when it is off. For the widgets such as the weather application, it will only update every 4 hours when there is an active internet connection. Is there a way to set the phone to auto connect to gprs when a widget/app requests it and then automatically disconnect after transfer is complete?

This would significantly improve my battery life instead of leaving gprs connected all day when it is not in use.


Go to settings, internet connections, choose "always ask", then save.

To manually connect to the web, you can either tap on the web "globe icon", any bookmark site,etc. It will prompt you to connect to internet or GPRS.

To connect or disconnect just tap the top screen icons (battery or 3g/2G network icon). A drop down menu will appear. Info about battery, profile, clock.alarm, internet connections, bluetooth, usb. Tap the internet connection and will give you options/selections. from there you can connect or disconnect from internet.

I wish I could show you screen shots but don't know how to do screen shots.

wheatbisc 2010-01-07 08:07

Re: How to connect to the internet only when needed?
 
Quote:

Originally Posted by Bugslife (Post 456850)
I wish I could show you screen shots but don't know how to do screen shots.

Ctrl + Shift + P
To take a scr shot, the image file is saved in /home/user/MyDocs/.images/Screenshots/

/Wheatbisc

woodyear99 2010-01-07 12:46

Allow widgets/apps to automatically connect and then automatically disconnect internet connection. Possible?
 
Quote:

Originally Posted by Bugslife (Post 456850)
Go to settings, internet connections, choose "always ask", then save.

To manually connect to the web, you can either tap on the web "globe icon", any bookmark site,etc. It will prompt you to connect to internet or GPRS.

To connect or disconnect just tap the top screen icons (battery or 3g/2G network icon). A drop down menu will appear. Info about battery, profile, clock.alarm, internet connections, bluetooth, usb. Tap the internet connection and will give you options/selections. from there you can connect or disconnect from internet.

I wish I could show you screen shots but don't know how to do screen shots.

I do not want to manually connect to the internet, I want it to automatically connect when widgets/apps request data at their intervals, once data transfers have been done I want it to disconnect the gprs connection. That would improve battery life since I noticed that just leaving the gprs connection running all day drains the battery faster even when not in use.

Dr. Drips 2010-01-07 13:04

Re: How to connect to the internet only when needed?
 
As stated many times before putting the Phone settings to GSM (2G) really is good for the battery and is good enough for calling/im.

It would be great to have an easy way to switch between 2G/3G.
so you can activate 3G when needed.

mikec 2010-01-07 13:36

Re: Allow widgets/apps to automatically connect and then automatically disconnect internet connection. Possible?
 
Quote:

Originally Posted by woodyear99 (Post 457191)
I do not want to manually connect to the internet, I want it to automatically connect when widgets/apps request data at their intervals, once data transfers have been done I want it to disconnect the gprs connection. That would improve battery life since I noticed that just leaving the gprs connection running all day drains the battery faster even when not in use.

Er thats how UMTS 3g works. It turns off the tranciever and receiver power needs when in active. The technical terms are Discontounius Transmission and reception DTX/DRX. It has some intelligence on what the turn off vs turn on times are also,especially important when making voice calls or there is a delay in traffic, you dont want the link to drop cause the system turned of the power.

heres a good overview.

http://www.csee.umkc.edu/csee-semina...377,6,Overview

I find that my wifi consumes more power when I am out and about if I leave it on autoscan as its alwas hunting for wifi connections.

woodyear99 2010-01-07 14:20

Allow widgets/apps to automatically connect and then automatically disconnect 2G internet connection. Possible?
 
I should have specified, I do not have 3G only 2G edge service. Phone is set to 2g only, does not seem to automatically disconnect after weather updates etc. I can confirm that leaving my 2G EDGE connected all day reduces battery life even when not in use.

sjgadsby 2010-01-07 14:28

Re: Connect to Internet on demand & disconnect automatically, particularly for GPRS?
 
Threads merged.

woodyear99 2010-01-07 14:50

Re: internet connection on demand
 
Quote:

Originally Posted by #9370 (Post 449763)
do you have a link for the bugs?

Thanks,
#9370

Bugs here, go vote for them :)

https://bugs.maemo.org/show_bug.cgi?id=5422

https://bugs.maemo.org/show_bug.cgi?id=6627

#9370 2010-01-17 11:30

Re: Connect to Internet on demand & disconnect automatically, particularly for GPRS?
 
Thank you for the links.

/#9370

#9370 2010-01-17 12:24

Re: Connect to Internet on demand & disconnect automatically, particularly for GPRS?
 
I now created a brainstorm item for this:
http://maemo.org/community/brainstor...automatically/

Please vote for it!

/#9370

woodyear99 2010-01-17 13:23

Re: Connect to Internet on demand & disconnect automatically, particularly for GPRS?
 
This would definitely improve battery life for those who only use applications that need periodic updates...

stopgap 2010-01-20 00:07

Re: Connect to Internet on demand & disconnect automatically, particularly for GPRS?
 
Before I start, let me just say that I love this phone. It does however need some significant fixes and automatic connection/disconnections is certainly one of them.

I have come from an N95 and on that I had several connections defined. I had various wifi points, including my home ones and I had two 2G connections (bad 3G signal where I am). One went ahead and connected without prompt, the other I had set to ask for a password.

Anything like weather, email etc. that was to be "always on" used the unrestricted internet connection.
Everything else I chose how to connect, be it wifi or 2G (using the passworded connection).

The phone checked my emails and whatnot and closed the 2G connection automatically. After using any other application, the connection was also closed obviously on all other wifi/2G connections.

The only thing it didn't do right was to allow a connection priority profile thing (which I think the N97 does allow...?) whereby you choose wifi a, then b, then blah, then 3G then give up.

The N900 should be so much more advanced at handling connections - to simply come on and stay on is really beyond basic and I can't imagine why this route was chosen. At least an inactivity auto-disconnect timer OPTION should be included.

I also don't want to trust the phone to handle my 2G/3G connection as if something goes wrong and starts downloading lots of data (due to a bug/bad design/whatever) I could end up with a huge bill. I'm on a data plan but the recent firmware updates used up over 20% of my monthly allowance - all it would take is for my home wifi connection to drop out for a moment (or longer) and the phone would decide to use 3G (if the setting to allow this is ticked of course). It's not always obvious that it is happening either. The email application seems to just download emails and attachments automatically - I see no option to turn it off. I regularly get emails from clients with truly massive attachments *sigh* (100MB+). On my N95 I would just choose not to download those but have no choice on the N900 for such things - except to turn off automatic email checking - and then what's the point in the phone really?

At the moment my data connection is pretty much useless when I'm out and about - there's just too little control to trust the phone with it. An OS like this should be promoting more complex options, more power to control power usage and more granular control over scenario/use profiling of ALL features.

In these respects the N900 is far inferior to Symbian on the N95/N82 etc and I assume 5800/N97 and so on. This REALLY needs fixing (and yes I have voted on the bugs - can't log onto brainstorm to vote there).

Matan 2010-01-20 00:46

Re: Connect to Internet on demand & disconnect automatically, particularly for GPRS?
 
This script should disconnect from network (wlan or GPRS/UMTS) after 5 to 10 minutes of no received packets:

Code:

#!/bin/sh
a=`ifconfig phonet0 | grep RX.p | cut -d: -f2`
c=`ifconfig wlan0 | grep RX.p | cut -d: -f2`
b=$a
d=$c

while true ; do
        sleep 300
        a=`ifconfig phonet0 | grep RX.p | cut -d: -f2`
        c=`ifconfig wlan0 | grep RX.p | cut -d: -f2`
        if [ "$a" == "$b" -a "$c" == "$d" ] ; then
                dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
        fi
        b=$a
        d=$c
done


woodyear99 2010-01-20 01:31

Re: Connect to Internet on demand & disconnect automatically, particularly for GPRS?
 
Hmm gotta go on google to try and figure out how to use this on my n900.

stopgap 2010-01-20 17:30

Re: Connect to Internet on demand & disconnect automatically, particularly for GPRS?
 
Quote:

Originally Posted by Matan (Post 483281)
This script should disconnect from network (wlan or GPRS/UMTS) after 5 to 10 minutes of no received packets:

Code:

#!/bin/sh
a=`ifconfig phonet0 | grep RX.p | cut -d: -f2`
c=`ifconfig wlan0 | grep RX.p | cut -d: -f2`
b=$a
d=$c

while true ; do
        sleep 300
        a=`ifconfig phonet0 | grep RX.p | cut -d: -f2`
        c=`ifconfig wlan0 | grep RX.p | cut -d: -f2`
        if [ "$a" == "$b" -a "$c" == "$d" ] ; then
                dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
        fi
        b=$a
        d=$c
done


Thanks Matan for writing this script. To my surprise I can even vaguely follow it even though I consider myself a complete n00b when it comes to Linux. It must be all that fiddling with my Linux DD-WRT router installation to get a FON hotspot working that's given me a tentative grounding there!

That said, I have no idea where one would put this to be executed... on the router I have a nice simple web interface (although I've used the busybox telnet access too) for Cron Jobs and startup scripts etc. Could you help me and others out with how to install this script and also exactly which variables to change to alter settings...

As far as I can tell the "sleep 300" gives the 5 minute interval... where does the 10 minute upper range come into things, or is that just assuming two loops of 5 minutes each and data occurring between minute 1-5?

You're grep-ing RX.p - I assume this is received packets. Could you similarly do TX.p for transmitted to add to this script... in fact, is there somewhere you could point me like a wiki on this - I'd be interested to know more about the output from ifconfig and what you can do with it.

Thanks for your help :D

stopgap 2010-01-20 17:56

Re: Connect to Internet on demand & disconnect automatically, particularly for GPRS?
 
OK, I've actually gone into this on my router now and having seen the output from ifconfig, and looked at a few guides on the web, I think I now understand the basics of grep, cut and how that's all being done. I assume the output from ifconfig is always rigidly formatted enough to rely on that then?

I'm still not sure how to get this running on the N900 though, I have not installed the thing to allow sudo gainroot yet... I'm guessing that's necessary as a first step. Where from there?

Matan 2010-01-20 18:26

Re: Connect to Internet on demand & disconnect automatically, particularly for GPRS?
 
You create a file (say /usr/local/bin/scriptname) with this content, make sure it is executable (with a command like)

chmod a+x /usr/local/bin/scriptname

First, you should run it to see if it does what you want.

If you are sure you want it to start at boot time, the easiest way is probably to create a file /etc/event.d/autodisconnect, containing:
Code:

description "Run a script to disconnect idle networks"

start on started icd2

console none

script
        /usr/local/bin/scriptname
end script

About the script itself:
It can be up to 10 minutes, if last transfer happens a few seconds after the sleep starts, because the next check will see this transfer.

I believe using received makes more sense, since sometime the network appears up, but the other side is not there. In that case applications might continually send data, but nothing will be received.

I don't know of a wiki explaining all this, but you seem to be on the right track for understanding. I can think of no better way to do it than looking at simple scripts, and playing with them. If you don't have a Linux desktop, search for "manual page" of each command you need to learn.

stopgap 2010-01-21 03:04

Re: Connect to Internet on demand & disconnect automatically, particularly for GPRS?
 
Ok, so I've gotten quite far acutally. I have tailored the script a little and after testing that it worked, have now got it installed as a startup, as per your instructions above.

Should I wish to terminate this script - what would I need to do? I have HTOP installed and was poking around with that. I'm also aware of kill and ps now, but don't know what it is I'm supposed to be killing. Should the process be listed in there with a PID?

Thanks again for your help here, you've really opened up the gateway here re: linux scripting. I never knew where to start and this has been a brilliant introduction. Cheers :D

** EDIT
Ok, so it didn't run. Did I need to CHMOD the file which ran the script file in the same way too? That's the only thing that I didn't do...

woodyear99 2010-01-21 03:39

Re: Connect to Internet on demand & disconnect automatically, particularly for GPRS?
 
Let us know if your battery life has improved with everyday usage after using the script.

Matan 2010-01-21 19:27

Re: Connect to Internet on demand & disconnect automatically, particularly for GPRS?
 
Do you mean that the script runs when you run it manually, but does not start automatically? I am not sure about the operation of the upstart system. Perhaps you need to add an ampersand after the call to the script, so the line should be:
/usr/local/bin/scriptname &
Also /usr/local/bin/scriptname needs to be executable, not the file in /etc/event.d

colnago 2010-01-21 19:36

Re: Allow widgets/apps to automatically connect and then automatically disconnect internet connection. Possible?
 
Quote:

Originally Posted by woodyear99 (Post 457191)
I do not want to manually connect to the internet, I want it to automatically connect when widgets/apps request data at their intervals, once data transfers have been done I want it to disconnect the gprs connection. That would improve battery life since I noticed that just leaving the gprs connection running all day drains the battery faster even when not in use.

FWIW, this was a setting in the web browser (pocket IE) for my Motorola Q. One could set the length of "inactivity" before disconnecting. I had two different "3G" icons...one for "voice", the other "data", which confirmed connection state. If the "data" session was disconnected, and the icon not visible, if I open the browser, or checked email, the icon would appear, and disapear again, after the preconfigured inactivity period.

stopgap 2010-01-21 22:14

Re: Connect to Internet on demand & disconnect automatically, particularly for GPRS?
 
Yes... the script runs fine manually. I can't get upstart to start it - it just doesn't work. Is there some way I could get my script to set a variable or something to show it is running? I tried using export to set a global variable but it seems to be limited to the shell in which the script is running... unless I misunderstanding (this is only my second day writing shell scripts so it could well be that! ;)

How would I go about piping the time to a text file for example, or is there a way to set a variable that I could check this way?

Thanks again for your help :D

Matan 2010-01-21 22:17

Re: Connect to Internet on demand & disconnect automatically, particularly for GPRS?
 
Use something like

date >> /tmp/a.log

snookh 2010-01-22 10:14

Re: Connect to Internet on demand & disconnect automatically, particularly for GPRS?
 
This is an interesting idea, I hate to forgetting turning wifi off before going to bed and find my phone dead in the morning.

Installed script and it works fairly good for 3G.

Seems like wlan keeps sending packets although the device is idle.

A more accurate way to turn connections off would be to check for user inactivity but I have no idea how to check that via a shell script.

stopgap 2010-01-22 17:15

Re: Connect to Internet on demand & disconnect automatically, particularly for GPRS?
 
Quote:

Originally Posted by snookh (Post 488346)
This is an interesting idea, I hate to forgetting turning wifi off before going to bed and find my phone dead in the morning.

Installed script and it works fairly good for 3G.

Seems like wlan keeps sending packets although the device is idle.

A more accurate way to turn connections off would be to check for user inactivity but I have no idea how to check that via a shell script.

You got it to install... may I ask what exactly you did? I'm just not getting it to work... I've followed the instructions above and I just can't seem to get it to auto start when the phone boots.

As it stands I have an executable script which disconnects properly and logs startup and disconnections to a text file. It executes manually without error but I just cannot autostart it.

Also, does anyone know if there's a way to send a notification message from a script? I'm talking about the notifications which confirm an SMS delivery or a website's security or "code accepted" when you unlock - the pop up ones which fade & slide away automatically.

Thanks again for all the help!

qwerty12 2010-01-22 17:21

Re: Connect to Internet on demand & disconnect automatically, particularly for GPRS?
 
Quote:

Originally Posted by stopgap (Post 489018)
Also, does anyone know if there's a way to send a notification message from a script? I'm talking about the notifications which confirm an SMS delivery or a website's security or "code accepted" when you unlock - the pop up ones which fade & slide away automatically.

Code:

run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Message goes here"


All times are GMT. The time now is 13:11.

vBulletin® Version 3.8.8