-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve WiFi scan result display #10253
Changes from 3 commits
1106c2a
1decd0e
1d4a341
bdd7151
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2067,9 +2067,6 @@ String HtmlEscape(const String unescaped) { | |
return result; | ||
} | ||
|
||
// Indexed by enum wl_enc_type in file wl_definitions.h starting from -1 | ||
const char kEncryptionType[] PROGMEM = "|||" D_WPA_PSK "||" D_WPA2_PSK "|" D_WEP "||" D_NONE "|" D_AUTO; | ||
|
||
void HandleWifiConfiguration(void) | ||
{ | ||
if (!HttpCheckPriviledgedAccess(!WifiIsInManagerMode())) { return; } | ||
|
@@ -2114,36 +2111,46 @@ void HandleWifiConfiguration(void) | |
} | ||
} | ||
|
||
// remove duplicates ( must be RSSI sorted ) | ||
String cssid; | ||
for (uint32_t i = 0; i < n; i++) { | ||
if (-1 == indices[i]) { continue; } | ||
cssid = WiFi.SSID(indices[i]); | ||
uint32_t cschn = WiFi.channel(indices[i]); | ||
for (uint32_t j = i + 1; j < n; j++) { | ||
if ((cssid == WiFi.SSID(indices[j])) && (cschn == WiFi.channel(indices[j]))) { | ||
DEBUG_CORE_LOG(PSTR(D_LOG_WIFI D_DUPLICATE_ACCESSPOINT " %s"), WiFi.SSID(indices[j]).c_str()); | ||
indices[j] = -1; // set dup aps to index -1 | ||
} | ||
} | ||
} | ||
|
||
//display networks in page | ||
for (uint32_t i = 0; i < n; i++) { | ||
if (-1 == indices[i]) { continue; } // skip dups | ||
uint32_t i = 0; | ||
while (i < n) { | ||
int32_t rssi = WiFi.RSSI(indices[i]); | ||
String ssid = WiFi.SSID(indices[i]); | ||
DEBUG_CORE_LOG(PSTR(D_LOG_WIFI D_SSID " %s, " D_BSSID " %s, " D_CHANNEL " %d, " D_RSSI " %d"), | ||
WiFi.SSID(indices[i]).c_str(), WiFi.BSSIDstr(indices[i]).c_str(), WiFi.channel(indices[i]), rssi); | ||
int quality = WifiGetRssiAsQuality(rssi); | ||
int auth = WiFi.encryptionType(indices[i]); | ||
char encryption[20]; | ||
WSContentSend_P(PSTR("<div><a href='#p' onclick='c(this)'>%s</a> (%d) <span class='q'>%s %d%% (%d dBm)</span></div>"), | ||
HtmlEscape(WiFi.SSID(indices[i])).c_str(), | ||
WiFi.channel(indices[i]), | ||
GetTextIndexed(encryption, sizeof(encryption), auth +1, kEncryptionType), | ||
quality, rssi | ||
ssid.c_str(), WiFi.BSSIDstr(indices[i]).c_str(), WiFi.channel(indices[i]), rssi); | ||
|
||
// Print SSID | ||
WSContentSend_P(PSTR("<div><a href='#p' onclick='c(this)'>%s</a><br><ul>"), | ||
HtmlEscape(ssid).c_str() | ||
); | ||
delay(0); | ||
|
||
int j = 0; | ||
String nextSSID = ""; | ||
// Handle all APs with the same SSID | ||
while((i+j) < n && (nextSSID = WiFi.SSID(indices[i+j])) == ssid) { | ||
// Update RSSI / quality | ||
rssi = WiFi.RSSI(indices[i+j]); | ||
int quality = WifiGetRssiAsQuality(rssi); | ||
// Color-code quality | ||
uint8_t colors[2] = { 0xFF, 0xFF }; | ||
if(quality > 50) { | ||
// Scale red component to go from yellow to green (full green) | ||
colors[0] = (0xFF * (100-quality))/50; | ||
} else { | ||
// Scale green component to go from red to yellow (full red) | ||
colors[1] = (0xFF * quality)/50; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can save even more here:
I would also suggest to avoid pure Yellow #FFFF00 which is not readable with light background. Maybe going for a darker version would still do it:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figured that most (all?) will run Tasmota in the standard configuration which seems to be a black background. This seems to be a wrong assumption and getting colors what are visible for all (e.g. green or orange background) is hard if not impossible. Removing the quality colors isn't much of a loss as the results are anyway sorted by RSSI (= quality) and I still think my improvement brings advantage to the display. Removing the color code, we're down to 597492 bytes so even less (8 bytes) than current There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// Print item | ||
WSContentSend_P(PSTR("<li title='%d dBm'>%s, CH %d, <span style='color:#%02X%02X00'>Quality %d%%</span></li>"), | ||
rssi, WiFi.BSSIDstr(indices[i+j]).c_str(), | ||
WiFi.channel(indices[i+j]), colors[0], colors[1], quality | ||
); | ||
j++; | ||
} | ||
// Skip all the duplicates | ||
i += j; | ||
|
||
WSContentSend_P(PSTR("</ul></div>")); | ||
|
||
} | ||
WSContentSend_P(PSTR("<br>")); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can save code with
String nextSSID;
You don't need to give it a value, is it still initialized.