ESP32 how to read the MAC Adress

For general Flowcode discussion that does not belong in the other sections.
Post Reply
stefan.erni
Valued Contributor
Posts: 1106
http://meble-kuchenne.info.pl
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 209 times
Been thanked: 229 times

ESP32 how to read the MAC Adress

Post by stefan.erni »

Hi to All

in the supplemetary code I includet

#include "esp_mac.h"

In the main I creat a variable Byte MAC[6]
and a c-code:

Code: Select all

esp_efuse_mac_get_default(FCV_MAC);
But I get not the mac adress in MAC[0]...MAC[5]

mnfisher
Valued Contributor
Posts: 1693
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 146 times
Been thanked: 789 times

Re: ESP32 how to read the MAC Adress

Post by mnfisher »

The read should work AOK - I tested on a esp32-wrooom - and the result looks okay....

This just outputs the MAC to UART..

Martin
Attachments
esp32_ReadMAC.fcfx
(11.21 KiB) Downloaded 28 times

stefan.erni
Valued Contributor
Posts: 1106
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 209 times
Been thanked: 229 times

Re: ESP32 how to read the MAC Adress

Post by stefan.erni »

Hi Martin

Yes perfect!
It's working on two ESP32 wroom:
read from first ESP32 wroom:
MAC address A0:B7:65:60:55:40
read from second ESP32 wroom:
MAC address A0:B7:65:6C:74:EC

on my program was the handle from the string.
I suspect that some string functions do not work with string bigger than [20] on the ESP32.
I changed it a little and now it works with my program.
I will test the string functions I used before and post if I find one with problems.

Code: Select all

MAC_strg1 = NumberToHex$(MAC[0])
MAC_strg1 = RemoveFromString$(MAC_strg1,2,0)
mac_string = MAC_strg1 + ":"

MAC_strg2 = NumberToHex$(MAC[1])
MAC_strg2 = RemoveFromString$(MAC_strg2,2,0)
mac_string = mac_string + MAC_strg2 + ":"

MAC_strg3 = NumberToHex$(MAC[2])
MAC_strg3 = RemoveFromString$(MAC_strg3,2,0)
mac_string = mac_string + MAC_strg3 + ":"

MAC_strg4 = NumberToHex$(MAC[3])
MAC_strg4 = RemoveFromString$(MAC_strg4,2,0)
mac_string = mac_string + MAC_strg4 + ":"

MAC_strg5 = NumberToHex$(MAC[4])
MAC_strg5 = RemoveFromString$(MAC_strg5,2,0)
mac_string = mac_string + MAC_strg5 + ":"

MAC_strg6 = NumberToHex$(MAC[5])
MAC_strg6 = RemoveFromString$(MAC_strg6,2,0)
mac_string = mac_string + MAC_strg6 + ":"



mnfisher
Valued Contributor
Posts: 1693
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 146 times
Been thanked: 789 times

Re: ESP32 how to read the MAC Adress

Post by mnfisher »

Hi Stefan,

Default string size is 20 - and if somewhere there is a 'make a copy' box checked that might explain things? Passing strings by reference (not copying them) is usually the preferred option - and quicker too - but the default seems to be to pass by value.

Martin

stefan.erni
Valued Contributor
Posts: 1106
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 209 times
Been thanked: 229 times

Re: ESP32 how to read the MAC Adress

Post by stefan.erni »

Hi Martin

Yes, I haven't made all the strings that long now.
And it's working nice.
But I have a small issue with the UART.
The red data is without a interrupt, the green data with an interrupt in the program .
This interrupt is doing nothing but the the data I send is thisway ok
I don't know why I have these problem but i just add it.
My program:
esp32_ReadMAC_macro_FC11.fcfx
(15.45 KiB) Downloaded 23 times
Test on terminal program:
The red data is without interrupt, the green with interrupt,
2025-10-24_15-49-41.PNG
2025-10-24_15-49-41.PNG (38.01 KiB) Viewed 379 times
2025-10-24_15-51-35.PNG
2025-10-24_15-51-35.PNG (61.88 KiB) Viewed 379 times

mnfisher
Valued Contributor
Posts: 1693
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 146 times
Been thanked: 789 times

Re: ESP32 how to read the MAC Adress

Post by mnfisher »

I can't replicate the issue (I think you've mentioned it before) - I tried PuTTY and idf.py - p COM6 -b 115200 monitor - and both work as expected with / without the interrupt.

Which terminal program are you using? There is definitely some repeated data that is 'correct' (A0:B7:) - but then everything goes a bit awry. Try a different terminal prog - see if you get the same issue?

Martin

stefan.erni
Valued Contributor
Posts: 1106
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 209 times
Been thanked: 229 times

Re: ESP32 how to read the MAC Adress

Post by stefan.erni »

Hi Martin

It look like a problem on my computers

That's not such a big problem, I always use an IRQ in my program. However, I shouldn't send any data before I activate it.

With IRQ:
2025-10-27_10-59-08.PNG
2025-10-27_10-59-08.PNG (25.45 KiB) Viewed 249 times
Without IRQ:
2025-10-27_11-01-11.PNG
2025-10-27_11-01-11.PNG (32.95 KiB) Viewed 249 times
I created a program for AppDevelopper FC11 to obtain the characters.
Terminal_FC11.fcpcd
(12.73 KiB) Downloaded 10 times
and improved the macro a little:
esp32_ReadMAC_macro_FC11.fcfx
(15.99 KiB) Downloaded 8 times

Post Reply