Reputation: 245
I am looking into printing out the MAC address of an ESP32 board. The Arduino Examples define it by the following:
uint64_t chipid=ESP.getEfuseMac();//The chip ID is essentially its MAC address(length: 6 bytes).
Serial.printf("ESP32 Chip ID = %04X",(uint16_t)(chipid>>32));//print High 2 bytes
Serial.printf("%08X\n",(uint32_t)chipid);//print Low 4bytes.
However, I found the following way to do it:
uint64_t chipId = ESP.getEfuseMac();
Serial.printf("%" PRIx64 "\n", chipId);
The second way is obviously more verbose, however, while looking online, I never found such an example with the Arduino boards. Is there a memory issue that way and if so - what?
Upvotes: 2
Views: 1988
Reputation: 31
If anyone's interested have a working header and source files that supports 64-bit int and long double printing natively. The code simply overloads the print()
and println()
functions to include these types. You can down the files here: https://github.com/Michael-Brodsky/PG/tree/main/hardware/avr
You'll need to replace the equivalent files supplied with the Arduino IDE (avr-libc), so I recommend making backups.
Upvotes: 0
Reputation: 5161
64-bit printf() support was added end of 2016 (I think) and the example seems to predate that. The PRIx64
is the correct way to print a 64-bit number.
See also https://github.com/espressif/esp-idf/issues/52
Upvotes: 3