ESP UID or not UID

I need to have an ID of an ESP8266. Until now, I just add one in EEPROM. But wonder if I can use UID from the ESP8266 himself. By reading a bunch of articles over the internet, I found some data that is a little bit confusing.

First of all, according to this:
https://bbs.espressif.com/viewtopic.php?t=1303
It looks like ID is just the last part of the MAC address. Also, it is not unique as in the time to come, there could be more chips with the same ID. Which is weird.

The second thing...
With:
Serial.println(WiFi.macAddress());
I get something (say) like this:
A8:48:FA:EF:FD:00

With:
Serial.printf("chip id:\t%08X\n",ESP.getChipId());
I get something like this:
chip id: 00EFFD00

But with this:
Serial.println(ESP.getChipId());
I get some 8 numbers that do not match with the MAC address.

Any light here, please.

Please post your test sketch and what you actually see printed rather than "something like" what you see

The only difference may be that the MAC address is being printed with colon separators

Code is nothing special. But as you wish...

#include <ESP8266WiFi.h>
void setup() {
  Serial.begin(9600);
  Serial.println();
  Serial.println(WiFi.macAddress());
  Serial.println();
  Serial.printf("chip id:\t%08X\n",ESP.getChipId());
  Serial.println();
  Serial.println(ESP.getChipId());
  Serial.println();
}
void loop() {
}

A8:48:FA:EE:FD:E7

chip id: 00EEFDE7

15662567

If you try this you can see that the chip ID seems to be the last 4 bytes of the MAC address

#include <ESP8266WiFi.h>

void setup()
{
  Serial.begin(115200);
  Serial.println("\n");
  Serial.println(WiFi.macAddress());
  Serial.println(ESP.getChipId(), HEX);
}

void loop()
{
}

Yes, I tried this, too. But, is it UID, or just ID?

It is hardly going to be very unique and as it is only the last 3 bytes, not 4 as a I suggested

Why not use the MAC address ?
I know that it can be changed in software but read it before it is changed to uniquely identify the chip

I can always use my own stored in the EEPROM. Just thought it could be easier to use built-in.

What if I want to use this ID? Say I want to put it into a String (here comes the shi... string storm). I can not just make it like this:
String espID = ESP.getChipId(), HEX;

What do you want to use it for ?

Just trying a thing or two. Thought it could be useful after all.

Interesting...
This:
String x = String(ESP.getChipId(), HEX);
Serial.println(x);

returns
acb6dd

and this:
Serial.println(ESP.getChipId(), HEX);

returns this:
ACB6DD

Does it need to be a String to use it for what you have in mind ? Do you really need to convert it to a String is what I am getting at ?

Come to that, does it need to be expressed in Hex ?

Of course, it doesn't. As I said, this is just to understand how things go. But String is one of those things.

OK. You have found out how to turn the ID into a String. How what ?

Not sure what causes the difference between these two outputs... A is not a.

Use of capitals for hex values is a convention, not a requirement

Bear in mind that hex is a method of displaying data to make it easier for humans to read and that the underlying data is held as a series of bits in bytes unless the hex data is actually held as characters, in which case you can't do maths or comparisons with it as you can with raw data

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.