I am trying to run following code:
#include <WiFi.h>
void setup() {
//int16_t scanNetworks(bool async = false, bool show_hidden = false, bool passive = false, uint32_t max_ms_per_chan = 300, uint8_t channel = 0, const char * ssid=nullptr, const uint8_t * bssid=nullptr);
int n = WiFi.scanNetworks(true, false, false, 5, 7, "HTM");
Serial.begin(115200);
delay(10); // Minimum 10 milliseonds delay required to reliably receive message from Gateway.
for (int i = 0; i < 4; i++)
{
uint8_t values[4];
values[i] = WiFi.BSSID(0)[i];
}
}
void loop() { }
but I get an Arduino compile error (call of overloaded 'BSSID(int)' is ambiguous):
C:\Users\ebhynes\AppData\Local\Temp\arduino_modified_sketch_647803\sketch_apr04a.ino: In function 'void setup()':
sketch_apr04a:17:29: error: call of overloaded 'BSSID(int)' is ambiguous
17 | values[i] = WiFi.BSSID(0)[i];
| ~~~~~~~~~~^~~
In file included from C:\Users\ebhynes\AppData\Local\Arduino15\packages\esp32\hardware\esp323円.2.0\libraries\WiFi\src/WiFi.h:34,
from C:\Users\ebhynes\AppData\Local\Temp\arduino_modified_sketch_647803\sketch_apr04a.ino:1:
C:\Users\ebhynes\AppData\Local\Arduino15\packages\esp32\hardware\esp323円.2.0\libraries\WiFi\src/WiFiSTA.h:171:12: note: candidate: 'uint8_t* WiFiSTAClass::BSSID(uint8_t*)'
171 | uint8_t *BSSID(uint8_t *bssid = NULL);
| ^~~~~
In file included from C:\Users\ebhynes\AppData\Local\Arduino15\packages\esp32\hardware\esp323円.2.0\libraries\WiFi\src/WiFi.h:36:
C:\Users\ebhynes\AppData\Local\Arduino15\packages\esp32\hardware\esp323円.2.0\libraries\WiFi\src/WiFiScan.h:52:12: note: candidate: 'uint8_t* WiFiScanClass::BSSID(uint8_t, uint8_t*)'
52 | uint8_t *BSSID(uint8_t networkItem, uint8_t *bssid = NULL);
|
What is the solution?
1 Answer 1
Here is a slightly pruned version of the error message. If you take the time to read it carefully, it should hint you at the origin of the problem:
error: call of overloaded 'BSSID(int)' is ambiguous
candidate: uint8_t *BSSID(uint8_t *bssid = NULL);
candidate: uint8_t *BSSID(uint8_t networkItem, uint8_t *bssid = NULL);
This means that the method expects, as parameters:
either an optional pointer (defaulting to
NULL
), which is the signature of the first candidateor a
uint8_t
number, optionally followed by a pointer (defaulting toNULL
), which is the second candidate.
Since you called it with the single parameter 0
, which is an int
,
the compiler does not know whether you meant for this parameter to be a
pointer (first candidate) or a uint8_t
(second candidate).
The solution is to be explicit about the type. Presumably:
values[i] = WiFi.BSSID(uint8_t(0))[i];
values[i] = WiFi.BSSID( ((uint8_t) 0)[i];
to remove the ambiguity. not your error. they have a wrong API design0
an integer and a pointer. :-D The issue comes up only because of the literal value0
. However, a good API would strive to work around.