A lightweight ESP32 library for securely storing and verifying a device’s Chip ID in NVS, ensuring that only authorized hardware can run your application.
- Automatic First-Time Registration – Stores the current Chip ID if none exists.
- Secure Verification – Compares stored ID with the current device’s ID on each boot.
- Unauthorized Device Lockout – Stops execution if the device is not recognized.
- Persistent Storage – Uses ESP32’s
Preferences(NVS) to store data across resets.
The following example shows how to:
- Retrieve the ESP32’s Chip ID.
- Use the
Authorizationclass to register or verify the device.
#include <Arduino.h>
#include <initAuthorization.h>
Authorization auth;
String getChipID()
{
uint64_t chipid = ESP.getEfuseMac(); // Unique 64-bit ID
char idStr[17];
sprintf(idStr, "%04X%08X",
(uint16_t)(chipid >> 32),
(uint32_t)chipid);
return String(idStr);
}
void setup()
{
Serial.begin(115200);
delay(1000);
String chipID = getChipID();
Serial.print("Device Chip ID: ");
Serial.println(chipID);
// Check authorization
if (auth.check(chipID))
{
Serial.println("✅ Device authorized. Running application...");
}
// If unauthorized, the library will halt execution
}
void loop()
{
// Your main code here
}Checks if the given Chip ID matches the stored one.
If no ID is stored, it will register the provided one.
Same as above, but accepts a C-style string.
Same as above, but accepts a std::string.
This project is licensed under the MIT License – see LICENSE for details.
Milad Nikpendar
GitHub: milad-nikpendar/initMemory
Email: milad82nikpendar@gmail.com