How to get Nearby Wifi distance and direction in Android Studios - android

How can I get the direction and the strength of all the nearby Wifi ?
Till now I have been able to get Wifi Strength in Level but only of connected wifi using following code
WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
int numberOfLevels = 5;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
I am trying to do something like this
Play Store App Link
This app gives nearby wifi plot on campas
Can anyone guide my how this is possible?

Short answer "not possible".
Long answer is that the phone gives just the strength of the incoming signal, which can come from any direction. You can not even estimate the distance to the WiFi access point until you know its signal strength with your phone for some known distance. You can however estimate the direction of where the WiFi access point is from movement of your phone and the differences of the WiFi signal strength changes.
The app you linked to tells you to start scanning and then slowly rotate. That is needed for recording the device orientation and the signal strength changes. Then based on the orientation of the device and the signal strength for that orientation it can estimated where the WiFi access point is. I am not connected with that app in any way, nor I have used it. All this information is based on the app's screenshots and general knowledge of how WiFi works.
Then there are other funny things like WiFi access points which can send a stronger signal in a specific direction when it detects a device with low signal.

To find distance you can try:
public double calculateDistance(double signalLevelInDb, double freqInMHz) {
double exp = (27.55 - (20 * Math.log10(freqInMHz)) + Math.abs(signalLevelInDb)) / 20.0;
return Math.pow(10.0, exp);
}

Related

How to detect slow internet connection in android app

I want to detect if a phone has a slow internet connection or high-speed internet.
Now they have deprecated NetworkInfo and suggesting that we should use ConnectivityManager#getNetworkCapabilities using this I am able to get the signal strength but not able to figure out how to use integer value returned by networkCapabilities.getSignalStrength()
It is returning an Integer value I am getting these values (-39, -71, -31).
My question is how should we define that signal strength is good/poor.
Here is my code to get Signal Strength:
ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
Network activeNetwork = cm.getActiveNetwork();
NetworkCapabilities networkCapabilities = cm.getNetworkCapabilities(activeNetwork);
int signalStrength = networkCapabilities.getSignalStrength();
First this is a directive approach rather than being a direct answer to the question.
int signalStrength = networkCapabilities.getSignalStrength();
Doc:
This is a signed integer, with higher values indicating a stronger signal. The exact units are bearer-dependent. For example, Wi-Fi uses the same RSSI units reported by wifi code.
This means that signalStrength holds a value that is relevant to the signal bearer; for instance if the bearer is WiFi, then the signalStrength will reflect the same WiFi RSSI units.
RSSI, or “Received Signal Strength Indicator,” is a measurement of how well your device can hear a signal from an access point or router. It’s a value that is useful for determining if you have enough signal to get a good wireless connection.
So, you need to map those units to some quality gauge to know whether the signal is weak/strong. This is communication/signal dependent rather than a programming point of view... This thread and also this one may help you for that in case of WiFi bearer.
But you need to customize this quality level for other types of signal bearers the same-wise according to their RSSI units.
GSM signal for instance you may use CellSignalStrengthGsm which has getRssi()
CellSignalStrengthLte is for LTE and so on.
You may also get the level of signal strength from the android.telephony API's SignalStrength class... there is a getLevel() method which returns an integer from 0 to 4 representing the general signal quality. Here you can find a listener to that.

Google Nearby Connection API: measure signal strength

Recently I found a seemingly cool way to communicate between devices using Google Nearby API. Skimming through the documentation didn't answer my question - is it possible to measure the connection signal strength in real time, or should I invent some kludges e.g. measuring time of sending and receiving data or something else?
Thank you.
As a developer of Nearby API stated in thread Google Nearby Messages - Cancel initial link between devices :
Today, Nearby doesn't expose distance directly
He suggests to use BLE RSII instead
You can get a rough approximation of distance by measuring BLE RSSI if one of the devices is capable of BLE advertising. This will be sensitive to how the device is held, antenna gain and environmental factors but better than random.
There's not a straight-forward "tape measure" API, though.
If your question really is about "Nearby Connection API" and not "Nearby Messages API", you could simply check the Wifi-Signal Strength:
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
int numberOfLevels = 5;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);

how to get Distance between wifi access point and Mobile Device

i am developing an android application which have module to search all nearest / detected wifi hotspot.
i can get all detail from searched wifi hotspot like,
SSID, BSSID, capabilities, frequency, level and timestamp
with these information, i also need Distance of wifi ( The distance between wifi accesspoint and Mobile Device )
i am using below lines to get Distance.
double exp = (27.55 - (20 * Math.log10(freqInMHz)) + Math.abs(levelInDb)) / 20.0;
double distanceM = Math.pow(10.0, exp);
this will return distance in meter.
i got these code by reserch on google from many pages.
but i think i am going wrong, this code is returning wrong distance. i also tried a lot on google search but not getting accurate output.
Please help me. how can i get Distance between Wifi AP and Mobile device?
This code:
double exp = (27.55 - (20 * Math.log10(freqInMHz)) + Math.abs(levelInDb)) / 20.0;
double distanceM = Math.pow(10.0, exp);
Works under the assumption of free space path attenuation between two isotropic antennas and the AP transmitting at a power of 20dBm (and the math is not even correct; the frequency dependence of free space path loss is different; not that is matters for the bands of W-LAN, uses, the correction is in the 27.55).
In reality you're dealing with anisotropic antennas, obstacles in your path, diffraction effects and the AP varying it's power output to save energy if no high bandwidth is required.
Or in other words: It's totally impractical to obtain a reliable distance figure just looking at the received power. It can give you a ballpark, order of magnitude, but not something that's remotely accurate. This is just basic physics.
The only reliable way of measuring distance is time-of-flight. For this you have to measure the roundtrip time between the device and the access point. Since we're dealing with the speed of light and distances in the order of meters up to 100m (top), this means measuring nanoseconds. Can be done but requires some work. See the link SatelliteSD gave you (it's in German but the diagrams and keywords should be understandable).
It is possible, you could use the Time-of-Flight approach. Keep in mind that you can't rely on the messages recieved, but on the overhead received (like ACK)
I can only come up with this reference (german language) measuring of signal runtimes
And from a quick read I think it is a very tedious thing to do.
No, it is not possible.
You'll not be able to find the hotspots distance from your current device location to the actual hotspot.
It seems that the hotspots don't report their coordinates.
Check the Link which has more detailed info.
There is a method called "triangulation" but for this case you have least 3 hotspot. You can answer with detail in this pdf.
http://www.see.ed.ac.uk/~slig/papers/ITM2010.pdf

Android: Controlling Wifi Range Potency

I am developing an android application and I would like to be able to control the range potency of my smartphone's wifi.
For example, suppose that I want to use the Wifi direct API, but I it shows me people that are in a range of 10 meters from me. Although this is very good, I just want to connect with people that are in a range of 3 meters from me. In this case my idea was to limit the potency of my smatphone's wifi, in order to only "see" the devices that are very near me.
My question in this case is: Is there anyway to limit/control the potency of the wifi device of my smartphone ?
The WifiManager exposes the public WifiManager.WifiLock createWifiLock (int lockType, String tag) method to allow for the application to claim a lock on the Wi-Fi in a certain mode, however, this is no mode that allow for the power to be decreased. So the answer to your question is no.

get dbm wifi signal strength from home access point

I have been trying to create an android application that will give me the signal strength of my home access point from a wireless device e.g. laptop, mobile phone. I have been pulling my hair out with it the last few days and been getting no where. Can someone please give a hand with this because it is really getting on my nerves :( all I want it to do at the minute is display the strength in the console for me, it sounded pretty simple and I have read countless articles and have got nowhere at all :(
You can get the dbm value using WifiManager.
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if(wifiManager.isWifiEnabled()) {
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if(wifiInfo != null) {
int dbm = wifiInfo.getRssi();
}
}
In addition to dbm, if you wish to get the percentage about the signal strength:
int strengthInPercentage = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), 100);

Categories

Resources