How can I pass the MAC address to Ethernet shield with leading zeroes?
I change the default MAC address from DEADBEEFFEED
to something like DEADBEEFFE01
. So I only change the last number from 0xED
to 0x01
. My board is communicating to a separate server and when I look at the MAC in that server, my board is listed as DEADBEEFFE1
.
It's not as simple as printing the MAC address with padded zeroes as the board is actually removing it.
I've looked at the Ethernet library and I saw that the mac is passed as an array of uint8_t
. I think that's why, the last number is read as 1 (which is correct) but passed as just that.
Is there a way for the MAC to pass leading zeroes?
-
20x01 is 1. the server prints it wrongJuraj– Juraj ♦2020年10月23日 06:43:10 +00:00Commented Oct 23, 2020 at 6:43
-
Yep, apparently, found out that it is the server that has a problem.noobiejp– noobiejp2020年10月23日 15:39:47 +00:00Commented Oct 23, 2020 at 15:39
1 Answer 1
Writing this in case someone in the future might be interested.
The values passed in the Ethernet library is correct. The last value, 0x01 must be 1 and is written correctly, 0x01
in the registers of the W5500 inside the Ethernet shield.
Where I've got it wrong is how I pass the MAC address to the server. I'm basically creating a string for a json message. In there, I've put %02x
to make sure that zeroes are padded.