How to check and compare the MAC address (of an ESP32)

Dear all

I have tailored my sketch for three different ESP32. I would like to perform certain code only if the mac address corresponds with the respective hardware. How to do that?

Thanks a lot.

error: invalid operands of types ‘’ and ‘int’ to binary ‘operator==’

error: expected ‘)’ before ‘:’ token

void setup()
{
  Serial.begin(115200);
  WiFi.mode(WIFI_MODE_STA);
  Serial.println(WiFi.macAddress());
  if (WiFi.macAddress == 24:XX:YY:ZZ:66:55)
  {
  Serial.println("Hello, I am ESP32 No1");  
  }
}

WiFi.macAddress is a string.

You left out the '()' after the function name so you were trying to compare to the function address. The function returns a String which you can compare with a string literal.
Change:

if (WiFi.macAddress == 24:XX:YY:ZZ:66:55)

to

if (WiFi.macAddress() == "24:XX:YY:ZZ:66:55")

johnwasser:

if (WiFi.macAddress() == "24:XX:YY:ZZ:66:55")

Depends if OP plans to provide actual numbers for XX, YY, and ZZ. If he / she is thinking those form a match-anything wildcard, then it ain't going to work.

Thank you all very much for your help and explanations. It works now with the query corrected by johnwasser.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.