Thursday, July 12, 2018

wi fi - How to turn-off WiFi when there's no Internet available on the connection?


I have a wifi hotspot that is always on but sometimes internet isn't available within the connection; in such a situations, the phone is connected as expected to the wifi hotspot but because there's no internet, apps can't check for updates(messages) so I wont be notified of incoming messages from IM apps unless I manually turn off wifi and use mobile data for internet connectivity(2g or 3g for example)


Is there any way to automatically check for internet availability (by pinging a website maybe) and if there's no internet available within the connected wifi network, turn the wifi off? (so that the phone can use mobile data for internet connectivity)



Answer



should be capable of that. It can execute HTTP_GET commands, and it can also deal with data connections; but for the latter, depending on the Android version you're running on your device, you might need root access to toggle data connection.



Tasker uses (combinations of) "conditions" (also called "context") to trigger "tasks" – which both together is called a "profile". So you would need a profile for that. Let's go step-by-step:


Your condition will be a time-based one, as you want to check connectivity periodically. Chose wisely here: checking too often might become a battery-drain – checking to rarely makes the whole thing useless. Play starting with 1 minute, and maybe go down to 30s if that's not enough.


The task then is a conditional one, which could be described as "switch off WiFi if I cannot reach the internet". So let's put that together:



  • Condition:

    • Time.
      In the fields, define the time frame this should be active in, and the "repeat" interval.

    • WiFi connected.
      I recommend adding that to safe some juice: If you're already on mobile data with WiFi turned off, there's no need to turn WiFi off – right? Alternatively, you could also use %WIFI ~ on – but that could give you a headache when you just switch it on and, failing to retrieve the URL, Tasker switches it off before it connects ;)




  • Task:

    • HTTP Get

    • WiFi (off) IF %HTTPR ~ -1




%HTTPR is a Tasker variable where the response code is stored into. According to the Tasker UserGuide, A response code of -1 indicates a problem making the request. This problem should be a timeout or "network unreachable" error (as a "not found" should be a "404" code), but you might need to play with this.



The above doesn't cover an "automatic return", so you had to enable WiFi manually (though that could be automated by a second "profile", periodically checking if things changed).


No comments:

Post a Comment

samsung galaxy s 2 - Cannot restore Kies backup after firmware upgrade

I backed up my Samsung Galaxy S2 on Kies before updating to Ice Cream Sandwich. After the upgrade I tried to restore, but the restore fails ...