-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
Add limit for returning the first 12 access points with high rssi #387
base: main
Are you sure you want to change the base?
Conversation
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.
@fabik111 just a little clarification about growth: anything that grows logarithmic-ally
grows less than linear.
That is impossible for any container: for 1 element (big as "space") the vector needs at least 1 space, for 2 elements at least 2 spaces, for 3 elements at least 3 spaces and
so on (this is a linear growth).
If the growth would be logarithmic-ally that would mean that for 100 elements less
than 100 spaces were required (which is obviously impossible).
What you mentioned in your PR said that "reallocations should only happen at
logarithmic-ally growing intervals of size" which has a completely different meaning
(although it is related to the fact that to store n elements more than n-space can be allocated, so the growth is more than linear and definitely more than logarithmic).
Your concern about saving memory is really appreciable, but is always
risky: what if you are in a environment with a lot of (good) Wifi Network available
and you have to connect with the 13-th RSSI strongest network? You cannot connect to the network. Did you run out memory due to the presence of so many Wifi Network?
Or is just a concern? That is something to think about with this kind of PR.
Last but most important your code does not work: my understanding is that you want to select the 12 strongest Wifi Networks, but your code does not achieve this result. I have tried it.
Here is the output of your algorithm (I limited the number of network to 4)
with some made up values:
adding AP with RSSI 384
adding AP with RSSI 887
adding AP with RSSI 778
adding AP with RSSI 916
adding AP with RSSI 2004
adding AP with RSSI 2005
adding AP with RSSI 2006
adding AP with RSSI 2007
adding AP with RSSI 2008
adding AP with RSSI 2009
ACCESS POINTS Selected:
384
887
778
2009
Clearly not the best 4 RSSI are selected.
Pay attention to the fact that
std::vector<CAccessPoint>::reverse_iterator rit = access_points.rbegin();
access_points.insert(rit.base(), ap);
is equivalent to
access_points.push_back(ap);
just with a more convolute syntax.
You can verify that with something like:
vector<int> v;
vector<int> w;
for(int i = 0; i < 10 ; i++){
auto rit = v.rbegin();
v.insert(rit.base(), i);
w.push_back(i);
}
for(int i = 0; i < 10 ; i++){
cout << v[i] << " " << w[i] << endl;
}
At the end the 2 vectors (w,v) are equal.
So you are always working on the last elements of the vector, but this does not allow you to select the strongest n Wifi Networks.
My personal suggestion, if really you run out of memory, is to completely revise the strategy: perhaps the access_points vector might be erased when is no more needed
(perhaps when the board is connected to a Wifi network, but this is something that needs to be investigated in deep to see if there are not side effects).
Thank you
Hello @maidnl, thank you for your review. About the problem: this is not a concern, but actually what happens.
For sure, as you mention, the solution proposed in the PR is not the best, maybe adding a new |
During the
WiFi.scanNetworks()
the access points found are stored on avector
container.The allocation of memory for the
vector
doesn't grow linearly with the increasing of data stored, but logarithmically (view this ) and this can hang up the Arduino UNO R4 board for memory saturation when performing a scan inside an enviroment with many APs.This PR limits the number of element stored inside the vector for returning only the APs with the highest RSSI.