Best way to favor a particular wifi connection?

237 views
Skip to first unread message

technogeezer

unread,
Apr 28, 2015, 7:15:14 AM4/28/15
to tas...@googlegroups.com
Greetings,

I use my phone for home automation.  I also like to walk around my neighborhood.  I use tasker to open and close my garage door when I leave and return.

Along my route I connect and disconnect from many routers in the area.  When I get near home, depending on which direction I'm coming from, I am connected to one of my neighbor's routers.  I must manually disable and re-enable the wifi on my phone so that it connects to my wifi.

How can I automatically favor my own wifi over my neighbor's?

I'm thinking about using java getScanResults() but searching through all of the possible entries seems CPU intense, and along with that, how often should I scan?  What is the order of the list returned?  It appears to be by signal strength but the docs don't mention it.

Any help appreciated.

Thanks

Robert Ryan

unread,
Apr 28, 2015, 10:02:41 AM4/28/15
to tas...@googlegroups.com

Maybe you could use a WIFI Near profile with your SSID. As soon as you get near enough to your AP you can toggle your WIFI. That should duplicate what you do manually.

technogeezer

unread,
Apr 28, 2015, 10:44:34 AM4/28/15
to tas...@googlegroups.com
Thanks!  I hadn't thought of that.  (Tasker is soooo deep!)

I'll try your suggestion and report back.

Sean Williams

unread,
Apr 28, 2015, 10:52:31 AM4/28/15
to tas...@googlegroups.com
Along my route I connect and disconnect from many routers in the area. When I get near home, depending on which direction I'm coming from, I am connected to one of my neighbor's routers. I must manually disable and re-enable the wifi on my phone so that it connects to my wifi.


So in this case does your own wifi network overlap your neighbours, are they always both in range at the same time?

Marta Hintz

unread,
Apr 28, 2015, 11:57:39 AM4/28/15
to tas...@googlegroups.com
I would imagine if you go into your own phone WiFi seeing, check forget neighbors WiFi and then check in settings that you don't automatically connect to all wifi, you won't need taker to do this. At least on my last few phones it worked that way (all Samsungs)

technogeezer

unread,
Apr 29, 2015, 11:39:17 AM4/29/15
to tas...@googlegroups.com
There are always many routers in range at the same time in my neighborhood.

I tried the WIFI near trigger with disconnect and re-connect actions in the associated task.  This seems to speed up the connection to my wifi but it still takes a while.

Previously, my phone would ultimately connect to my home wifi once it got a high enough signal level (I think).  That means I'd have to be right at my front door and only after a 'scan' was completed.

I would like for the phone to connect as soon as it's in range of my home wifi, regardless of other routers in range.  When out of range of my home wifi, I want other routers to connect as usual.

Thanks

Robert Ryan

unread,
Apr 29, 2015, 1:21:38 PM4/29/15
to tas...@googlegroups.com

What if you did it by signal strength?

Profile: WIFI Near (12)
State: Wifi Near [ SSID:* MAC:* Capabilities:* Min. Activate Signal Level:4 Channel:0 Toggle Wifi:Off ]
Enter: Anon (15)
A1: WiFi [ Set:On ]

Profile: Check Signal (39)
Event: Intent Received [ Action:android.net.wifi.RSSI_CHANGED Cat:None Cat:None Scheme:* Mime Type:* ]
Enter: Reset WIFI Near (78)
A1: If [ %newrssi < -80 ]
A2: Profile Status [ Name:WIFI Near Set:Off ]
A3: WiFi [ Set:Off ]
A4: Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ]
A5: Profile Status [ Name:WIFI Near Set:On ]
A6: End If

Robert Ryan

unread,
Apr 29, 2015, 3:24:48 PM4/29/15
to tas...@googlegroups.com

I should point out that in the Wifi Near profile you should put all of the ssids that you can connect to along your route.

technogeezer

unread,
Apr 30, 2015, 7:24:12 AM4/30/15
to tas...@googlegroups.com
Thanks Robert!

What you listed is essentially what I have now except I use the WIFI disconnect and reconnect actions rather than turning WIFI on and off.  I'm going to try WIFI off and on to see if there's a difference.

I'm still experimenting.  It takes a while because the only way I can really test this is to go out for a walk.  ;)

Thanks

Robert Ryan

unread,
Apr 30, 2015, 7:42:39 AM4/30/15
to tas...@googlegroups.com

Well the real key is the disabling and enabling of the Wifi Near profile. When the profile is re-enabled, it does an immediate scan. This way I avoid Tasker's normal 2-min wait between scans.

technogeezer

unread,
Apr 30, 2015, 11:26:35 AM4/30/15
to tas...@googlegroups.com
Two minutes between scans?  That's no better than doing nothing at all since my phone will eventually connect to my home network when (I think) the signal is highest of all routers in the area.

I like the trigger on RSSI_CHANGE but the issue is all of those SSIDs.  Couldn't I set SSID/MAC to * and then parse the return from getScanResults(), looking for my home WIFI?

Robert Ryan

unread,
Apr 30, 2015, 11:52:40 AM4/30/15
to tas...@googlegroups.com

I meant that the profile *avoids* the two min wait. Sorry if I wasn't clear.

I use this profile at work. We have multiple AP and the signals vary as I move through the building. As I get too far away from one AP, the profile will switch to the next with about a 1 sec delay.

technogeezer

unread,
May 1, 2015, 6:52:33 AM5/1/15
to tas...@googlegroups.com
No, I was the one who was unclear.  I was complaining about the time between scans.

Yours is a good algorithm.  Thanks for sharing!  It does run a lot, though, since RSSI changes once or twice a second (in my experience).  However, my desire is to favor a particular connection rather than simply shorten the connection delay.

You've given me a great start.  I'll see what I can do with it.

Thanks!

technogeezer

unread,
May 1, 2015, 1:01:32 PM5/1/15
to tas...@googlegroups.com
One other thing, you can change the wifi scan time in preferences->monitor.

Robert Ryan

unread,
May 1, 2015, 1:32:57 PM5/1/15
to tas...@googlegroups.com

On May 1, 2015 11:01 AM, "technogeezer" <spider...@gmail.com> wrote:
> One other thing, you can change the wifi scan time in preferences->monitor.

Yes, but I only want the first scan done quickly. I don't want want it to be rapidly scanning when I  am outside connection range. That just eats battery.

I could change the scan time for the first scan and then change it back, but it is just simpler to toggle the profile status.

technogeezer

unread,
May 4, 2015, 7:07:22 AM5/4/15
to tas...@googlegroups.com
Doesn't the code running as a result of the constantly changing RSSI also consume battery?  Also, the wifi toggle only occurs when the RSSI is less than -80.  That means the old router must be near out of range before any new router can connect, doesn't it?

Anyways, I tried a variation of what you posted and it does improve response time a bit.  I think the only way I can give quick priority to my home network is to actually scan the list returned from getScanResults().

The problem then is, how do I connect to a particular wifi?  (Looks like I'm off for more research.)

Thanks

Robert Ryan

unread,
May 4, 2015, 8:41:10 AM5/4/15
to tas...@googlegroups.com

On May 4, 2015 5:07 AM, "technogeezer" <spider...@gmail.com> wrote:
> Doesn't the code running as a result of the constantly changing RSSI also consume battery? 

Anytime you are connected to an AP you are going to receive these intents, whether you react to them or not. I believe the extra drain from a tasker script to be insignificant.

>Also, the wifi toggle only occurs when the RSSI is less than -80.  That means the old router must be near out of range before any new router can connect, doesn't it?

You probably have to adjust the numbers for your particular situation.

You could also try Wifi Manager
(http://goo.gl/ehkkR0), it also will scan for and switch to the strongest net. It may be better in this case.

> The problem then is, how do I connect to a particular wifi?  (Looks like I'm off for more research.)

The only way I have found to do this is via Java as shown here: http://goo.gl/7yX4xU

technogeezer

unread,
May 4, 2015, 10:22:37 AM5/4/15
to tas...@googlegroups.com
You could also try Wifi Manager

(http://goo.gl/ehkkR0), it also will scan for and switch to the strongest net. It may be better in this case.

This does not interface to Tasker but it does seem to allow a 'favored' wifi.  Would changes made to wifi by this app propagate to Tasker's internals?

> The problem then is, how do I connect to a particular wifi?  (Looks like I'm off for more research.)

The only way I have found to do this is via Java as shown here: http://goo.gl/7yX4xU

This is pure java.  How can java be executed via Tasker?  Sorry, I haven't looked into this.  Do you know of a 'how to' page by any chance?

Thanks
 

technogeezer

unread,
May 4, 2015, 10:33:14 AM5/4/15
to tas...@googlegroups.com

This is pure java.  How can java be executed via Tasker?  Sorry, I haven't looked into this.  Do you know of a 'how to' page by any chance?

I should have looked first.  Yes, the Java code is completely executable from Tasker.  This is it!

Thanks!!
 

Robert Ryan

unread,
May 4, 2015, 10:40:58 AM5/4/15
to tas...@googlegroups.com


On May 4, 2015 8:22 AM, "technogeezer" <spider...@gmail.com> wrote:
>
> You could also try Wifi Manager
>>
>> (http://goo.gl/ehkkR0), it also will scan for and switch to the strongest net. It may be better in this case.
>
> This does not interface to Tasker but it does seem to allow a 'favored' wifi.  Would changes made to wifi by this app propagate to Tasker's internals?

Yes, any change to the wifi connection would be seen by Tasker.

>> > The problem then is, how do I connect to a particular wifi?  (Looks like I'm off for more research.)
>>
>> The only way I have found to do this is via Java as shown here: http://goo.gl/7yX4xU
>
> This is pure java.  How can java be executed via Tasker?  Sorry, I haven't looked into this.  Do you know of a 'how to' page by any chance?

The only 'how to' that I know of that deals with Java + Tasker is in the User's Guide: http://goo.gl/AErqYI

technogeezer

unread,
May 4, 2015, 11:08:09 AM5/4/15
to tas...@googlegroups.com

The only 'how to' that I know of that deals with Java + Tasker is in the User's Guide: http://goo.gl/AErqYI


Yeah, found that.  Let me get back to you.

Thanks


technogeezer

unread,
May 4, 2015, 11:13:29 AM5/4/15
to tas...@googlegroups.com
Hoe does one set a member of a structure within Tasker, i.e. how does one set up an equivalent action to 'wifiConfig.SSID = "blah"'?

Robert Ryan

unread,
May 4, 2015, 11:34:56 AM5/4/15
to tas...@googlegroups.com

On May 4, 2015 9:13 AM, "technogeezer" <spider...@gmail.com> wrote:
> Hoe does one set a member of a structure within Tasker, i.e. how does one set up an equivalent action to 'wifiConfig.SSID = "blah"'?

I am pretty sure you would use the assign() method as described in the UG. I have never actually assigned anything to a field, so I'm not sure of the correct syntax.

technogeezer

unread,
May 4, 2015, 11:38:34 AM5/4/15
to tas...@googlegroups.com

I am pretty sure you would use the assign() method as described in the UG. I have never actually assigned anything to a field, so I'm not sure of the correct syntax.

No, so far, neither assign() nor toString() appear to work.

 

technogeezer

unread,
May 7, 2015, 9:03:22 AM5/7/15
to tas...@googlegroups.com
OK, got past that issue (thanks to that other thread).  But now it seems I'm fighting with Android's internal algorithm for wifi connections.

Does anyone know when or why Android changes wifi connections?  On my phone, I don't get much control, AFAICT, so it's completely up to Android.

Thanks

technogeezer

unread,
May 7, 2015, 10:50:02 AM5/7/15
to tas...@googlegroups.com
OK, found these.

http://www.tp-link.com/lb/article/?faqid=592

http://www.heleron.com/android-apps.html

At the moment, it appears I have been successful giving priority to a list of selected wifi connections.

BTW, for anyone who can use this info, I can verify that '(WifiManager)wiman.enableNetwork(id, others)' includes a disconnect and connect so you don't need to specifically call them.

Thanks!

Reply all
Reply to author
Forward
0 new messages