33IoT WiFi Macaddress returns a different value than several external BTooth scanners

When running simple code as follows, the WiFi Macaddress does not match with any external scanned macaddress of the device ... The 33IoT Device delivers 3C:71:BF:87:CA:E8, whereas any external scanner device delivers 3C:71:BF:87:CA:EA

#include <WiFiNINA.h>
#include <SPI.h>

void setup() {
  Serial.begin(9600);
  while (!Serial);

  // initialize WiFi
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("WiFi module not found");
    while (true);
  }

  // print MAC address:
  byte mac[6];
  WiFi.macAddress(mac);
  Serial.println("MAC: ");  
  printMacAddress(mac);
  while(1);
}

void loop() 
{
  // code here
}

void printMacAddress(byte mac[6]) 
{
  char buffer[9];
  for (int i = 5; i >= 0; i--) 
  {
    if (mac[i] < 16) {
      Serial.print("0");
    }
    if (i >= 0)
    {
      Serial.print(":");
    }
    Serial.print(mac[i], HEX);Serial.print(" | ");Serial.print(mac[i], BIN);Serial.println(" | ");
    
  }
  Serial.println();
}

The output, is as follows :

The value delivered by any external scanner is as follows:

The WiFi MAC address returned by the WiFi.macAddress() function is the MAC address of the WiFi module, not the MAC address of the device itself. This is because the WiFi module has its own MAC address and communicates with the network using that address.

If you want to get the MAC address of the device, you can use the WiFiNINA.getDeviceMAC() function instead of WiFi.macAddress(). This function will return the MAC address of the device's WiFi chip, which should match the MAC address shown on the device's network settings.

Here's an example code that uses WiFiNINA.getDeviceMAC() to print the device's MAC address:

scssCopy code

#include <WiFiNINA.h>
#include <SPI.h>

void setup() {
  Serial.begin(9600);
  while (!Serial);

  // initialize WiFi
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("WiFi module not found");
    while (true);
  }

  // print MAC address:
  byte mac[6];
  WiFi.macAddress(mac);
  Serial.print("WiFi module MAC: ");
  printMacAddress(mac);

  WiFiNINA.getDeviceMAC(mac);
  Serial.print("Device MAC: ");
  printMacAddress(mac);

  while(1);
}

void loop() 
{
  // code here
}

void printMacAddress(byte mac[6]) 
{
  char buffer[9];
  for (int i = 5; i >= 0; i--) 
  {
    if (mac[i] < 16) {
      Serial.print("0");
    }
    if (i >= 0)
    {
      Serial.print(":");
    }
    Serial.print(mac[i], HEX);Serial.print(" | ");Serial.print(mac[i], BIN);Serial.println(" | ");
    
  }
  Serial.println();
}

With this code, you should see two MAC addresses printed in the Serial Monitor: the MAC address of the WiFi module and the MAC address of the device. The device MAC address should match the MAC address displayed in the device's network settings.

Dear hiibrarahmad, this simple solution makes me feel dumb - THX for you clear advice on the subject. Next time, I will investigate a little deeper before posting for support. THX again!

NOT working though - Error message as follows: 'WiFiNINA' was not declared in this scope

Installing and updating libraries

BTW - The issue is always on the last HEXA char of the mac-address.. e.g when 8, it changes to A in the external scanner. When C, it changes to E in the external scanner ... binary speaking, there is an issue with the second least significant bit of the binary equivalent HEXA last char ...

HEXA LAST char Binary equivalent
C => 1100 (Arduino IoT 33 N1)
E => 1110 (External Scanner)

8 => 1000 (Arduino IoT33 N2)
A => 1010 (External Scanner)

Well, after some research, the code does not work for an Arduino 33IoT. After asking "Mr Chat GPT" i got this answer:

I apologize for the confusion. The WiFiNINA library can be used to retrieve the MAC address of the WiFi module, not the Arduino board itself. Unfortunately, the SAMD21 processor used in the Arduino 33IoT does not have a built-in unique identifier like some other microcontrollers do, so it is not possible to directly retrieve the MAC address of the board.

However, it is possible to generate a unique identifier for the board by combining various hardware-specific characteristics such as the CPU serial number, flash memory size, and a random number. Here's an example code that generates a unique identifier for the Arduino 33IoT ......

Hence, somewhere there is a bug, either in the mac-address recovered by the external scanners or the function retrieving the mac-address, i.e. WiFi.macAddress() - This could be caused due to a miss-match between the function WiFi.macAddress() when displaying the data through the serial monitor if compared to the same data at the external scanner output ...

Please any comments on the subject - Is there anybody that may have been through the same issue with any suggestions?

its getting complicated

but i am also searching for that issue just give it a last try by lookiing this link

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