Skip to content

Add ESP.getChipId() function to get ESP32's ChipID. #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 5, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cores/esp32/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,11 @@ bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size)
{
return spi_flash_read(offset, (uint32_t*) data, size) == ESP_OK;
}


uint64_t EspClass::getChipId(void)
{
uint64_t _chipid;
esp_efuse_read_mac((uint8_t*) (&_chipid));
return _chipid;
}
2 changes: 2 additions & 0 deletions cores/esp32/Esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class EspClass
bool flashWrite(uint32_t offset, uint32_t *data, size_t size);
bool flashRead(uint32_t offset, uint32_t *data, size_t size);

uint64_t getChipId();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like you to rename the method to getEfuseMac() because the name is misleading :) I get that ESP8266 has this method and that the result could be interpreted as unique id of the chip, but still this is not the chip id that ESP8266 have.


};

extern EspClass ESP;
Expand Down
14 changes: 14 additions & 0 deletions libraries/ESP32/examples/ChipID/GetChipID/GetChipID.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
uint64_t chipid;

void setup() {
Serial.begin(115200);
}

void loop() {
chipid=ESP.getChipId();//The chip ID is essentially its MAC address(length: 6 bytes).
Serial.printf("ESP32 Chip ID = %04X",(uint16_t)(chipid>>32));//print High 2 bytes
Serial.printf("%08X\n",(uint32_t)chipid);//print Low 4bytes.

delay(3000);

}