From 3237bbf9b17125b1be24cedf4a2e81a705267db3 Mon Sep 17 00:00:00 2001 From: cweinhofer <7067427+cweinhofer@users.noreply.github.com> Date: Sun, 7 Jun 2020 17:52:02 -0400 Subject: [PATCH] Update GetChipID.ino --- .../examples/ChipID/GetChipID/GetChipID.ino | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/libraries/ESP32/examples/ChipID/GetChipID/GetChipID.ino b/libraries/ESP32/examples/ChipID/GetChipID/GetChipID.ino index de8a7386b93..3a5f3243870 100644 --- a/libraries/ESP32/examples/ChipID/GetChipID/GetChipID.ino +++ b/libraries/ESP32/examples/ChipID/GetChipID/GetChipID.ino @@ -1,14 +1,30 @@ -uint64_t chipid; +/* The true ESP32 chip ID is essentially its MAC address. +This sketch provides an alternate chip ID that matches +the output of the ESP.getChipId() function on ESP8266 +(i.e. a 32-bit integer matching the last 3 bytes of +the MAC address. This is less unique than the +MAC address chip ID, but is helpful when you need +an identifier that can be no more than a 32-bit integer +(like for switch...case). + +created 2020-06-07 by cweinhofer +with help from Cicicok */ + +uint32_t chipId = 0; void setup() { Serial.begin(115200); } void loop() { - chipid=ESP.getEfuseMac();//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. + for(int i=0; i<17; i=i+8) { + chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i; + } - delay(3000); + Serial.print("ESP8266-Style Chip ID: "); + Serial.println(chipId); + Serial.println(); + + delay(5000); }