Skip to content
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

Update WiFiScan example to show more useful data #7378

Merged
merged 3 commits into from
Dec 21, 2022

Conversation

Rotzbua
Copy link
Contributor

@Rotzbua Rotzbua commented Oct 19, 2022

Description of Change

Update WiFiScan example to show more useful data.

  • Add channel to output.
  • Add type of encryption to output.
  • Format output as table.
  • Update outdated example description.

Since this example is part of the Arduino library I avoided to add IDF specific code.

Tests scenarios

  • Tested on ESP32-C3 Board.
  • Let CI compile.

Related links

Closes #7377

@VojtechBartoska VojtechBartoska added the Area: BT&Wifi BT & Wifi related issues label Oct 21, 2022
@VojtechBartoska
Copy link
Collaborator

@P-R-O-C-H-Y & @PilnyTomas Please help with the review.

@VojtechBartoska VojtechBartoska added the Type: Example Issue is related to specific example. label Oct 21, 2022
if (n == 0) {
Serial.println("no networks found");
} else {
Serial.print(n);
Serial.println(" networks found");
Serial.println("Nr | SSID | RSSI | CH | Encryption");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest changing this to accommodate 32 character SSID maximum to:

Serial.println( " # | SSID                             | RSSI | CH | Encryption" );

Suggest adding the following after the above to "pretty up" the output table:
Serial.println( "---------------------------------------------------------------" );

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will also suggest to add BSSID column to differentiate between APs with the same SSID

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@me-no-dev Should I increase the column size? The limitation was on purpose because it is easier to read a table row without a huge space between the columns. Most SSIDs were shorter than 15 chars on my test setup.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is an example, I recommend printing the whole SSID. I agree a shorter SSID field looks better, but that can be customized for each application. This is the header I use for printing WiFi list (debug use only):

Serial.println(" #                             SSID  BSSID              RSSI  Ch  Authmode  Rate" );
Serial.println("-----------------------------------------------------------------------------------" );

I print the full SSID with sprintf(ptr, "%32s ", AP->ssid[0] != 0 ? (const char *)AP->ssid : "<hidden>");.

* Add channel to output.
* Add type of encryption to output.
* Format output as table.
* Update outdated example description.
* Add `scanDelete()` as hint to free memory.
Copy link
Contributor

@PilnyTomas PilnyTomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote for accommodating the longer RSSIs
This is what it looks like for 32-char RSSI


4 networks found
Nr | SSID            | RSSI | CH | Encryption
 1 | Foo             |  -34 |  4 | WPA2
 2 | 0123456789abcdef0123456789abcdef |  -34 | 11 | WPA2
 3 | Bar             |  -76 |  4 | WPA2
 4 | 42              |  -87 |  4 | WPA2

Tip - use std::string (variable_white_space_length, ' ') to pad table dynamically - see it used here

@mrengineer7777
Copy link
Collaborator

Tip - use std::string (variable_white_space_length, ' ') to pad table dynamically

That's interesting. IMHO the field width specifier in printf/sprintf is even easier to use.
https://www.tutorialspoint.com/c_standard_library/c_function_sprintf.htm
e.g.
sprintf(buf, "%3u", 42)
sprintf(buf, "%32s", ssid.c_str())
sprintf(buf, "%-32s", ssid.c_str())
sprintf(buf, "%*s", width, ssid.c_str()) //I have not tried the variable width format specifier

@VojtechBartoska VojtechBartoska added the Resolution: Awaiting response Waiting for response of author label Nov 16, 2022
@VojtechBartoska VojtechBartoska added this to the 2.0.6 milestone Dec 14, 2022
@me-no-dev me-no-dev merged commit a6fefb2 into espressif:master Dec 21, 2022
@Rotzbua Rotzbua deleted the example branch December 17, 2023 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: BT&Wifi BT & Wifi related issues Resolution: Awaiting response Waiting for response of author Type: Example Issue is related to specific example.
Projects
Development

Successfully merging this pull request may close these issues.

Update WiFiScan example to show more useful data
8 participants