ftctechnh / ftc_app

FTC Android Studio project to create FTC Robot Controller app.
759 stars 3.17k forks source link

WiFi connection info display and logging #535

Open AlecHub opened 6 years ago

AlecHub commented 6 years ago

Request Driver Station to display WiFi signal level, link speed, and channel number. Useful for WiFi diagnostic purposes and to ensure team is using the assigned channel. Also request Robot Controller to log changes and/or anomalies in signal level, link speed, and channel number.

Relevant JDK APIs:

import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;

WifiInfo wifiInfo = wifiManager.getConnectionInfo();

int rssi = wifiInfo.getRssi();  // signal strength in dBm
int frequency = wifiInfo.getFrequency();  // connection frequency
int linkSpeed = wifiInfo.getLinkSpeed();  // link speed

// convert rssi to signal level from 0 to 10

int signalLevel = wifiManager.calculateSignalLevel(rssi, 11); 

// convert frequency to 802.11 channel number and band

double band;
int channel;

if (frequency >= 2412 && frequency <= 2472) 
{
   band = 2.4;
   channel = 1 + ((frequency - 2412) / 5);
} 
else if (frequency == 2484)
{
   band = 2.4;
   channel = 14;
}
else if (frequency >= 4915 && frequency <= 4980)
{
   band = 5.0;
   channel = 183 + ((frequency - 4915) / 5);
}
else if (frequency >= 5035 && frequency <= 5865)
{
   band = 5.0;
   channel = 7 + ((frequency - 5035) / 5);
}
else
{
   band = -1.0;
   channel = -1;
}
Windwoes commented 6 years ago

@AlecHub This would only work if FTC changes to use soft-AP instead of WiFi-Direct.

If wifiManager.getConnectionInfo(); is called when connected via WiFi-Direct, it will not return any useful information.

Additionally, WifiP2pManager does not provide a getConnectionInfo() method, so I'm afraid this is not possible.

AlecHub commented 6 years ago

Thanks FROGBots... I didn't realize that WifiManager and WifiInfo doesn't apply to WiFi-Direct connections. Good catch!