LATER
I have now written a WiFiConnectSta() function to connect to the strongest of the networks matching the ssid.
I am doing this using Sloeber IDE 4.2 and I am having some problems with its checking of the source code...
Here is my function (not yet tested on the real hardware):
bool ConnectWiFiSta(char *ssid, char *passwd)
{
int i, j, m;
bool ret = false;
bool found = false;
uint8_t mac[6];
int32_t level, channel;
SerialDebug.print("Starting WiFi scan to check availability at T="); SerialDebug.println(millis());
m = WiFi.scanNetworks(); //Return network count.
SerialDebug.print("Processing scan result at T="); SerialDebug.println(millis());
if (m > 0) //Networks found
{
for (i = 0; i < m; i++) //Check if ssid compares
{
if (strcmp(ssid, WiFi.SSID(i).c_str()) == 0) //We have a match!
{
if (!found) //First match so grab whetever comes along
{
for (j = 0; j<6; j++) mac[j] = WiFi.BSSID(i)[j];
level = WiFi.RSSI(i);
channel = WiFi.channel(i);
found = true; //Only once here...
}
else if (WiFi.RSSI(i) > level) //A new match is stronger
{
for (j = 0; j<6; j++) mac[j] = WiFi.BSSID(i)[j];
level = WiFi.RSSI(i);
channel = WiFi.channel(i);
}
}
}
if (found)
{
//So we have checked the networks and have a good strength match
//Now connect:
WiFi.begin(ssid, passwd, channel, mac, true);
ret = true;
}
}
return (ret);
}
It compiles OK, but Sloeber shows an error marker on each line dealing with the array of scan result, such as:
level = WiFi.RSSI(i);
All in all there are 8 such error bombs in the left side margin.
Apparently Sloeber cannot figure out that there is an overload where there is an index inside the call like (i).
What can I do to fix this?