Page 1 of 1

Partial mac address ?

Posted: Thu Jan 16, 2020 5:46 pm
by uxhamby
MicroPython v1.12-58-g7ef2f6511 on 2020-01-12; ESP32 module with ESP32

OK, so I am reading the docs at:
bottom of the page where they suggest that
print(nic.config('mac'))
should return the mac address of the 'nic' interface.

When I run it however, I get only part of the mac in response:
b'$b\xab\xd4\xce\xe8'
My device's nic is actually
24: 62: ab: d4: ce: e8
.


So, what's up with that?

Thanks,

Brian H.

Re: Partial mac address ?

Posted: Thu Jan 16, 2020 5:58 pm
by MostlyHarmless
The dollar sign at the beginning is one byte, the 'b' the second, followed by four bytes that don't have a corresponding ascii character and are therefore displayed in their \x representation.


Regards, Jan

Re: Partial mac address ?

Posted: Thu Jan 16, 2020 6:26 pm
by uxhamby
Yes, I understand now. Thanks!

Brian H.

Re: Partial mac address ?

Posted: Thu Jan 16, 2020 7:22 pm
by cgglzpy
Hi, just mention that MicroPython introduced a separator option for binascii.hexlify function which is quite nice for this case:

Code: Select all

>>> from binascii import hexlify
>>> hexlify(b'$b\xab\xd4\xce\xe8', ':')
b'24:62:ab:d4:ce:e8'
Or

Code: Select all

>>> hexlify(b'$b\xab\xd4\xce\xe8', ':').decode()
'24:62:ab:d4:ce:e8'
In case you want a string.

Re: Partial mac address ?

Posted: Thu Jan 16, 2020 9:43 pm
by MostlyHarmless
cgglzpy wrote:
Thu Jan 16, 2020 7:22 pm
Hi, just mention that MicroPython introduced a separator option for binascii.hexlify function ...
Neat, thanks!