# Giga R1; Retrieve MAC address without WiFi connection

**URL:** <https://forum.arduino.cc/t/giga-r1-retrieve-mac-address-without-wifi-connection/1329739>\
**Category:** GIGA R1 WiFi\
**Created:** [December 6, 2024, 10:25pm UTC](https://forum.arduino.cc/t/giga-r1-retrieve-mac-address-without-wifi-connection/1329739 "2024-12-06T22:25:34Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![alphathinktink](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alphathinktink/32/303283_2.png) [@alphathinktink](https://forum.arduino.cc/u/alphathinktink)\
**Post date:** [December 6, 2024, 10:25pm UTC](https://forum.arduino.cc/t/giga-r1-retrieve-mac-address-without-wifi-connection/1329739/1 "2024-12-06T22:25:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![gilshultz](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gilshultz](https://forum.arduino.cc/u/gilshultz)\
**Post date:** [December 7, 2024, 3:01am UTC](https://forum.arduino.cc/t/giga-r1-retrieve-mac-address-without-wifi-connection/1329739/2 "2024-12-07T03:01:34Z")

</div>

> [@alphathinktink](#):
>
> Again, neither work until AFTER a WiFi connection has been established

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.

---

<div class="post-metadata">

**Author:** ![steve9](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/steve9/32/1098630_2.png) [@steve9](https://forum.arduino.cc/u/steve9)\
**Post date:** [December 7, 2024, 6:05am UTC](https://forum.arduino.cc/t/giga-r1-retrieve-mac-address-without-wifi-connection/1329739/3 "2024-12-07T06:05:28Z")

</div>

> [@alphathinktink](#):
>
> I understand that MAC addresses aren't truly unique but it's close enough for startup.

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

```arduino
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.

> <https://github.com/arduino/ArduinoCore-mbed/issues/1002>
>
> however HAL\_GetUIDw0, HAL\_GetUIDw1 and HAL\_GetUIDw2 do return the expected regis…ter values

---

<div class="post-metadata">

**Author:** ![alphathinktink](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alphathinktink/32/303283_2.png) [@alphathinktink](https://forum.arduino.cc/u/alphathinktink)\
**Post date:** [December 7, 2024, 3:27pm UTC](https://forum.arduino.cc/t/giga-r1-retrieve-mac-address-without-wifi-connection/1329739/4 "2024-12-07T15:27:04Z")

</div>

> [@steve9](#):
>
> Instead you could use the MCU unique serial number returned by this function in variant.cpp
> 
> ```arduino
> uint8_t getUniqueSerialNumber(uint8_t* name) {
> utox8(HAL_GetUIDw0(), &name[0]);
> utox8(HAL_GetUIDw1(), &name[16]);
> utox8(HAL_GetUIDw2(), &name[32]);
> return 48;
> }
> 
> ```

`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`

---

<div class="post-metadata">

**Author:** ![alphathinktink](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alphathinktink/32/303283_2.png) [@alphathinktink](https://forum.arduino.cc/u/alphathinktink)\
**Post date:** [December 7, 2024, 3:50pm UTC](https://forum.arduino.cc/t/giga-r1-retrieve-mac-address-without-wifi-connection/1329739/5 "2024-12-07T15:50:06Z")

</div>

Found utox8 and copy/pasted it.

---

<div class="post-metadata">

**Author:** ![steve9](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/steve9/32/1098630_2.png) [@steve9](https://forum.arduino.cc/u/steve9)\
**Post date:** [December 7, 2024, 5:09pm UTC](https://forum.arduino.cc/t/giga-r1-retrieve-mac-address-without-wifi-connection/1329739/6 "2024-12-07T17:09:57Z")

</div>

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:

```arduino

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

---

<div class="post-metadata">

**Author:** ![alphathinktink](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alphathinktink/32/303283_2.png) [@alphathinktink](https://forum.arduino.cc/u/alphathinktink)\
**Post date:** [December 7, 2024, 5:23pm UTC](https://forum.arduino.cc/t/giga-r1-retrieve-mac-address-without-wifi-connection/1329739/7 "2024-12-07T17:23:01Z")

</div>

> [@steve9](#):
>
> hmm shouldn't need to copy/paste. Is your board set to GIGA R1 in the IDE?

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.

---

<div class="post-metadata">

**Author:** ![alphathinktink](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alphathinktink/32/303283_2.png) [@alphathinktink](https://forum.arduino.cc/u/alphathinktink)\
**Post date:** [December 7, 2024, 5:28pm UTC](https://forum.arduino.cc/t/giga-r1-retrieve-mac-address-without-wifi-connection/1329739/8 "2024-12-07T17:28:41Z")

</div>

> [@alphathinktink](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![alphathinktink](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alphathinktink/32/303283_2.png) [@alphathinktink](https://forum.arduino.cc/u/alphathinktink)\
**Post date:** [December 9, 2024, 10:24pm UTC](https://forum.arduino.cc/t/giga-r1-retrieve-mac-address-without-wifi-connection/1329739/9 "2024-12-09T22:24:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![steve9](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/steve9/32/1098630_2.png) [@steve9](https://forum.arduino.cc/u/steve9)\
**Post date:** [December 10, 2024, 5:40am UTC](https://forum.arduino.cc/t/giga-r1-retrieve-mac-address-without-wifi-connection/1329739/10 "2024-12-10T05:40:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ptillisch](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@ptillisch](https://forum.arduino.cc/u/ptillisch)\
**Post date:** [December 10, 2024, 5:53am UTC](https://forum.arduino.cc/t/giga-r1-retrieve-mac-address-without-wifi-connection/1329739/11 "2024-12-10T05:53:54Z")

</div>

> [@alphathinktink](#):
>
> the X is capitalized, as I understand what's being attempted it shouldn't be.

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](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`)

---

<div class="post-metadata">

**Author:** ![alphathinktink](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alphathinktink/32/303283_2.png) [@alphathinktink](https://forum.arduino.cc/u/alphathinktink)\
**Post date:** [December 10, 2024, 3:39pm UTC](https://forum.arduino.cc/t/giga-r1-retrieve-mac-address-without-wifi-connection/1329739/12 "2024-12-10T15:39:50Z")

</div>

> [@ptillisch](#):
>
> No. Both `0X` and `0x` are valid prefixes on hexadecimal literals:
> 
> [Integer literal - cppreference.com](https://en.cppreference.com/w/cpp/language/integer_literal#:~:text=the%20character%20sequence%200x%20or%20the%20character%20sequence%200X)

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.
