🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    M5Paper unique device identifier?

    PRODUCTS
    2
    4
    4.7k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G
      gionata
      last edited by

      This post is deleted!
      1 Reply Last reply Reply Quote 0
      • ZontexZ
        Zontex
        last edited by

        Hello, does the getEfuseMac return you the same value? you can try to generate a value one time and keep it inside the device for use later.

        1 Reply Last reply Reply Quote 0
        • G
          gionata
          last edited by gionata

          Actually, my bad, I ran the same code again on 3 different M5Paper and it is indeed working...

          So yes, getMACString is returning a unique id.

          `
          [global_setting.cpp:70] getMACString(): MAC = 0000CC240805613C
          [main.cpp:261] run(): getEfuseMac: 0805613C

          [global_setting.cpp:70] getMACString(): MAC = 0000CC370805613C
          [main.cpp:261] run(): getEfuseMac: 0805613C

          [global_setting.cpp:70] getMACString(): MAC = 000084170905613C
          [main.cpp:261] run(): getEfuseMac: 0905613C
          `

          Thanks

          1 Reply Last reply Reply Quote 0
          • G
            gionata
            last edited by

            Here is a solution to create an unique identifier that is based on the device's MAC address (but is not easy to guess and is not the MAC address itself):

            /** Returns a hashed uint64_t */
            uint64_t getHashedInt64(uint64_t u)
            {
                uint64_t v = u * 3935559000370003845 + 2691343689449507681;
            
                v ^= v >> 21;
                v ^= v << 37;
                v ^= v >> 4;
            
                v *= 4768777513237032717;
            
                v ^= v << 20;
                v ^= v >> 41;
                v ^= v << 5;
            
                return v;
            }
            
            /** Return a device unique identifier based on device's mac address, eg. 6C4080B51A5D3659 */
            String getUniqueId()
            {
                uint64_t mac = ESP.getEfuseMac();
                uint64_t hash = getHashedInt64(mac);
                uint32_t msb = hash >> 32;
                uint32_t lsb = hash & 0xFFFFFFFF;
            
                char unique_id[20];
                sprintf(unique_id, "%08X%08X", msb, lsb);
                return String(unique_id);
            }
            

            Calling:
            getUniqueId() returns something like 6C4080B51A5D3659

            1 Reply Last reply Reply Quote 0
            • First post
              Last post