How can I check Internet connectivity with Tasker?

10,114 views
Skip to first unread message

Frogbone

unread,
Oct 16, 2012, 10:30:50 AM10/16/12
to tas...@googlegroups.com
Pretty much a noob here and I am looking for some step by step instructions on how to accomplish this with Tasker:

Check if Wifi is ON
AND
Check there is Internet Connectivity (Ping a site?)

If there is Internet connectivity then do nothing

If there is NO internet connectivity then turn Wifi OFF

Check this every 10 minutes

Any help is greatly appreciated

Frogbone

unread,
Oct 16, 2012, 10:32:31 AM10/16/12
to tas...@googlegroups.com
Saw a Ping explanation in the FAQ but I don't know how to actually implement / configure that in Tasker :-/

Hussain

unread,
Oct 16, 2012, 10:40:18 AM10/16/12
to tas...@googlegroups.com
Use a plug in called Secure Settings

It allows you to run the ping command.

This is how I've set up a task to check if a PC in my house is switched on. You can play around with it to get the desired outcome:

PC On Test (47) 
A1: Variable Clear [ Name:%EXPING Pattern Matching:Off ] 
A2: Secure Settings [ Configuration:myping Package:com.intangibleobject.securesettings.plugin Name:Secure Settings ] 
A3: Wait Until [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ] If [ %EXPING Is Set ] 
A4: If [ %EXPING = 0 ] 
A5: Notify [ Title:PC Status Text:PC already ON. Icon: Number:0 Permanent:Off Priority:3 ] 
A6: Else 
A7: Perform Task [ Name:WoL Stop:Off Priority:5 Parameter 1 (%par1): Parameter 2 (%par2): Return Value Variable: ] 
A8: Stop [ With Error:Off Task: ] 
A9: End If

Frogbone

unread,
Oct 16, 2012, 10:49:35 AM10/16/12
to tas...@googlegroups.com
Thanks Hussain,

I did find the secure settings plug in but this seems a bit over my head. I hate to bother anyone but I probably need some step by step instructions as I have no idea where to start and how to do all this :(

Hussain

unread,
Oct 16, 2012, 11:59:10 AM10/16/12
to tas...@googlegroups.com
This is how I've configured Run Command in Secure Settings:

Matt R

unread,
Oct 16, 2012, 4:00:02 PM10/16/12
to tas...@googlegroups.com
The FAQ tells you how to do it without using a plugin.  For further explanation, create a profile with the WiFi On context (State -> Variable -> Variable Value -> Name: %WIFI, Op: Matches, Value: on).  Then make the first action HTTP Get on a known webpage like www.google.com (Net -> HTTP Get -> Server:Port: www.google.com, check "Continue Task After Error" at the bottom).  Then, do an If action (Task -> If -> %HTTPR in the left box and 200 in the right box).  Add whatever other actions you want to do if you DO have an internet connection, and end it with an End If action (Task -> End If).  Then you finish the task edit window (bottom left green checkmark), go back to your profile and long-press on the WiFi context and you can then add a second context.  Pick Time, uncheck To and From, and check Repeat and put your 10 minutes there.
 
Matt

Frogbone

unread,
Oct 17, 2012, 6:25:27 PM10/17/12
to tas...@googlegroups.com
Thanks for the directions Matt,

I don't have an option to check the "continue after error "

Pent

unread,
Oct 18, 2012, 2:15:05 AM10/18/12
to Tasker
You may need to disable Menu / Prefs / UI / Beginner Mode to see that.

Pent

UncleMike

unread,
Oct 19, 2012, 9:15:47 PM10/19/12
to tas...@googlegroups.com
Here's what I'm using for a task triggered using a shortcut on my home screen:

Connectivity Test (70)
A1: HTTP Get [ Server:Port:www.google.com Path: Attributes: Cookies: Timeout:10 Mime Type:text/* Output File: Continue Task After Error:On ] 
A2: If [ %HTTPR = 200 ]
A3: Flash [ Text:Connection OK Long:Off ] 
A4: Else 
A5: Flash [ Text:Connection Failed Long:Off ] 
A6: If [ %WIFII ~ *connection* ]
A7: Flash [ Text:Resetting Wifi Long:Off ] 
A8: WiFi [ Set:Toggle ] 
A9: Wait [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ] 
A10: WiFi [ Set:Toggle ] 
A11: Else 
A12: Flash [ Text:Resetting Mobile Data Long:Off ] 
A13: Mobile Data [ Set:Toggle ] 
A14: Wait [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ] 
A15: Mobile Data [ Set:Toggle ] 
A16: End If 
A17: End If 
A18: HTTP Get [ Server:Port:<nonexistent web site> Path: Attributes: Cookies: Timeout:10 Mime Type:text/plain Output File: Continue Task After Error:On ] 
A19: If [ %HTTPR = 200 ]
A20: WiFi [ Set:Off ] 
A21: Vibrate Pattern [ Pattern:0,70,300,70 ] 
A22: Flash [ Text:Wifi Blocked Long:Off ] 
A23: End If 

The first part (A1-A17) will test for availability of www.google.com, and toggle Wifi or Mobile Data as needed if it's not available.  The remainder checks for availability of an invalid web site which, if available, would indicate that some hot spot authentication or terms of service page is being substituted for the requested page - meaning you don't really have any connectivity beyond the local Wifi network (until you either login or accept the terms of service).

Frogbone

unread,
Oct 22, 2012, 2:25:27 PM10/22/12
to tas...@googlegroups.com
@Uncle Mike

I created this task and I am running this while having both Mobile Data and Wifi connectivity.

I get the "Connection Ok" then I get the "Wifi blocked" and then it turns off Wifi. 

I do however have good wifi internet connectivity.



On Tuesday, October 16, 2012 9:30:50 AM UTC-5, Frogbone wrote:

UncleMike

unread,
Oct 22, 2012, 8:44:25 PM10/22/12
to tas...@googlegroups.com
Did you substitute an invalid name in the check for blocked Internet?  I was using a page on my own site that I know won't ever exist, but I stripped it out before posting the task.

Frogbone

unread,
Oct 22, 2012, 9:27:47 PM10/22/12
to tas...@googlegroups.com
Yes, I did enter some gibberish .com to ,make sure the site doesn't exist


On Tuesday, October 16, 2012 9:30:50 AM UTC-5, Frogbone wrote:

UncleMike

unread,
Oct 23, 2012, 11:18:30 AM10/23/12
to tas...@googlegroups.com
That's a fairly simple test, so I'm not sure what could go wrong.  Perhaps you could double check to make sure that web address doesn't exist, and possibly flash the %HTTPR code after A18.  When my connection is good, %HTTPR = 404.

TomL

unread,
Oct 24, 2012, 11:23:16 AM10/24/12
to tas...@googlegroups.com
Some ISPs will avoid giving you a real 404 error and instead serve you a webpage with a "friendly 404" message.  Because you are getting a page, it'll look like a result 200 instead of 404.

Tom


On Monday, October 22, 2012 9:27:48 PM UTC-4, Frogbone wrote:

M@xF@ctor

unread,
Apr 9, 2014, 7:16:13 AM4/9/14
to tas...@googlegroups.com
Action : Run Shell
  Command : ping -c 1 -q -w 2 8.8.8.8
     Store Result in : %result

If %result doesn't match 0 you have no internet connectivity

Glauber Lima

unread,
Apr 9, 2014, 12:35:52 PM4/9/14
to tas...@googlegroups.com, wkn...@gmail.com
Here's mine:

1-) I'm using the special Google URL "http://clients3.google.com/generate_204" which returns an HTTP 204 status code wherever a connection is established. Tech details here: http://www.chromium.org/chromium-os/chromiumos-design-docs/network-portal-detection
2-) Then based on the result I set my %Connected variable to 1 (success, the http returned 204) or clear it.

It's working like a charm. Hope this helps.

Profile: Connectivity check
Restore: no
State: Wifi Connected [ SSID:* MAC:* IP:* ]
Enter:
A1: HTTP Get [ Server:Port:http://clients3.google.com/generate_204 Path: Attributes: Cookies: Timeout:5 Mime Type:text/html Output File: Trust Any Certificate:Off Continue Task After Error:On ] 
A2: If [ %HTTPR ~ 204 ]
A3: Variable Set [ Name:%Connected To:1 Do Maths:Off Append:Off ] 
A4: Else 
A5: Variable Clear [ Name:%Connected Pattern Matching:Off ] 
A6: End If 
Exit:
A1: Variable Clear [ Name:%Connected Pattern Matching:Off ]
Message has been deleted

Luis Castro Martín

unread,
Dec 8, 2014, 7:00:34 AM12/8/14
to tas...@googlegroups.com
You da real MVP. Http requests are eventually stored in cache and the no-cache option is not implemented yet. Only pings are truly reliable.
Message has been deleted

Charles Butcher

unread,
Dec 12, 2014, 1:23:16 PM12/12/14
to tas...@googlegroups.com
M@xF@ctor:
This is brilliant, thanks. I agree with Luis Castro Martín (below): ping just seems the right way, unless you need to check a specific HTTP response.

I wanted to get a "no connectivity" message when wifi is turned off, so I set the "Run Shell" action to ignore errors. 

ירון זיגי פרזי זיגי קוסם לימי הולדת ומבוגרים

unread,
Feb 28, 2015, 10:12:02 AM2/28/15
to tas...@googlegroups.com, wkn...@gmail.com
Hey guys, simple solution - upload a simple html file, just write the number "1" in notepad and save it as html. Upload it. In tasker, have a HTTP Get to that page URL. If %HTTPD = "1" we have internet, otherwise - nope.
Reply all
Reply to author
Forward
0 new messages