CHECK FOR VERSION UPDATES IN THIS MONITORED XDA THREAD
I looked at my data connections and their battery usage when my scheduled once hourly sync of widgets, emails, facebook, twitter, rss etc etc took place. Without extensive testing, it became clear that these synchronisations became misaligned from the hourly slot due to data quantity, connection time/errors etc etc. Over time, it is therefore theoretically possible to have 10 applications/widgets/processes causing a data sync separately every six minutes (60 mins/10) and although some might say that the total data volume may be the same overall, the act of using the data connection so many more times tells me it will use more battery life.
Even if you don’t agree, the following Tasker profiles are to completely manage your wireless and data connectivity and prevent syncing of unwanted applications at misaligned times.
My phone starts its day set to 2g networks only, data connection off, wireless off, screen brightness set so low I need there to be solar eclipse for me to see it and all system volumes set to only alert nearby dogs that I have a text message – all naturally for maximum battery preservation. Depending on the day, my location, calendar entries etc Tasker selects a relevant profile for me to use.
For the benefit of the profiles below, I am going to assume your phone starts in full battery saving mode and go from there. Once you’re up to speed with the flow of the profiles, you can adjust them accordingly to suit your usage.
Profiles are set up assuming you'd prefer a wireless connection over mobile data.
Wireless states to consider:
On and connected to a preferred network
On and connected to an open network
On but not connected to a network
On and recently disconnected from a network
Import all the profiles (un-tick them) and tasks and with the relevant profile and tasks open (it will make a whole lot more sense then), follow the guide below.
Before we can look at the syncing profile itself, we need to set up some variables for the above first. For battery preservation, I couldn’t have an individual profile for each of the above, as many of them would be active at the same time and constantly on - After a lot of head scratching (and I mean a lot) I came up with the profile WIFI-OnCon let’s have a look at it:
We start with the state of ‘Wifi Connected’. This state means wifi is connected to a network (rather than just ‘on’). The task WifiOnConVar firstly runs a separate task WIFIPREFCON.
WIFIPREFCON writes a text file containing the standard wifi info variable %WIFII (you can take a look at the output file for your information). The next step is to extract just the SSID from the information so Tasker can set this as a variable %WIFIPREF (short for a wifi preferred network). The task ends with speech for you to test the variable has been set correctly (make sure you are connected to a network at the time). Note at this point that the variable %WIFIPREF remains populated. It will continue to remain populated even when the connection is eventually disconnected – we will need to deal with that later.
Next, WifiOnConVar sets a variable %WIFIOC (standing for wifi on and connected) to a value of 2. It then sets a variable of %WIFIHOME to the value 2 only IF the name matches that of your home wireless SSID. You can set and add as many of these variables in as you like e.g. %WIFIWORK, %WIFIGIRLFRIENDHOUSE, %WIFISCHOOL with the IF statement for their respective SSID’s. Setting up these variables is very useful to let Tasker determine your location for use in other profiles, without the need of running GPS or cell tower location profiles.
At the moment, Tasker knows wifi is on and connected (%WIFIOC set to value 2) and you are at home (%WIFIHOME set to your home SSID) (assuming you are testing this at home). A speech task confirms the variables are set.
The next state to consider is when wifi is no longer BOTH on AND connected. We do this in the exit task – the exit task starting when the state of on and connected is no longer true. Firstly it checks if wifi is still on, if it is (goto action 7), it sets the variable %WIFIOC to a value of 3 (another profile reads this shortly) and then clears the name of the preferred network in %WIFIPREF as of course, that cannot be connected anymore…
If the wifi is off, it sets the variable %WIFIHOME to the value 1 and if you have added multiple preferred network variables (%WIFIWORK etc), you should insert that it sets these to a value of 1 too. A speech action confirms the values for your testing purposes (remember, if you delete the speech when you are happy it is working properly, you’ll need to change the Goto Action number accordingly!), the variable %WIFIPREF is cleared as of course you cannot be connected to a preferred network anymore and the task STOPs.
Finally, to complete the wifi control, we need to deal with the wireless still being on, but out of range of a preferred network (that you were connected to). This is definitely a chance to save some battery life, as we’ve all left wifi on by accident when we are not going to be using it. Above, we set the variable of wifi on and connected (%WIFIOC) to a value of 3 when the state became ON but NOT connected. The profile of WIFI-AutoDiscon is set up to come to life when %WIFIOC is set to a value of 3. It activates the task to start a one minute countdown before checking on the wifi state again. This one minute wait allows time where you may have been in a black spot in your office or home and experienced a short disconnection. At the end of the minute, it checks that the value of %WIFIOC has not been changed back to 2 (it has reconnected to a preferred network) and then switches off wifi with your battery giving you a high-5.
That concludes the wireless management. The only missing eventualities are:
On and connected to an open network. (I have little use for this, but can’t sort something out if the demand is high enough).
On and not connected to a network. Not having a profile for this may surprise you, but in actually fact, how often do you turn wireless on when you are not around a preferred network and just leave it? The only reason you would surely do this, is if you were scanning for open networks, in which case a battery saving profile is pretty irrelevant to the scenario. Remember, the state of on and not connected to a network when you were previously connected IS covered, the %WIFIOC variable 3 and the WIFI-AutoDiscon profile monitors this.
If not, set up a new profile with the state of wifi connected and click ‘invert’ – but this of course will be active when you’re not even using wifi at all…
Taking control of your data syncing
The profile AutoSync is of course time activated, as you would set up your normal ‘between hours’ for email synchronisation. The repeat value sets how often you would like to sync your emails, widgets, applications, weather updates etc etc, by simply restricting their access to an active data connection in-between-times.
The task of AutoSync itself, firstly checks your battery is above a chosen threshold (you decide) to perform the action and that it’s not the weekend (if you want). Again, once you get to grips with the task flow, you can add in separate entries for individual applications, actions etc based on an individual setting – not syncing your work email on the weekend for example.
Action 4 sets a new variable of %WIFIORS. This stands for the ‘original state of wifi’ when the task began and populates using the previously created %WIFIOC variable. The purpose of this is to make sure that once the task has finished it does not turn off wifi if you were in the middle of using it – it will return wifi to the state it was when the task started – clever hey?
The task continues by turning on wifi (if it is already on nothing will change) and waiting to see if it connects to a preferred network by checking the value of the variable %WIFIOC. If a wifi connection is established, it skips to turning on automatic syncing (settings/accounts and sync to view what will sync), if it isn’t, it turns wifi off and uses your phone’s data connection until either eventuality ends up at action 16 where wifi is requested to switch off IF it was off when the task began using the value of %WIFIORS (clever hey).
Finally, the task STOPS if %WIFIORS tells tasker that wifi was on originally or it continues on to switch to 2g only and kill the mobile data connection (these wouldn’t have been activated if wifi had connected or already been on).
So there you have it… Full wifi control and full sync management, with not a single byte of data or rouge connection in sight… You are free to switch off your wifi, data connection, uncheck auto-sync (settings/accounts and sync) and go to 2g only. Tick the profile boxes, hit apply and it’s job done.
Don't forget to set all of your applications and widgets etc that will be syncing to just below the AutoSync repeat time!
Bdanders for wifi variable inspiration