Re: [android-developers] How to scan Access Points and select strongest signal?

2010-05-26 Thread Donal Rafferty
Thanks again Kostya,

One final thing (well final for now, I'll probably run into more problems
after testing)

I was wondering what method you chose to convert the RSSI to a percentage?

I have been reading up on it and found the formula that uses RSSI_MAX value
but I'm unsure of the max RSSI value of the Wifi adapters.

Another way I thought about doing it is using the calculateSignal method and
converting to a percentage that way.

Can you provide any guidance on the matter?

2010/5/18 Kostya Vasilyev kmans...@gmail.com

  Donal,

 It's in scanResult.capabilites, and it's a pretty self-explanatory string.

 describeCapabilities is inhertied from Parcelable and has to do with
 persistence.

 -- Kostya

 18.05.2010 12:48, Donal Rafferty пишет:

 Very good tutorial there, thanks.

 One thing missing though is how you decide whether a scan result is an open
 netowrk or one using WEP or WPA/WPA2?

 Do you have to use scanResult.describeContents() or scanResult.capabilities
 in some way to determine which type of network to add?



 2010/5/18 Kostya Vasilyev kmans...@gmail.com

 Donald,

 Yes, obviously it's possible - Android's built-it UI for connection
 management does it somehow :)

 In my program, I do it like this:


 http://kmansoft.wordpress.com/2010/04/08/adding-wifi-networks-to-known-list/

 --
 Kostya Vasilev -- WiFi Manager + pretty widget -
 https://kmansoft.wordpress.com

 18.05.2010 12:25, Donal Rafferty пишет:

 Thanks Kostya, I think I'm nearly there.

 My current problem is adding a new configured access point.

 I have it hard coded in my code as follows:

 ---

 WifiConfiguration wc = new WifiConfiguration();
 wc.SSID = ''+scanResult.SSID+'';
 wc.status = WifiConfiguration.Status.ENABLED;

 wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);

 wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
 wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
 wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
 wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);

 wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);

 wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
 wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
 wc.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
 int res = mainWifi.addNetwork(wc);
 Log.d(WifiPreference, add Network returned  + res );
 boolean b = mainWifi.enableNetwork(res, true);
 Log.d(WifiPreference, enableNetwork returned  + b );

 --

 But is there a way I can get the information needed from a Scan Result to
 add a new Wifi configuration? Things like PairwiseCiphers, Protocols,
 AuthAlgorithms, KeyManagement I cant see a method to retrieve that info from
 a Scan result.

 Is it possible?

 2010/5/14 Kostya Vasilyev kmans...@gmail.com

 Donald,

 Yes, your algorithm is correct. Only add network from the scan list to
 the known list if not already there.

 As for scanning on the move, take a look at wake locks.

 14 мая, 2010 5:35 PM пользователь Donal Rafferty draf...@gmail.com
 написал:


 Thanks again Kostya,

 I have downloaded your app and had a look, its very nice, the widget will
 come in very handy for my testing!

 I was aware of the known versus as is quotes.

 My problem is for my app to work I need it to scan for AP's when the
 device is on the move.

 So it should scan, find a new AP that has the highest RSSI in the area
 and connect to that.

 The problem is I can only connect to a known or already configured AP
 and not one resulting from a scan.

 So would I be correct in saying that I need to do the following?

 Scan
 Get the highest RSSI
 Compare the SSID of this AP to the Wifi Config list
 If its in the Wifi config list then connect
 If its not then add a new access point (As a configured AP)
 Get the id of the newly added AP and connect


  On Fri, May 14, 2010 at 1:47 PM, Kostya Vasilyev kmans...@gmail.com
 wrote:   Donal,   I think...
 --

 You received this message because you are subscribed to the Google Groups
 Android Developers group...

 --
  You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


--
 You 

Re: [android-developers] How to scan Access Points and select strongest signal?

2010-05-18 Thread Donal Rafferty
Thanks Kostya, I think I'm nearly there.

My current problem is adding a new configured access point.

I have it hard coded in my code as follows:

---

WifiConfiguration wc = new WifiConfiguration();
wc.SSID = ''+scanResult.SSID+'';
wc.status = WifiConfiguration.Status.ENABLED;
wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);

wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);

wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);

wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wc.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
int res = mainWifi.addNetwork(wc);
Log.d(WifiPreference, add Network returned  + res );
boolean b = mainWifi.enableNetwork(res, true);
Log.d(WifiPreference, enableNetwork returned  + b );

--

But is there a way I can get the information needed from a Scan Result to
add a new Wifi configuration? Things like PairwiseCiphers, Protocols,
AuthAlgorithms, KeyManagement I cant see a method to retrieve that info from
a Scan result.

Is it possible?

2010/5/14 Kostya Vasilyev kmans...@gmail.com

 Donald,

 Yes, your algorithm is correct. Only add network from the scan list to the
 known list if not already there.

 As for scanning on the move, take a look at wake locks.

 14 мая, 2010 5:35 PM пользователь Donal Rafferty draf...@gmail.com
 написал:


 Thanks again Kostya,

 I have downloaded your app and had a look, its very nice, the widget will
 come in very handy for my testing!

 I was aware of the known versus as is quotes.

 My problem is for my app to work I need it to scan for AP's when the device
 is on the move.

 So it should scan, find a new AP that has the highest RSSI in the area and
 connect to that.

 The problem is I can only connect to a known or already configured AP and
 not one resulting from a scan.

 So would I be correct in saying that I need to do the following?

 Scan
 Get the highest RSSI
 Compare the SSID of this AP to the Wifi Config list
 If its in the Wifi config list then connect
 If its not then add a new access point (As a configured AP)
 Get the id of the newly added AP and connect


 On Fri, May 14, 2010 at 1:47 PM, Kostya Vasilyev kmans...@gmail.com
 wrote:   Donal,   I think...
 --

 You received this message because you are subscribed to the Google Groups
 Android Developers group...

  --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] How to scan Access Points and select strongest signal?

2010-05-18 Thread Kostya Vasilyev

Donald,

Yes, obviously it's possible - Android's built-it UI for connection 
management does it somehow :)


In my program, I do it like this:

http://kmansoft.wordpress.com/2010/04/08/adding-wifi-networks-to-known-list/

--
Kostya Vasilev -- WiFi Manager + pretty widget - 
https://kmansoft.wordpress.com


18.05.2010 12:25, Donal Rafferty пишет:

Thanks Kostya, I think I'm nearly there.

My current problem is adding a new configured access point.

I have it hard coded in my code as follows:

---

WifiConfiguration wc = new WifiConfiguration();
wc.SSID = ''+scanResult.SSID+'';
wc.status = WifiConfiguration.Status.ENABLED;

wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);

wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);

wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);

wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);

wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);

wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wc.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
int res = mainWifi.addNetwork(wc);
Log.d(WifiPreference, add Network returned  + res );
boolean b = mainWifi.enableNetwork(res, true);
Log.d(WifiPreference, enableNetwork returned  + b );

--

But is there a way I can get the information needed from a Scan Result 
to add a new Wifi configuration? Things like PairwiseCiphers, 
Protocols, AuthAlgorithms, KeyManagement I cant see a method to 
retrieve that info from a Scan result.


Is it possible?

2010/5/14 Kostya Vasilyev kmans...@gmail.com mailto:kmans...@gmail.com

Donald,

Yes, your algorithm is correct. Only add network from the scan
list to the known list if not already there.

As for scanning on the move, take a look at wake locks.


14 мая, 2010 5:35 PM пользователь Donal Rafferty
draf...@gmail.com mailto:draf...@gmail.com написал:


Thanks again Kostya,

I have downloaded your app and had a look, its very nice, the
widget will come in very handy for my testing!

I was aware of the known versus as is quotes.

My problem is for my app to work I need it to scan for AP's when
the device is on the move.

So it should scan, find a new AP that has the highest RSSI in the
area and connect to that.

The problem is I can only connect to a known or already
configured AP and not one resulting from a scan.

So would I be correct in saying that I need to do the following?

Scan
Get the highest RSSI
Compare the SSID of this AP to the Wifi Config list
If its in the Wifi config list then connect
If its not then add a new access point (As a configured AP)
Get the id of the newly added AP and connect


On Fri, May 14, 2010 at 1:47 PM, Kostya Vasilyev
kmans...@gmail.com mailto:kmans...@gmail.com wrote:  
Donal,   I think...

-- 


You received this message because you are subscribed to the
Google Groups Android Developers group...

-- 
You received this message because you are subscribed to the Google

Groups Android Developers group.
To post to this group, send email to
android-developers@googlegroups.com
mailto:android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
mailto:android-developers%2bunsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en 


--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] How to scan Access Points and select strongest signal?

2010-05-18 Thread Donal Rafferty
Very good tutorial there, thanks.

One thing missing though is how you decide whether a scan result is an open
netowrk or one using WEP or WPA/WPA2?

Do you have to use scanResult.describeContents() or scanResult.capabilities
in some way to determine which type of network to add?



2010/5/18 Kostya Vasilyev kmans...@gmail.com

  Donald,

 Yes, obviously it's possible - Android's built-it UI for connection
 management does it somehow :)

 In my program, I do it like this:


 http://kmansoft.wordpress.com/2010/04/08/adding-wifi-networks-to-known-list/

 --
 Kostya Vasilev -- WiFi Manager + pretty widget -
 https://kmansoft.wordpress.com

 18.05.2010 12:25, Donal Rafferty пишет:

 Thanks Kostya, I think I'm nearly there.

 My current problem is adding a new configured access point.

 I have it hard coded in my code as follows:

 ---

 WifiConfiguration wc = new WifiConfiguration();
 wc.SSID = ''+scanResult.SSID+'';
 wc.status = WifiConfiguration.Status.ENABLED;
 wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);

 wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
 wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
 wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
 wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);

 wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);

 wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
 wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
 wc.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
 int res = mainWifi.addNetwork(wc);
 Log.d(WifiPreference, add Network returned  + res );
 boolean b = mainWifi.enableNetwork(res, true);
 Log.d(WifiPreference, enableNetwork returned  + b );

 --

 But is there a way I can get the information needed from a Scan Result to
 add a new Wifi configuration? Things like PairwiseCiphers, Protocols,
 AuthAlgorithms, KeyManagement I cant see a method to retrieve that info from
 a Scan result.

 Is it possible?

 2010/5/14 Kostya Vasilyev kmans...@gmail.com

 Donald,

 Yes, your algorithm is correct. Only add network from the scan list to the
 known list if not already there.

 As for scanning on the move, take a look at wake locks.

 14 мая, 2010 5:35 PM пользователь Donal Rafferty draf...@gmail.com
 написал:


 Thanks again Kostya,

 I have downloaded your app and had a look, its very nice, the widget will
 come in very handy for my testing!

 I was aware of the known versus as is quotes.

 My problem is for my app to work I need it to scan for AP's when the
 device is on the move.

 So it should scan, find a new AP that has the highest RSSI in the area and
 connect to that.

 The problem is I can only connect to a known or already configured AP
 and not one resulting from a scan.

 So would I be correct in saying that I need to do the following?

 Scan
 Get the highest RSSI
 Compare the SSID of this AP to the Wifi Config list
 If its in the Wifi config list then connect
 If its not then add a new access point (As a configured AP)
 Get the id of the newly added AP and connect


  On Fri, May 14, 2010 at 1:47 PM, Kostya Vasilyev kmans...@gmail.com
 wrote:   Donal,   I think...
 --

 You received this message because you are subscribed to the Google Groups
 Android Developers group...

 --
  You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


  --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at

Re: [android-developers] How to scan Access Points and select strongest signal?

2010-05-18 Thread Kostya Vasilyev

Donal,

It's in scanResult.capabilites, and it's a pretty self-explanatory string.

describeCapabilities is inhertied from Parcelable and has to do with 
persistence.


-- Kostya

18.05.2010 12:48, Donal Rafferty пишет:

Very good tutorial there, thanks.

One thing missing though is how you decide whether a scan result is an 
open netowrk or one using WEP or WPA/WPA2?


Do you have to use scanResult.describeContents() or 
scanResult.capabilities in some way to determine which type of network 
to add?




2010/5/18 Kostya Vasilyev kmans...@gmail.com mailto:kmans...@gmail.com

Donald,

Yes, obviously it's possible - Android's built-it UI for
connection management does it somehow :)

In my program, I do it like this:

http://kmansoft.wordpress.com/2010/04/08/adding-wifi-networks-to-known-list/

--
Kostya Vasilev -- WiFi Manager + pretty widget -
https://kmansoft.wordpress.com

18.05.2010 12:25, Donal Rafferty пишет:

Thanks Kostya, I think I'm nearly there.

My current problem is adding a new configured access point.

I have it hard coded in my code as follows:

---

WifiConfiguration wc = new WifiConfiguration();
wc.SSID = ''+scanResult.SSID+'';
wc.status = WifiConfiguration.Status.ENABLED;
   
wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
   
wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
   
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
   
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);

wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
   
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
   
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);

wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wc.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
int res = mainWifi.addNetwork(wc);
Log.d(WifiPreference, add Network returned  + res );
boolean b = mainWifi.enableNetwork(res, true);
Log.d(WifiPreference, enableNetwork returned  + b );

--

But is there a way I can get the information needed from a Scan
Result to add a new Wifi configuration? Things like
PairwiseCiphers, Protocols, AuthAlgorithms, KeyManagement I cant
see a method to retrieve that info from a Scan result.

Is it possible?

2010/5/14 Kostya Vasilyev kmans...@gmail.com
mailto:kmans...@gmail.com

Donald,

Yes, your algorithm is correct. Only add network from the
scan list to the known list if not already there.

As for scanning on the move, take a look at wake locks.


14 мая, 2010 5:35 PM пользователь Donal Rafferty
draf...@gmail.com mailto:draf...@gmail.com написал:


Thanks again Kostya,

I have downloaded your app and had a look, its very nice,
the widget will come in very handy for my testing!

I was aware of the known versus as is quotes.

My problem is for my app to work I need it to scan for AP's
when the device is on the move.

So it should scan, find a new AP that has the highest RSSI
in the area and connect to that.

The problem is I can only connect to a known or already
configured AP and not one resulting from a scan.

So would I be correct in saying that I need to do the following?

Scan
Get the highest RSSI
Compare the SSID of this AP to the Wifi Config list
If its in the Wifi config list then connect
If its not then add a new access point (As a configured AP)
Get the id of the newly added AP and connect


On Fri, May 14, 2010 at 1:47 PM, Kostya Vasilyev
kmans...@gmail.com mailto:kmans...@gmail.com wrote:  
Donal,   I think...

-- 


You received this message because you are subscribed to the
Google Groups Android Developers group...

-- 
You received this message because you are subscribed to the

Google
Groups Android Developers group.
To post to this group, send email to
android-developers@googlegroups.com
mailto:android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
mailto:android-developers%2bunsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


-- 
You received this message because you are subscribed to the Google

Groups Android Developers group.
To post to this group, send email to
android-developers@googlegroups.com
mailto:android-developers@googlegroups.com
To unsubscribe from this group, send email to

Re: [android-developers] How to scan Access Points and select strongest signal?

2010-05-14 Thread Donal Rafferty
Thanks for that Kostya

I have come across a bit of a problem though.

After a scan there are 11 AP's found and all 11 show up in the list in the
Wifi settings on the device.

But when I use 
getConfiguredNetworkshttp://developer.android.com/reference/android/net/wifi/WifiManager.html#getConfiguredNetworks()
it only returns 4 configured networks.

This happens despite the 11 AP's showing up in the settings after a scan.

So the majority of the time when I compared the AP with the best signal's
SSID with the SSID's in the Configured Network list the majority of the time
no matching SSID is found.

In that case I try to add a new network but this ends up creating duplicates
of the AP in the settings list.

On Thu, May 13, 2010 at 5:24 PM, Kostya Vasilyev kmans...@gmail.com wrote:

 Hi,

 1. Regarding duplicates. Android maintains a list of known networks - for
 each, it stores the SSID, encryption configuration, along with the password,
 if necessary. Each known network also has a unique numeric ID.

 You can only connect to networks on this known list, because, as you
 correctly figured out, connecting to a network is done by its id.

 However, it's not necessary to add the network to this list if it's already
 been added (by Android or by your application).

 You can get the list of known networks from the WifiManager:


 http://developer.android.com/reference/android/net/wifi/WifiManager.html#getConfiguredNetworks
 ()

 You can match these networks to your live scan results using their SSIDs.
 If the network is already in the known list, just use its numeric id. If
 not, you get the numeric ID back from addNetwork().

 2. Once you have the numeric ID, call enableNetwork(networkId, true) to
 connect. The second parameter means disconnect from others, not forget
 all other network as its name might seem to imply.

 -- Kostya Vasilyev


 2010/5/13 draf...@gmail.com draf...@gmail.com

 I am currently trying to write a class in Android that will Scan for
 access points, calculate which access point has the best signal and
 then connect to that access point.


 So the application will be able to scan on the move and attach to new
 access points on the go.

 I have the scanning and calculation of the best signal working.

 But when it comes to attaching to the best access point I am having
 trouble.

 It appears that enableNetwork(netid, othersTrueFalse) is the only
 method for attaching to an Access point but this causes problems as
 from my Scan Results I am not able to get the id of the access point
 with the strongest signal.

 This is my code:

 ---

public void doWifiScan(){

  scanTask = new TimerTask() {
  public void run() {
  handler.post(new Runnable() {
  public void run() {
   sResults = wifiManager.scan(getBaseContext());
   if(sResults!=null)
   Log.d(TIMER, sResults count + sResults.size());
   ScanResult scan =
 wifiManager.calculateBestAP(sResults);
   wifiManager.addNewAccessPoint(scan);
   }
   });
}};

t.schedule(scanTask, 3000, 3);
}


 ---

public ScanResult calculateBestAP(ListScanResult sResults){

 ScanResult bestSignal = null;
for (ScanResult result : sResults) {
  if (bestSignal == null
  ||
 WifiManager.compareSignalLevel(bestSignal.level,
 result.level)  0)
bestSignal = result;
}

String message = String.format(%s networks found. %s
 is the
 strongest. %s is the bsid,
sResults.size(), bestSignal.SSID,
 bestSignal.BSSID);

Log.d(sResult, message);
return bestSignal;
}


 ---

public void addNewAccessPoint(ScanResult scanResult){

WifiConfiguration wc = new WifiConfiguration();
wc.SSID = '\' + scanResult.SSID + '\';
//wc.preSharedKey  = \password\;
wc.hiddenSSID = true;
wc.status = WifiConfiguration.Status.ENABLED;

  wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);

  wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);

  wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);

 wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);

 wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
int res = mainWifi.addNetwork(wc);
Log.d(WifiPreference, add Network returned  + res );
boolean b = mainWifi.enableNetwork(res, false);
Log.d(WifiPreference, enableNetwork returned  + b );

}


 ---

 When I try to use addNewAccessPoint(ScanResult scanResult) it just
 adds another AP to the list in the settings application with the 

Re: [android-developers] How to scan Access Points and select strongest signal?

2010-05-14 Thread Kostya Vasilyev

Donal,

I think you are not matching the SSIDs of known and live networks correctly.

The SSIDs in the known list are enclosed in double quotes:

http://developer.android.com/reference/android/net/wifi/WifiConfiguration.html#SSID

The SSIDs in the live scan result list are as is, without the quotes.

Your code needs to take this into consideration when matching the 
networks between the two lists.


BTW, feel free to download and try my WiFi management tool, I think it 
should make it easier to see what's going on. See the link in my 
signature below.


--
Kostya Vasilyev ~ WiFi Manager + pretty widget ~ 
http://kmansoft.wordpress.com/sw


14.05.2010 14:33, Donal Rafferty ?:

Thanks for that Kostya

I have come across a bit of a problem though.

After a scan there are 11 AP's found and all 11 show up in the list in 
the Wifi settings on the device.


But when I use getConfiguredNetworks 
http://developer.android.com/reference/android/net/wifi/WifiManager.html#getConfiguredNetworks() 
it only returns 4 configured networks.


This happens despite the 11 AP's showing up in the settings after a scan.

So the majority of the time when I compared the AP with the best 
signal's SSID with the SSID's in the Configured Network list the 
majority of the time no matching SSID is found.


In that case I try to add a new network but this ends up creating 
duplicates of the AP in the settings list.


On Thu, May 13, 2010 at 5:24 PM, Kostya Vasilyev kmans...@gmail.com 
mailto:kmans...@gmail.com wrote:


Hi,
1. Regarding duplicates. Android maintains a list of known
networks - for each, it stores the SSID, encryption configuration,
along with the password, if necessary. Each known network also has
a unique numeric ID.
You can only connect to networks on this known list, because, as
you correctly figured out, connecting to a network is done by its id.
However, it's not necessary to add the network to this list if
it's already been added (by Android or by your application).
You can get the list of known networks from the WifiManager:

http://developer.android.com/reference/android/net/wifi/WifiManager.html#getConfiguredNetworks()
You can match these networks to your live scan results using their
SSIDs. If the network is already in the known list, just use its
numeric id. If not, you get the numeric ID back from addNetwork().
2. Once you have the numeric ID, call enableNetwork(networkId,
true) to connect. The second parameter means disconnect from
others, not forget all other network as its name might seem to
imply.
-- Kostya Vasilyev

2010/5/13 draf...@gmail.com mailto:draf...@gmail.com
draf...@gmail.com mailto:draf...@gmail.com

I am currently trying to write a class in Android that will
Scan for
access points, calculate which access point has the best
signal and
then connect to that access point.


So the application will be able to scan on the move and attach
to new
access points on the go.

I have the scanning and calculation of the best signal working.

But when it comes to attaching to the best access point I am
having
trouble.

It appears that enableNetwork(netid, othersTrueFalse) is the only
method for attaching to an Access point but this causes
problems as
from my Scan Results I am not able to get the id of the access
point
with the strongest signal.

This is my code:

---

   public void doWifiScan(){

 scanTask = new TimerTask() {
 public void run() {
 handler.post(new Runnable() {
 public void run() {
  sResults = wifiManager.scan(getBaseContext());
  if(sResults!=null)
  Log.d(TIMER, sResults count +
sResults.size());
  ScanResult scan =
wifiManager.calculateBestAP(sResults);
  wifiManager.addNewAccessPoint(scan);
  }
  });
   }};

   t.schedule(scanTask, 3000, 3);
   }


---

   public ScanResult calculateBestAP(ListScanResult sResults){

ScanResult bestSignal = null;
   for (ScanResult result : sResults) {
 if (bestSignal == null
 ||
WifiManager.compareSignalLevel(bestSignal.level,
result.level)  0)
   bestSignal = result;
   }

   String message = String.format(%s networks
found. %s is the
strongest. %s is the bsid,
   sResults.size(), bestSignal.SSID,
bestSignal.BSSID);

   Log.d(sResult, 

Re: [android-developers] How to scan Access Points and select strongest signal?

2010-05-14 Thread Donal Rafferty
Thanks again Kostya,

I have downloaded your app and had a look, its very nice, the widget will
come in very handy for my testing!

I was aware of the known versus as is quotes.

My problem is for my app to work I need it to scan for AP's when the device
is on the move.

So it should scan, find a new AP that has the highest RSSI in the area and
connect to that.

The problem is I can only connect to a known or already configured AP and
not one resulting from a scan.

So would I be correct in saying that I need to do the following?

Scan
Get the highest RSSI
Compare the SSID of this AP to the Wifi Config list
If its in the Wifi config list then connect
If its not then add a new access point (As a configured AP)
Get the id of the newly added AP and connect



On Fri, May 14, 2010 at 1:47 PM, Kostya Vasilyev kmans...@gmail.com wrote:

  Donal,

 I think you are not matching the SSIDs of known and live networks
 correctly.

 The SSIDs in the known list are enclosed in double quotes:


 http://developer.android.com/reference/android/net/wifi/WifiConfiguration.html#SSID

 The SSIDs in the live scan result list are as is, without the quotes.

 Your code needs to take this into consideration when matching the networks
 between the two lists.

 BTW, feel free to download and try my WiFi management tool, I think it
 should make it easier to see what's going on. See the link in my signature
 below.

 --
 Kostya Vasilyev ~ WiFi Manager + pretty widget ~ 
 http://kmansoft.wordpress.com/sw


 14.05.2010 14:33, Donal Rafferty пишет:

 Thanks for that Kostya

 I have come across a bit of a problem though.

 After a scan there are 11 AP's found and all 11 show up in the list in the
 Wifi settings on the device.

 But when I use 
 getConfiguredNetworkshttp://developer.android.com/reference/android/net/wifi/WifiManager.html#getConfiguredNetworks()
 it only returns 4 configured networks.

 This happens despite the 11 AP's showing up in the settings after a scan.

 So the majority of the time when I compared the AP with the best signal's
 SSID with the SSID's in the Configured Network list the majority of the time
 no matching SSID is found.

 In that case I try to add a new network but this ends up creating
 duplicates of the AP in the settings list.

 On Thu, May 13, 2010 at 5:24 PM, Kostya Vasilyev kmans...@gmail.comwrote:

 Hi,

 1. Regarding duplicates. Android maintains a list of known networks -
 for each, it stores the SSID, encryption configuration, along with the
 password, if necessary. Each known network also has a unique numeric ID.

 You can only connect to networks on this known list, because, as you
 correctly figured out, connecting to a network is done by its id.

 However, it's not necessary to add the network to this list if it's
 already been added (by Android or by your application).

 You can get the list of known networks from the WifiManager:


 http://developer.android.com/reference/android/net/wifi/WifiManager.html#getConfiguredNetworks
 ()

 You can match these networks to your live scan results using their SSIDs.
 If the network is already in the known list, just use its numeric id. If
 not, you get the numeric ID back from addNetwork().

 2. Once you have the numeric ID, call enableNetwork(networkId, true) to
 connect. The second parameter means disconnect from others, not forget
 all other network as its name might seem to imply.

 -- Kostya Vasilyev


 2010/5/13 draf...@gmail.com draf...@gmail.com

  I am currently trying to write a class in Android that will Scan for
 access points, calculate which access point has the best signal and
 then connect to that access point.


 So the application will be able to scan on the move and attach to new
 access points on the go.

 I have the scanning and calculation of the best signal working.

 But when it comes to attaching to the best access point I am having
 trouble.

 It appears that enableNetwork(netid, othersTrueFalse) is the only
 method for attaching to an Access point but this causes problems as
 from my Scan Results I am not able to get the id of the access point
 with the strongest signal.

 This is my code:

 ---

public void doWifiScan(){

  scanTask = new TimerTask() {
  public void run() {
  handler.post(new Runnable() {
  public void run() {
   sResults = wifiManager.scan(getBaseContext());
   if(sResults!=null)
   Log.d(TIMER, sResults count + sResults.size());
   ScanResult scan =
 wifiManager.calculateBestAP(sResults);
   wifiManager.addNewAccessPoint(scan);
   }
   });
}};

t.schedule(scanTask, 3000, 3);
}


 ---

public ScanResult calculateBestAP(ListScanResult sResults){

 ScanResult bestSignal = null;
for (ScanResult result : sResults) {
  if (bestSignal == null
  ||
 

Re: [android-developers] How to scan Access Points and select strongest signal?

2010-05-14 Thread Kostya Vasilyev
Donald,

Yes, your algorithm is correct. Only add network from the scan list to the
known list if not already there.

As for scanning on the move, take a look at wake locks.

14 мая, 2010 5:35 PM пользователь Donal Rafferty draf...@gmail.com
написал:

Thanks again Kostya,

I have downloaded your app and had a look, its very nice, the widget will
come in very handy for my testing!

I was aware of the known versus as is quotes.

My problem is for my app to work I need it to scan for AP's when the device
is on the move.

So it should scan, find a new AP that has the highest RSSI in the area and
connect to that.

The problem is I can only connect to a known or already configured AP and
not one resulting from a scan.

So would I be correct in saying that I need to do the following?

Scan
Get the highest RSSI
Compare the SSID of this AP to the Wifi Config list
If its in the Wifi config list then connect
If its not then add a new access point (As a configured AP)
Get the id of the newly added AP and connect


On Fri, May 14, 2010 at 1:47 PM, Kostya Vasilyev kmans...@gmail.com wrote:
  Donal,   I think...
-- 

You received this message because you are subscribed to the Google Groups
Android Developers group...

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] How to scan Access Points and select strongest signal?

2010-05-13 Thread draf...@gmail.com
I am currently trying to write a class in Android that will Scan for
access points, calculate which access point has the best signal and
then connect to that access point.


So the application will be able to scan on the move and attach to new
access points on the go.

I have the scanning and calculation of the best signal working.

But when it comes to attaching to the best access point I am having
trouble.

It appears that enableNetwork(netid, othersTrueFalse) is the only
method for attaching to an Access point but this causes problems as
from my Scan Results I am not able to get the id of the access point
with the strongest signal.

This is my code:

---

public void doWifiScan(){

  scanTask = new TimerTask() {
  public void run() {
  handler.post(new Runnable() {
  public void run() {
   sResults = wifiManager.scan(getBaseContext());
   if(sResults!=null)
   Log.d(TIMER, sResults count + sResults.size());
   ScanResult scan =
wifiManager.calculateBestAP(sResults);
   wifiManager.addNewAccessPoint(scan);
   }
   });
}};

t.schedule(scanTask, 3000, 3);
}


---

public ScanResult calculateBestAP(ListScanResult sResults){

 ScanResult bestSignal = null;
for (ScanResult result : sResults) {
  if (bestSignal == null
  || WifiManager.compareSignalLevel(bestSignal.level,
result.level)  0)
bestSignal = result;
}

String message = String.format(%s networks found. %s is the
strongest. %s is the bsid,
sResults.size(), bestSignal.SSID, bestSignal.BSSID);

Log.d(sResult, message);
return bestSignal;
}


---

public void addNewAccessPoint(ScanResult scanResult){

WifiConfiguration wc = new WifiConfiguration();
wc.SSID = '\' + scanResult.SSID + '\';
//wc.preSharedKey  = \password\;
wc.hiddenSSID = true;
wc.status = WifiConfiguration.Status.ENABLED;
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);

wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);

wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
int res = mainWifi.addNetwork(wc);
Log.d(WifiPreference, add Network returned  + res );
boolean b = mainWifi.enableNetwork(res, false);
Log.d(WifiPreference, enableNetwork returned  + b );

}


---

When I try to use addNewAccessPoint(ScanResult scanResult) it just
adds another AP to the list in the settings application with the same
name as the one with the best signal, so I end up with loads of
duplicates and not actually attaching to them.

Can anyone point me in the direction of a better solution?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] How to scan Access Points and select strongest signal?

2010-05-13 Thread Kostya Vasilyev
Hi,

1. Regarding duplicates. Android maintains a list of known networks - for
each, it stores the SSID, encryption configuration, along with the password,
if necessary. Each known network also has a unique numeric ID.

You can only connect to networks on this known list, because, as you
correctly figured out, connecting to a network is done by its id.

However, it's not necessary to add the network to this list if it's already
been added (by Android or by your application).

You can get the list of known networks from the WifiManager:

http://developer.android.com/reference/android/net/wifi/WifiManager.html#getConfiguredNetworks
()

You can match these networks to your live scan results using their SSIDs. If
the network is already in the known list, just use its numeric id. If not,
you get the numeric ID back from addNetwork().

2. Once you have the numeric ID, call enableNetwork(networkId, true) to
connect. The second parameter means disconnect from others, not forget
all other network as its name might seem to imply.

-- Kostya Vasilyev


2010/5/13 draf...@gmail.com draf...@gmail.com

 I am currently trying to write a class in Android that will Scan for
 access points, calculate which access point has the best signal and
 then connect to that access point.


 So the application will be able to scan on the move and attach to new
 access points on the go.

 I have the scanning and calculation of the best signal working.

 But when it comes to attaching to the best access point I am having
 trouble.

 It appears that enableNetwork(netid, othersTrueFalse) is the only
 method for attaching to an Access point but this causes problems as
 from my Scan Results I am not able to get the id of the access point
 with the strongest signal.

 This is my code:

 ---

public void doWifiScan(){

  scanTask = new TimerTask() {
  public void run() {
  handler.post(new Runnable() {
  public void run() {
   sResults = wifiManager.scan(getBaseContext());
   if(sResults!=null)
   Log.d(TIMER, sResults count + sResults.size());
   ScanResult scan =
 wifiManager.calculateBestAP(sResults);
   wifiManager.addNewAccessPoint(scan);
   }
   });
}};

t.schedule(scanTask, 3000, 3);
}


 ---

public ScanResult calculateBestAP(ListScanResult sResults){

 ScanResult bestSignal = null;
for (ScanResult result : sResults) {
  if (bestSignal == null
  ||
 WifiManager.compareSignalLevel(bestSignal.level,
 result.level)  0)
bestSignal = result;
}

String message = String.format(%s networks found. %s is
 the
 strongest. %s is the bsid,
sResults.size(), bestSignal.SSID,
 bestSignal.BSSID);

Log.d(sResult, message);
return bestSignal;
}


 ---

public void addNewAccessPoint(ScanResult scanResult){

WifiConfiguration wc = new WifiConfiguration();
wc.SSID = '\' + scanResult.SSID + '\';
//wc.preSharedKey  = \password\;
wc.hiddenSSID = true;
wc.status = WifiConfiguration.Status.ENABLED;

  wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);

  wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);

  wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);

 wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);

 wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
int res = mainWifi.addNetwork(wc);
Log.d(WifiPreference, add Network returned  + res );
boolean b = mainWifi.enableNetwork(res, false);
Log.d(WifiPreference, enableNetwork returned  + b );

}


 ---

 When I try to use addNewAccessPoint(ScanResult scanResult) it just
 adds another AP to the list in the settings application with the same
 name as the one with the best signal, so I end up with loads of
 duplicates and not actually attaching to them.

 Can anyone point me in the direction of a better solution?

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group,