How network.WLAN reports a mac address

The official PYBD running MicroPython, and its accessories.
Target audience: Users with a PYBD
Post Reply
Jim.S
Posts: 84
Joined: Fri Dec 18, 2015 7:36 pm

How network.WLAN reports a mac address

Post by Jim.S » Sun Jun 23, 2019 8:18 pm

I'm just starting to play with my pyboard-D and I am a bit confused how it reports mac addresses. for instance,
>>> w.config('mac')
b'HJ0\x01\xb2\xd0'

I understand that the b' means that it is a byte string and that the H means they are unsigned short integers, but I dont understand why there only seem to be three integers in the mac address. I am used to seeing mac addresses as a group of six integers in hexadecimal, like this, ab:cd:ef:12:34:56. I have just learnt from the internet that the first three integers in a mac address identify the manufacturer, is that why the w.config('mac') only reports three integers? Is the J0 something to do with the manufacturers OUI code? (OUI={Organizationally Unique Identifier}

User avatar
Roberthh
Posts: 1569
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: How network.WLAN reports a mac address

Post by Roberthh » Sun Jun 23, 2019 9:05 pm

The byte string is all bytes, 6 in total. H is just a byte with the hex value 0x48, J is 0x49, 0 is 0x30, so all in all it is:
48:49:30:01:b2:d0. To see the usual representation, you can convet it to hex using ubinascii.hexlify()

User avatar
pythoncoder
Posts: 3538
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: How network.WLAN reports a mac address

Post by pythoncoder » Wed Jun 26, 2019 6:33 am

Code: Select all

>>> mac = b'HJ0\x01\xb2\xd0'
>>> '{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}'.format(*mac)
'48:4a:30:01:b2:d0'
>>> 
Peter Hinch

Post Reply