How can Tasker Monitor the WIFI download traffic

1,819 views
Skip to first unread message

beshoo

unread,
Feb 25, 2012, 8:37:59 PM2/25/12
to Tasker
Hi all
i know how to turn WIFI of , but what if there is a download in
progress , i want to wait till download is end then turn the WIFI
off !.

Pent

unread,
Feb 26, 2012, 3:59:54 AM2/26/12
to Tasker
> i know how to turn WIFI of , but what if there is a download in
> progress , i want to wait till download is end then turn the WIFI
> off !.

Sorry, not possible yet (unless you are technical and can do stuff
with shell scripts)

Pent

Сергей Коротков

unread,
Feb 26, 2012, 6:22:41 AM2/26/12
to tas...@googlegroups.com

No, this is possible with standard tasker actions. Bellow is the task to collect current value of data transferred and sent on all interfaces. It can be modified to check data for wifi only. However if wifi is on all data should go over it so measure of total traffic is enough. I use this function to decide if its ok to turn data connection off. I make one measurement and then another in 30sec. If differnce is less than some treshold it is safe to switch off wifi.
func-getTotalB (15)
Run Both Together, Stay Awake
A1: Read Paragraph [ File:/proc/self/net/dev Para:1 To Var:%tet ]
A2: Variable Set [ Name:%newline To:
Do Maths:Off Append:Off ]
A3: Variable Split [ Name:%tet Splitter:%newline Delete Base:Off ]
A4: For [ Variable:%line Items:%tet(3:) ]
A5: Variable Split [ Name:%line Splitter: Delete Base:Off ]
A6: Variable Add [ Name:%rxb Value:%line2 Wrap Around:0 ]
A7: Variable Add [ Name:%txb Value:%line10 Wrap Around:0 ]
A8: End For
A9: Variable Set [ Name:%totalb To:%rxb+%txb Do Maths:On Append:Off ]
A10: Return [ Value:%totalb Stop:On ]

26.02.2012 13:00 пользователь "Pent" <sup...@apps.dinglisch.net> написал:

TW

unread,
Feb 26, 2012, 6:35:20 AM2/26/12
to tas...@googlegroups.com
this is a nice trick, thanks!
gonna have a play with it :)

Сергей Коротков

unread,
Feb 26, 2012, 7:00:25 AM2/26/12
to tas...@googlegroups.com

There is the trick with %newline variable which is not visible. In set variable dialog you have to press enter key.

26.02.2012 15:35 пользователь "TW" <the...@gmail.com> написал:

Pent

unread,
Feb 26, 2012, 7:34:17 AM2/26/12
to Tasker
> No, this is possible with standard tasker actions.

I stand happily corrected :-)

Pent

TW

unread,
Feb 26, 2012, 7:35:39 AM2/26/12
to tas...@googlegroups.com
thanks for the added info
this is actually something I started using about a week ago and with the same varname :)


On Sunday, February 26, 2012 1:00:25 PM UTC+1, Sergy Korotkov wrote:

There is the trick with %newline variable which is not visible. In set variable dialog you have to press enter key.

26.02.2012 15:35 пользователь "TW" написал:

beshoo

unread,
Feb 26, 2012, 7:56:36 PM2/26/12
to Tasker
thank you , but since i am new on tasker , how can i install your
script ! it is not like normal xml profile .. how can i import it !

On Feb 26, 3:22 am, Сергей Коротков <sergey...@gmail.com> wrote:
> No, this is possible with standard tasker actions. Bellow is the task to
> collect current value of data transferred and sent on all interfaces. It
> can be modified to check data for wifi only. However if wifi is on all data
> should go over it so measure of total traffic is enough. I use this
> function to decide if its ok to turn data connection off. I make one
> measurement and then another in 30sec. If differnce is less than some
> treshold it is safe to switch off wifi.
> func-getTotalB (15)
> Run Both Together, Stay Awake
> A1: Read Paragraph [ File:/proc/self/net/dev Para:1 To Var:%tet ]
> A2: Variable Set [ Name:%newline To:
> Do Maths:Off Append:Off ]
> A3: Variable Split [ Name:%tet Splitter:%newline Delete Base:Off ]
> A4: For [ Variable:%line Items:%tet(3:) ]
> A5: Variable Split [ Name:%line Splitter: Delete Base:Off ]
> A6: Variable Add [ Name:%rxb Value:%line2 Wrap Around:0 ]
> A7: Variable Add [ Name:%txb Value:%line10 Wrap Around:0 ]
> A8: End For
> A9: Variable Set [ Name:%totalb To:%rxb+%txb Do Maths:On Append:Off ]
> A10: Return [ Value:%totalb Stop:On ]
>  26.02.2012 13:00 пользователь "Pent" <supp...@apps.dinglisch.net> написал:

René Jensen

unread,
Mar 1, 2012, 11:12:22 AM3/1/12
to tas...@googlegroups.com
Hi

Sorry for stealing your thread.

I made a different approach, but more of less the same result, but perhaps a bit easier to implement.

I made a "Run Shell" task with this inside: grep -i "eth0" /proc/net/dev | awk '{print ($2+$10)}' > /mnt/sdcard/tmp/eth0data

now "sdcard/tmp/eth0data" contains the total send and received amount for eth0

make a readline task to get it to a variable.

I think this version is a bit easier to implement for others, but it only monitors one interface. replace eth0 with the interface to monitor.

The grep command only "outputs" the lines which contains/starts with eth0, awk then takes the 2nd and the 10th parameter and adds them.

My inspiration came from here
http://tasker.wikidot.com/using-linux-shell-with-tasker-for-a-technical-battery-widget
 

Best regards

René
Message has been deleted

beshoo

unread,
Mar 2, 2012, 9:53:14 PM3/2/12
to Tasker
still want to know how can i install this profile

On Feb 26, 3:22 am, Сергей Коротков <sergey...@gmail.com> wrote:
> No, this is possible with standard tasker actions. Bellow is the task to
> collect current value of data transferred and sent on all interfaces. It
> can be modified to check data for wifi only. However if wifi is on all data
> should go over it so measure of total traffic is enough. I use this
> function to decide if its ok to turn data connection off. I make one
> measurement and then another in 30sec. If differnce is less than some
> treshold it is safe to switch off wifi.
> func-getTotalB (15)
> Run Both Together, Stay Awake
> A1: Read Paragraph [ File:/proc/self/net/dev Para:1 To Var:%tet ]
> A2: Variable Set [ Name:%newline To:
> Do Maths:Off Append:Off ]
> A3: Variable Split [ Name:%tet Splitter:%newline Delete Base:Off ]
> A4: For [ Variable:%line Items:%tet(3:) ]
> A5: Variable Split [ Name:%line Splitter: Delete Base:Off ]
> A6: Variable Add [ Name:%rxb Value:%line2 Wrap Around:0 ]
> A7: Variable Add [ Name:%txb Value:%line10 Wrap Around:0 ]
> A8: End For
> A9: Variable Set [ Name:%totalb To:%rxb+%txb Do Maths:On Append:Off ]
> A10: Return [ Value:%totalb Stop:On ]
>  26.02.2012 13:00 пользователь "Pent" <supp...@apps.dinglisch.net> написал:
Message has been deleted

Tom

unread,
May 29, 2014, 2:22:44 AM5/29/14
to tas...@googlegroups.com
Ok, I've built this task.  Can anyone give me a pointer on implementing it?

Krzysztof Cebulski

unread,
Oct 7, 2015, 4:00:55 PM10/7/15
to Tasker
Another way created by me in javascript:

1) Set Variable "TotalUsage" to -1
2) Code -> JavaScripLet    (Paste code below) and that's it

var data = [];
var re = /wlan0:\s+(\d+)\s+(\d+\s+){7}(\d+)/;
var sourcestring = readFile('/proc/self/net/dev');
var matches = re.exec(sourcestring); 

data.push(matches[1], matches[3])
wait(1000);

sourcestring = readFile('/proc/self/net/dev');
matches = re.exec(sourcestring); 
data.push(matches[1], matches[3]);

var download = parseInt(data[2]) - parseInt(data[0]);
var upload = parseInt(data[3]) - parseInt(data[1]);
var total = download + upload;

flash('Usage:\ndownload=' + download + ' \nupload=' + upload + '\ntotal=' + total);

//setGlobal('Download', download);
//setGlobal('Upload', upload);
setGlobal('TotalUsage', total);



Checked on my Galaxy S5

Marta Hintz

unread,
Oct 9, 2015, 6:30:02 PM10/9/15
to Tasker
Super cool, thanks

きぼう Hope

unread,
Oct 10, 2015, 12:25:13 AM10/10/15
to Tasker
I'm a noob!
Can you please show me how to do this in tasker? I don't even know when to start.

1. I created a task, then all under the same task did the following actions:

2. Added variable: %TotalUsage to task
3. Went to code -->JavaScriplet and pasted the information you provided
4. Went to Task, under preform task choose (disable Wi-Fi) *if %TotalUsage ~1
------------------------------------------------------------------------------------------------------------------
Naturally, because I have no I idea what I'm doing, it did not work. Can anyone help?
Thanks.
Reply all
Reply to author
Forward
0 new messages