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

fixed network scan #2906

Merged
merged 5 commits into from
Oct 31, 2024
Merged

fixed network scan #2906

merged 5 commits into from
Oct 31, 2024

Conversation

pljakobs
Copy link
Contributor

esp_wifi_scan_get_ap_records() clears the ap data structure, so calling esp_wifi_scan_get_ap_num() after it will return zero. Switching the order fixes the error of Sming WifiStation.scan() not returning any networks on the esp32 platform

Copy link

what-the-diff bot commented Oct 31, 2024

PR Summary

  • Improved Order of Function Calls
    The sequence of operations has been updated. Now, the first operation is gauging the number of access points (the places from which users connect to our system), known as 'ap_count'. The second operation involves collecting detailed information about these access points 'ap_info'. This change enhances system flow, verifying the quantity before delving into specifics.

@pljakobs
Copy link
Contributor Author

this should fix #2905

@slaff slaff added this to the 6.0.0 milestone Oct 31, 2024
@slaff slaff requested a review from mikee47 October 31, 2024 09:09
Comment on lines 423 to 424
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&number, ap_info));
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(&ap_count));
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&number, ap_info));
Copy link
Contributor

@mikee47 mikee47 Oct 31, 2024

Choose a reason for hiding this comment

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

The call to esp_wifi_scan_get_ap_num is actually redundant since it's returned from esp_wifi_scan_get_ap_records:

memset(ap_info, 0, sizeof(ap_info));
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&number, ap_info));
// TODO: Handle hidden APs
for(unsigned i = 0; i < number; i++) {
  list.addElement(new BssInfoImpl(&ap_info[i]));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i was wondering about this and under which conditions the number of detected SSIDs and APs are different, especially, when the number of APs would be less than the number of SSIDs, but since this is the code that the ESP_IDF suggests, I thought it was "the right way"
I can drop the esp_wifi_scan_get_ap_num() call and replace ap_count with number where necessary (or actually use a variable that is a bit more descriptive)

// TODO: Handle hidden APs
for(unsigned i = 0; (i < event->number) && (i < ap_count); i++) {
for(unsigned i = 0; (i < event->number); i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this loop should use number instead of event->number as it's the more recently aquired value. Presumably these values should always be the same, so could include an assert(number == event->number) but I think that's overkill.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack, especially as it's unclear if esp_wifi_scan_get_ap_records changes number and what it would mean if those diverge

Copy link
Contributor

@mikee47 mikee47 left a comment

Choose a reason for hiding this comment

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

Lovely, thank you for the fix!

@pljakobs
Copy link
Contributor Author

Lovely, thank you for the fix!

thank you for your support

@slaff slaff merged commit 78e70fe into SmingHub:develop Oct 31, 2024
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants