It's just a few days since I started using Arduino IDE ( programming an ESP32 ). As I learn, I am trying to write some snippets. I wanted to store the Chip ID of ESP32 into a variable (preferably string?) so that I can generate an unique device name. I looked through the ESP32 example programs and came across this program which just prints the Chip ID to the serial console.
uint64_t chipid; 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.
Now this works fine but I needed to store it into a variable in the following format "ESP32-0A1B3C4D5E6F" ( the last part of which is the Chip/MAC ID which is 6 bytes ). I went about some reading and currently reading and managed to get this far
char ssid1; char ssid2; uint64_t chipid = ESP.getEfuseMac(); // The chip ID is essentially its MAC address(length: 6 bytes). uint16_t chip = (uint16_t)(chipid >> 32); snprintf(ssid1, 15, "%04X", chip); snprintf(ssid2, 15, "%08X", (uint32_t)chipid); Serial.print(ssid1); Serial.println(ssid2);