Hi everyone,
is there a way to get the hardware ID of the chip from micropython? We have a project, were we want to identify some dozen micro:bits.
Thanks guys.
Hardware ID
-
- Posts: 363
- Joined: Sun Apr 17, 2016 1:55 pm
Re: Hardware ID
in ESP8266 and STM32 port, in machine mudule, it can get ID use machine.unique_id(). But microbit doesn't has this feature.
Re: Hardware ID
I have an ESP8266 on an Adafruit HUZZA board and ran it:
I searched for a way to make the byte string more human readable but could only come up with this:
Is there some other method to make the byte string more readable? I was thinking maybe a string of hex values without the \x
Thanks
Code: Select all
>>> import machine
>>> machine.unique_id()
b'~\xd8\xc6\x00'
>>>
Code: Select all
>>> machine.unique_id().decode("utf-8")
'~\x18\x06\x00
Thanks
Re: Hardware ID
That's a string of binary bytes. You can get a hex version by doing something like this:
You could also do something like:
Code: Select all
>>> import ubinascii
>>> ubinascii.hexlify(b'~\xd8\xc6\x00')
b'7ed8c600'
>>> ubinascii.hexlify(b'~\xd8\xc6\x00').decode('utf-8')
'7ed8c600'
Code: Select all
>>> id = b'~\xd8\xc6\x00'
>>> '{:02x}{:02x}{:02x}{:02x}'.format(id[0], id[1], id[2], id[3])
'7ed8c600'