Giga R1; Retrieve MAC address without WiFi connection

I think this is my first time posting to these forums so please forgive me for any lack of typical/customary requirements.

I have a Giga with the DisplayShield. I have been able to use an older version of the LVGL library for UI based user-friendly configuration/navigation. I have managed to get a user configurable WiFi connection (through the lvgl library UI) working and have managed to be able to store configuration information through the kv_store library, retrieve by ntp and set the UTC time when available, and write a log file to an attached USB pen drive.

I plan to have multiples of these devices for managing systems across multiple customers that will need to be individually tracked. For the first iteration of this I want to use the built-in WiFi MAC address as a temporary serial number to keep customers' data separated. I understand that MAC addresses aren't truly unique but it's close enough for startup.

My question is; is it even possible to retrieve the built-in WiFi's MAC address WITHOUT/BEFORE an active WiFi connection to an AP. I have already tried both overloaded calls to WiFi::macAddress and neither work until WiFi connects. I need it before WiFi connects or is even available so I can insert it into the log file.

Overloads:
uint8_t* macAddress(uint8_t* mac);
String macAddress();

Again, neither work until AFTER a WiFi connection has been established (I already tried both before posting here), I need it before that. Is it possible? Is there a library-less work-around instead?

I'm a bit confused. How will you access the remote device to retrieve this information if it is not connected to WiFi? Alternatively, you could use one of the Dallas temperature sensors. Each sensor has a unique serial number, which could help identify the device.

Instead you could use the MCU unique serial number returned by this function in variant.cpp

uint8_t getUniqueSerialNumber(uint8_t* name) {
  utox8(HAL_GetUIDw0(), &name[0]);
  utox8(HAL_GetUIDw1(), &name[16]);
  utox8(HAL_GetUIDw2(), &name[32]);
  return 48;
}

update: scratch that for the moment, not working for me - investigating

update: getUniqueSerialNumber always returns zero (I'll raise a git issue) but HAL_GetUIDw0(), HAL_GetUIDw1() and HAL_GetUIDw2() strung together is unique - if that's of any use.

C:\Users\User\Documents\Arduino\agsmac\SerialNumber.cpp: In function 'uint8_t getUniqueSerialNumber(uint8_t*)':
C:\Users\User\Documents\Arduino\agsmac\SerialNumber.cpp:12:3: error: 'utox8' was not declared in this scope
utox8(HAL_GetUIDw0(), &name[0]);
^~~~~
C:\Users\User\Documents\Arduino\agsmac\SerialNumber.cpp:12:3: note: suggested alternative: 'utoa'
utox8(HAL_GetUIDw0(), &name[0]);
^~~~~
utoa

exit status 1

Compilation error: 'utox8' was not declared in this scope

Found utox8 and copy/pasted it.

hmm shouldn't need to copy/paste. Is your board set to GIGA R1 in the IDE?

The getUniqueSerialNumber function is broken so I'd suggest using something like:


char sn[25];
snprintf(sn, sizeof(sn), "%08lX%08lX%08lX", HAL_GetUIDw0(), HAL_GetUIDw1(), HAL_GetUIDw2());

which will give you a unique string to work with

I realized that after compiling and seeing duplicate definitions of both. I also see that the function returns "0". I've copied them out and added _ex to the end and I'm trying to figure out what's going on.

I think I may have found it inside of utox8:
int d = val & 0XF; the X is capitalized, as I understand what's being attempted it shouldn't be.

I've given up on trying to sort out the mess with utox8, nothing works the way it's written.

I've gone ahead and implemented the snprintf solution.

If you take a look at the Arduino team response to the git issue I raised it'll explain how it's setup to work. For my purposes the snprintf option is simpler.

No. Both 0X and 0x are valid prefixes on hexadecimal literals:

https://en.cppreference.com/w/cpp/language/integer_literal#:~:text=the%20character%20sequence%200x%20or%20the%20character%20sequence%200X

  • hex-literal is the character sequence 0x or the character sequence 0X followed by one or more hexadecimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, A, b, B, c, C, d, D, e, E, f, F)

I'd never seen that before, it immediately stood out to me the moment I scanned the code for any obvious errors. But, well, whatever I guess.