How to Make the WiFi(On) Action Delay Until Connected?

525 views
Skip to first unread message

Sharp E

unread,
Dec 8, 2013, 12:05:09 PM12/8/13
to tas...@googlegroups.com
Hi
 
 
I have a small task that contains an HTTP GET action,
and I wanted to improve it by making the task also turn WiFi On.
 
I added a Net\WiFi action, set it to On,
and now the only problem, is that when WiFi is set to On, it takes several seconds until it's actually connected.
But my Tasker script continues right after the WiFi(On), and send the HTTP GET, even tho there's no WiFi connected yet,
and so I get an error.
 
 
Can I offer to make the WiFi action be a Blocking one,
so the operation will complete only after the requested WiFi state has actually happened?
 
 
And in the meanwhile, what can be a workaround for me?
Just putting a fixed delay, will not always be good, because sometimes it takes 2 seconds to connect to the wifi, and sometimes even 8 seconds..
So I need a "smart" way that will actually wait for the WiFi state to change to the desired one, and only then complete the waiting..
 
 
Thank you for the help

Matt R

unread,
Dec 8, 2013, 3:52:31 PM12/8/13
to tas...@googlegroups.com
Make a named WiFi Connected profile and then add a wait until action that waits until %PACTIVE matches *,TheNamedWiFiConnectedProfile,*

Matt

Sharp E

unread,
Dec 9, 2013, 6:24:30 AM12/9/13
to tas...@googlegroups.com
Thank you Matt.
 
Maybe there's a way to create a workaround without creating another profile?
By only adding activities to the current Task..
 
 
And also;
Is there a chance the creator of Tasker will change the WiFi activity to include a built-in Wait, till the requested State has achieved?
 
 
Thank you

Matt R

unread,
Dec 9, 2013, 11:28:19 AM12/9/13
to tas...@googlegroups.com
Only other way I can think of would be to do repeated http get actions and checking the response code, but the other way is better. And I think you're misunderstanding the WiFi action. It only turns the
WiFi radio on and off. It has nothing to do with connecting to a WiFi network.

Matt

Sharp E

unread,
Dec 9, 2013, 12:42:56 PM12/9/13
to tas...@googlegroups.com
>And I think you're misunderstanding the WiFi action.
>It only turns the WiFi radio on and off. It has nothing to do with connecting to a WiFi network.
 
Allow me to sharpen what I understand then:
 

I have a home WiFi network, that I always use.
My WiFi on the phone is usually Off,
and only when needed, I turn it on, manually, via Power Toggles.
 
When I turn it on, it automatically knows what Network to connect to, and it has the password for it..
So I only need to turn it on, and within several seconds everything is working.
 
 
Now the "Wifi" Action, from what I saw, does that too..
It turns the Wifi On, or Off,
and as usual, it connects to the default(my home) network.
 
 
So did I understand it OK?
Am I using the right Action?
 
 
Thank you

Matt R

unread,
Dec 9, 2013, 6:39:02 PM12/9/13
to tas...@googlegroups.com
Yes, when the WiFi radio is on, it will automatically connect to known networks.  But all the WiFi action does it turn on or off the radio.  The radio may be on, but not connected to any known networks.  Thus, I don't think it makes a lot of sense to have the WiFi action block task execution just because you aren't connected to a network.

Matt

Sharp E

unread,
Dec 10, 2013, 2:03:23 AM12/10/13
to tas...@googlegroups.com
>Yes, when the WiFi radio is on, it will automatically connect to known networks.  But all the WiFi action does it turn on or off the radio.
That's exactly what I need.
 
I run this task only when I'm at home,
and when I'm at home, I have my home WiFi network,
so I need the WiFi on the phone to be turned On, and the phone will connect byitself to its default network.
 
 
So the waiting is needed, because it has what to wait for..
(I am not running this task when not at home, so it will not be waiting for nothing)
 
 
Maybe I can implement a "smart wait" somehow?
 
For example like this:
Action WiFi=On
Wait for WiFi=On
 
(or: Wait for WiFiNetwork=MyHomeWiFi-SSID-Name)
 
 
Is that possible?
 
That will do what I need,
and it will all be contained in one task..

Matt R

unread,
Dec 10, 2013, 3:09:55 AM12/10/13
to tas...@googlegroups.com
Wait for WiFi on won't do anything because like I said, it's on once it's turned on, regardless if it is connected to a network or not. But I did have another thought. You could match the text in the %WIFII variable (note the extra "I"). Check what it contains when connected vs not connected; I think if should be different.

Matt

Sharp E

unread,
Dec 10, 2013, 3:33:12 AM12/10/13
to tas...@googlegroups.com
Hi Matt
 
 
%WIFII is indeed a great idea!
 
I checked now and the results are:
 
 
When the WiFi is Off or On but Connecting,
this Variable's first line equals to ">>> SCAN <<<"
 
 
When the WiFi is On and Connected,
this Variable's first line equals to ">>> CONNECTION <<<"
 
 
So I can use the "Wait Until" action, together with the %WIFII variable,
to test what I need.
 
 
Now the only question is how to I take the First Line out of a string variable(%WIFII) that contains severel lines of text in it..
(again, this would be very easy for me in text based coding, but here not so easy)
 
 
Thank you

Sharp E

unread,
Dec 10, 2013, 8:20:53 AM12/10/13
to tas...@googlegroups.com
Small addition:
 
I am trying to do Variable Split on %WIFII, splitting by an [Enter] (LF) character,
but in the Variable Split operation, when I go to the Splitter field, it doesnt let me put [Enter] there..
Is there maybe a string code for [Enter] in Tasker, that I can put there?

Tasker fan

unread,
Dec 10, 2013, 10:01:10 AM12/10/13
to tas...@googlegroups.com
The way I implemented this was adding the following to the task:



1. WIFI set on

2. Wait 5 seconds 
               Until %WIFII ~ R 192.168.0.* (or what ever ip range your wifi will get.  This proves two things.  the task will wait 5 seconds and test if your wifi has got a IP address meaning now connected to your AP.  IF it has then great the next task can run if not it will wait a further 5 seconds and try test again)

Hope this helps you

Sharp E

unread,
Dec 10, 2013, 10:52:27 AM12/10/13
to tas...@googlegroups.com
Hi Tasker Fan
 
You gave me a great idea.
 
I imeplemented it now this way:
 
Wait Until (1 sec) %WIFII ~ >>> CONNECTION <<<
 
An it workded!
 
 
 
Now I am just curious what the "R" part in the condition you wrote means:
"%WIFII ~ R 192.168.0.*"
 
What does the "R" there do?

Matt R

unread,
Dec 10, 2013, 1:30:03 PM12/10/13
to tas...@googlegroups.com
The R means it's a regex match.

Are you sure your match doesn't have an * (asterisk) after ">>> CONNECTION <<<"? I would think it wouldn't match otherwise. Check pattern matching in the user guide.

Matt

Sharp E

unread,
Dec 10, 2013, 2:01:53 PM12/10/13
to tas...@googlegroups.com
>Are you sure your match doesn't have an * (asterisk) after ">>> CONNECTION <<<"?
 
Oops you're right.
I forgot to copy it here..
 
So again:
Wait Until (1 sec) %WIFII ~ >>> CONNECTION <<<*
(thanks for noting it, that way other people who find this post in the future will know how to do it)
 

Sharp E

unread,
Dec 10, 2013, 2:06:11 PM12/10/13
to tas...@googlegroups.com
BTW
 
When I think of it,
can I put a TimeOut to the Wait Until action?
 
That way if it's waiting for the WiFi to connect, and it doesn't, after something like 20 seconds,
then I want to abort waiting...
 
Is that possible somehow?

Rich D

unread,
Dec 10, 2013, 2:20:42 PM12/10/13
to Tasker Google Groups Post

You just need to build your own 'wait until'

1. Wait 1 sec
2. Varible add  %loop  +1
3. Goto 5   If %loop > 20
4. Goto 1   if %WIFII  Does not match   *Connected*
5. Do more stuff...

Sharp E

unread,
Dec 10, 2013, 2:23:30 PM12/10/13
to tas...@googlegroups.com
Nice :)
I will do it now, thank you

Tim

unread,
Dec 10, 2013, 6:56:04 PM12/10/13
to tas...@googlegroups.com
I think Tasker should have a "boolean" variable WIFI_CONNECTED, it's very handy in general.
Meanwhile, take a look at my thread "How to prevent quick toggling of "wifi connected" state?"
https://groups.google.com/d/msg/tasker/7zX4tY4pwfw/t6l2VNfFplQJ

I set WIFI_CONNECTED=1 only if the wifi connection stays connected for 1 min. (you can of course adjust the time).
You can then have a profile to do your HTTP GET that becomes active when WIFI_CONNECTED=1. This way your GET will most likely work.

I find having that extra profile that sets the WIFI_CONNECTED variable to be worth the effort to get it right as I can then make use of the variable in many other places.

Sharp E

unread,
Dec 11, 2013, 2:18:21 AM12/11/13
to tas...@googlegroups.com
>I think Tasker should have a "boolean" variable WIFI_CONNECTED, it's very handy in general.
Me too :)
 
It can even be more useful, if the variable will give the Connected Network's Name, when it is connected,
and "" when not connected.
 
That way we can use it both for knowing if actually connected or not, and to verify if it's the right network(e.g. our home wifi network).
 
 
 
>Meanwhile, take a look at my thread "How to prevent quick toggling of "wifi connected" state?"
Very nice however you don't mention there how you actually check if it's connected or not..
Do you use %WIFII (double I) or just %WIFI with some wait?
 
The %WIFII method that we used here, to match for the word ">>> CONNECTION <<<" is extremely accurate,
and what I like about it is that we do not wait any extra second beyond what's needed.
 
 
Also, I implemented this check as a sub-routine task,
that way I do not need another profile, I just call this sub-routine to turn the Wi-Fi on, and Wait for it to actually turn on.
 

Matt R

unread,
Dec 11, 2013, 4:19:06 AM12/11/13
to tas...@googlegroups.com
The %WIFII variable does contain the network name (and MAC address, signal strength, connection speed, and IP...at least on my phone).

Matt

Sharp E

unread,
Dec 11, 2013, 12:49:17 PM12/11/13
to tas...@googlegroups.com
>The %WIFII variable does contain the network name (and MAC address, signal strength, connection speed, and IP...at least on my phone).
Yes I know..
But taking it from there is much more difficult than if the Connect Network Name was in a dedicated variable..
So that's what the offer was about

Matt R

unread,
Dec 11, 2013, 1:40:38 PM12/11/13
to tas...@googlegroups.com
Not sure how it's more difficult.  Just use pattern matching.  E.g. If %WIFII ~ >>> CONNECTION <<<*YourNetworkName*

Matt
Reply all
Reply to author
Forward
0 new messages