Active Topics

 


Reply
Thread Tools
Posts: 1,224 | Thanked: 1,763 times | Joined on Jul 2007
#41
See here: http://wiki.maemo.org/User:Jebba/DBU...d-notification

Replace $1 with your message.

But this is the type that does not go automatically.
Replace SystemNoteDialog with SystemNoteInfoprint and don't include the last uint32:0 string:'NAO OK!'
__________________
My repository

"N900 community support for the MeeGo-Harmattan" Is the new "Mer is Fremantle for N810".

No more Nokia devices for me.
 

The Following 2 Users Say Thank You to Matan For This Useful Post:
stopgap's Avatar
Posts: 139 | Thanked: 135 times | Joined on Jan 2010 @ Cambridgeshire, UK
#42
I've spent some time on this script and refined it a little:

*It now only does anything if there's an active connection.
*It logs startup and disconnections to a file in mydocs/tmp
*It notifies you onscreen when disconnecting
*It distinguishes between wifi/cellular connections

I still cannot get it to autostart though - I don't get what I'm doing wrong. I have an entry in /etc/event.d as suggested and have tried everything I can see - to no avail. Ideally it needs to start once the desktop is up and loaded properly... any ideas anyone?

Here's my script for anyone who wants it

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

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

#PREPARE INITIAL VARIABLES FOR TEMPORAL MONITORING OF NETWORK INTERFACES
getcell=`ifconfig phonet0 | grep RX.p | cut -d: -f2`
getwifi=`ifconfig wlan0 | grep RX.p | cut -d: -f2`
bakcell=$getcell
bakwifi=$getwifi

getcellup=`ifconfig | grep gprs0 | cut -d: -f0`
getwifiup=`ifconfig wlan0 | grep inet.addr | cut -d: -f2`

#LOG MONITOR STARTUP TO FILE & NOTIFY USER VIA POPUP
logentry "\nIdle Monitor Startup $(date)\nEVENTS:\n"
osnotify "Automatic internet disconnection monitor has started"

#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

        getcell=`ifconfig phonet0 | grep RX.p | cut -d: -f2`
        getwifi=`ifconfig wlan0 | grep RX.p | cut -d: -f2`
	getcellup=`ifconfig | grep gprs0 | cut -d: -f0`
	getwifiup=`ifconfig wlan0 | grep inet.addr | cut -d: -f1`

	if [ -n "$getcellup" -o -n "$getwifiup" ]; then
		#IF EITHER NETWORK INTERFACE HAS AN IP PROCEED WITH INACTIVITY TEST

        	if [ "$getcell" == "$bakcell" -a "$getwifi" == "$bakwifi" ]; then
			#IF NO PACKETS WERE RECEIVED SINCE LAST RECORDING THEN SHUTDOWN INTERFACES

                	dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
			
			if [ -n "$getcellup" ]; then
				osnotify "The 2G/3G internet connection has been closed due to inactivity"
				logentry " - 2G/3G DISCONNECTED @ $(date)"

			elif [ -n "$getwifiup" ]; then
				osnotify "The WI-FI internet connection has been closed due to inactivity"
				logentry " - WI-FI DISCONNECTED @ $(date)"

			else
				osnotify "The internet connection has been closed due to inactivity"
				logentry " - ????? DISCONNECTED @ $(date)"
			
			fi


        	fi

		bakcell=$getcell
		bakwifi=$getwifi

	fi

done

exit
 

The Following 3 Users Say Thank You to stopgap For This Useful Post:
Posts: 1,224 | Thanked: 1,763 times | Joined on Jul 2007
#43
Add an echo into some file to the event.d file, so you can know if the commands in this file run at startup.
__________________
My repository

"N900 community support for the MeeGo-Harmattan" Is the new "Mer is Fremantle for N810".

No more Nokia devices for me.
 

The Following User Says Thank You to Matan For This Useful Post:
Posts: 5 | Thanked: 0 times | Joined on Jan 2010
#44
appreciate your effort please let us know when your done
 
Posts: 69 | Thanked: 55 times | Joined on Nov 2009
#45
Originally Posted by stopgap View Post
I've spent some time on this script and refined it a little:

*It now only does anything if there's an active connection.
*It logs startup and disconnections to a file in mydocs/tmp
*It notifies you onscreen when disconnecting
*It distinguishes between wifi/cellular connections

I still cannot get it to autostart though - I don't get what I'm doing wrong. I have an entry in /etc/event.d as suggested and have tried everything I can see - to no avail. Ideally it needs to start once the desktop is up and loaded properly... any ideas anyone?

Here's my script for anyone who wants it

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

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

#PREPARE INITIAL VARIABLES FOR TEMPORAL MONITORING OF NETWORK INTERFACES
getcell=`ifconfig phonet0 | grep RX.p | cut -d: -f2`
getwifi=`ifconfig wlan0 | grep RX.p | cut -d: -f2`
bakcell=$getcell
bakwifi=$getwifi

getcellup=`ifconfig | grep gprs0 | cut -d: -f0`
getwifiup=`ifconfig wlan0 | grep inet.addr | cut -d: -f2`

#LOG MONITOR STARTUP TO FILE & NOTIFY USER VIA POPUP
logentry "\nIdle Monitor Startup $(date)\nEVENTS:\n"
osnotify "Automatic internet disconnection monitor has started"

#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

        getcell=`ifconfig phonet0 | grep RX.p | cut -d: -f2`
        getwifi=`ifconfig wlan0 | grep RX.p | cut -d: -f2`
	getcellup=`ifconfig | grep gprs0 | cut -d: -f0`
	getwifiup=`ifconfig wlan0 | grep inet.addr | cut -d: -f1`

	if [ -n "$getcellup" -o -n "$getwifiup" ]; then
		#IF EITHER NETWORK INTERFACE HAS AN IP PROCEED WITH INACTIVITY TEST

        	if [ "$getcell" == "$bakcell" -a "$getwifi" == "$bakwifi" ]; then
			#IF NO PACKETS WERE RECEIVED SINCE LAST RECORDING THEN SHUTDOWN INTERFACES

                	dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
			
			if [ -n "$getcellup" ]; then
				osnotify "The 2G/3G internet connection has been closed due to inactivity"
				logentry " - 2G/3G DISCONNECTED @ $(date)"

			elif [ -n "$getwifiup" ]; then
				osnotify "The WI-FI internet connection has been closed due to inactivity"
				logentry " - WI-FI DISCONNECTED @ $(date)"

			else
				osnotify "The internet connection has been closed due to inactivity"
				logentry " - ????? DISCONNECTED @ $(date)"
			
			fi


        	fi

		bakcell=$getcell
		bakwifi=$getwifi

	fi

done

exit
Maybe you need to run the script as a service (daemon) through upstart
or add the script to /etc/networks/if-pre-up.d/ or /etc/networks/if-up.d/
to start every time a network interface is upped.
 
stopgap's Avatar
Posts: 139 | Thanked: 135 times | Joined on Jan 2010 @ Cambridgeshire, UK
#46
Yeah, that'd be ideal to launch it when the network starts but I'm way out of my limited knowledge of linux here...

I took a look in if-up.d and saw there were some scripts in there. I tried to put my own in but it didn't seem to run. The others were named 00_something - maybe my test had a malformed naming for execution within that folder or perhaps I'm misunderstanding how that works... I can't find anything clear on this area on the web... What is there is linux specific - I'm not even sure if thats completely appropriate for all versions of linux, let alone maemo... I'm a Windows programmer so this is all rather unfamiliar to me to say the least!

Ideally I'd launch the monitor script with some handle, upon network up and then use the handle to terminate on network down (with the handle - if that's even how linux works?)

Any idea how, or does anyone know of any useful guides on this sort of stuff?

I sort of got it to auto-run on startup but something is not right and the script seems to freeze up or something, it stops working anyhow. I can see it running in HTOP still just doesn't seem to do anything.

Incidentally does anyone know how to use HTOP?... its functions use Fx keys and I'm not sure how you do that in a maemo console...
 
Posts: 5 | Thanked: 3 times | Joined on Jan 2010 @ Isle of Man
#47
You would probably do better to use transmitted rather than received packets because most networks will have some general chatter on them even if they are only occasional broadcast messages and those packet could keep your network connection up even if you aren't responding to them.

Perhaps the best solution is actually to check if both RX and TX have changed?
 
stopgap's Avatar
Posts: 139 | Thanked: 135 times | Joined on Jan 2010 @ Cambridgeshire, UK
#48
Originally Posted by farnwomt View Post
You would probably do better to use transmitted rather than received packets because most networks will have some general chatter on them even if they are only occasional broadcast messages and those packet could keep your network connection up even if you aren't responding to them.

Perhaps the best solution is actually to check if both RX and TX have changed?
Yeah, I am doing that now... just refining the script to work on connection up and down, as well as disconnecting when network is idle. A bit of a steep learning curve all this, but I'm quite enjoying it. I think I've worked out how to make it (optionally) disconnect if battery hits a certain level too.

I'll post it when I have a proper working script here for people to test
 

The Following User Says Thank You to stopgap For This Useful Post:
Posts: 5 | Thanked: 3 times | Joined on Jan 2010 @ Isle of Man
#49
Just a couple of other points

1) phonet is interesting, but I am not entirely sure if it is the best device to check for activity. In my experience it handles packets even when there is no connection in place. It may be that it is better to look at something like gprs0 (or whatever device is created when you are connected) as that will definitely relate to genuine traffic.

2) Using ifconfig is ok, but it is probably slightly more demanding than it needs to be. You can get the same result from the file /proc/net/dev, using something like

c=`grep wlan0 /proc/net/dev | awk '{ print $10 }'`

One of the joys of this option is that if you want to look for something like gprs devices it doesn't matter if they don't exist as you won't get an error.

3) The original script attempted to disconnect even if there was no current connection. I would consequently suggest that you could find out how you are currently connected by doing this ...

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

This would set the variable connection to be 'wlan0' or 'gprs0' or whatever you are using, or 'Iface' if you aren't connected. You could use this information to only look at the live connection for new packets. I am assuming in writing this that only one interface will be active at a time, so if you use something like 'openvpn' you would have an issue. Having said that products like openvpn tend to send regular packets anyway so you wouldn't be able to close your connection very easily.

Hopefully this information will be of help?

Last edited by farnwomt; 2010-01-28 at 16:40.
 

The Following 2 Users Say Thank You to farnwomt For This Useful Post:
Posts: 17 | Thanked: 0 times | Joined on Dec 2009 @ Honolulou
#50
Every phone I used somewhat disconnected from the web/wi-fi when I close the browser, email, or whatever app that was using internet connection but the N900 doesn't. For example, if I used 3g to browse then close the browser it takes hours to disconnect from tmobile 3g by itself. If I used wi-fi to browse or check emails, it doesn't disconnect when I'm done with email app. 3G disconnects after a while I guess but wi-fi never disconnects and drains the battery. Anybody else notice this?
 
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


 
Forum Jump


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