Obtaining mac address for portenta h7

Hello,

Quick question, how do I obtain the mac address of the portenta h7 device? I'm aware it has a wifi card but I don't know if there is an existing script that will help me get this?

Also the mac address is not written or stated in the Portenta box.

Thanks.

mbed get mac address

A bit unclear how to select ETH vs. WiFi (or do they use the same MAC address?)
Otherwise: use a network sniffer (WireShark) or Python script to figure out

Yes, I used wireshark and also I connected the board up to wifi and ran a basic arduino script to print out the mac address. Both methods gave the same results.

Thanks.

In the next version of the Board support package (or maybe a version after that), you will be able to change the mac address manually.

My suggestions:
I think, you can read from MCU a serial number, a unique ID.
Use this, so that every MCU has a different MAC address.

Even it works for me (I set in my project /FW always the MAC address),
maybe use such a unique S/N ID from MCU for MAC address (part of it).
Also different for ETH or WiFi as PHY.

I might be a bit tricky due to what I have seen:
there are STM HAL drivers setting the MAC address. But RTOS sets as well (at least it provides
on low level ETH functions such one).
So, there might be two places where the MAC address is defined.

I had the same issue when trying to obtain the Mac address of my Portenta H7 using the WiFi library WiFi.macAddress(). When calling WiFi.macAddress() within setup(), it would return a nonsense / default Mac address.

After some head scratching, I suspect the issue was due to my program handling the WiFi connection in a separate Thread to calling the WiFi.macAddress() function. From my testing, WiFi.macAddress() only returned the actual MAC address if WiFi.status() == WL_CONNECTED;

My solution was as follows:
Note: Ensure Portenta Bootloader and WiFi have been updated first.
Note: Im using the ThingerMbed lib which handles the Wifi connection, and establishes a connection with Thinger.io in a separate Thread, but the same should apply if just using WiFi.begin()

#include <ThingerMbed.h> 
#include <WiFi.h>
#include "arduino_secrets.h"

char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;        // your network password 
int status = WL_IDLE_STATUS; 

byte mac[6];  
int firstLoop = 1; //used to prevent Mac Address from printing more than once.

ThingerMbed thing(username, clientID, password); //I've removed the #includes for these inputs for clarity


void setup() {
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  } 

  String fv = WiFi.firmwareVersion();
  if (fv != "1.1.0") {
    Serial.print("WiFi firmware version: ");
    Serial.println(fv);
    Serial.print("Please upgrade the WiFi firmware");
  }
  
  thing.add_wifi(ssid, pass); // configure wifi network

  thing.start(); //Start Wifi connection and establish connection with Thinger.io in a separate Thread


void loop() {
// by including this if statement in the loop function ensures the loop code still executes while WiFi 
// connection is established on another Thread. MAC address is only printed if WiFi is connected. 
// The 'firstLoop' variable prevents the Mac address from being printed more than once. Its not ideal, but it worked for me. 
  if(firstLoop == 1 && WiFi.status() == WL_CONNECTED){ 
    WiFi.macAddress(mac);
    Serial.print("MAC: ");
    Serial.print(mac[5],HEX);
    Serial.print(":");
    Serial.print(mac[4],HEX);
    Serial.print(":");
    Serial.print(mac[3],HEX);
    Serial.print(":");
    Serial.print(mac[2],HEX);
    Serial.print(":");
    Serial.print(mac[1],HEX);
    Serial.print(":");
    Serial.println(mac[0],HEX);
    Serial.print("WiFi IP (local): ");
    Serial.println(WiFi.localIP());
    firstLoop = 2;
  }

//normal Loop() code here 

}

I checked the printed MAC address against that shown on my router. The Device MAC address listed on my WiFi routers device manager page checks out against the MAC address printed in the code.
I hope this helps