Partial mac address ?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
uxhamby
Posts: 34
Joined: Thu Nov 14, 2019 9:47 pm

Partial mac address ?

Post by uxhamby » Thu Jan 16, 2020 5:46 pm

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.

User avatar
MostlyHarmless
Posts: 166
Joined: Thu Nov 21, 2019 6:25 pm
Location: Pennsylvania, USA

Re: Partial mac address ?

Post by MostlyHarmless » Thu Jan 16, 2020 5:58 pm

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

uxhamby
Posts: 34
Joined: Thu Nov 14, 2019 9:47 pm

Re: Partial mac address ?

Post by uxhamby » Thu Jan 16, 2020 6:26 pm

Yes, I understand now. Thanks!

Brian H.

cgglzpy
Posts: 47
Joined: Thu Jul 18, 2019 4:20 pm

Re: Partial mac address ?

Post by cgglzpy » Thu Jan 16, 2020 7:22 pm

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.

User avatar
MostlyHarmless
Posts: 166
Joined: Thu Nov 21, 2019 6:25 pm
Location: Pennsylvania, USA

Re: Partial mac address ?

Post by MostlyHarmless » Thu Jan 16, 2020 9:43 pm

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

Post Reply