Skip to content

milad-nikpendar/initAuthorization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔐 initAuthorization

Arduino Library Manager License: MIT GitHub release Author

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.


✨ Features

  • 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.

🚀 Usage Example

The following example shows how to:

  1. Retrieve the ESP32’s Chip ID.
  2. Use the Authorization class 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
}

🛠 API Reference

bool check(const String &chip_ID)

Checks if the given Chip ID matches the stored one.
If no ID is stored, it will register the provided one.

bool check(const char* chip_ID)

Same as above, but accepts a C-style string.

bool check(const std::string &chip_ID)

Same as above, but accepts a std::string.


🧾 License

This project is licensed under the MIT License – see LICENSE for details.

✍️ Author

Milad Nikpendar
GitHub: milad-nikpendar/initMemory
Email: milad82nikpendar@gmail.com

About

Keep your ESP32 safe — this library remembers your device’s Chip ID and blocks anything else.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages