goiotuuidmac-addressserial-number

Best way to auto generate global unique identity for IoT devices


I have a application developed in Golang for IoT devices which communicates over MQTT, and this application can also be installed on any device that supports Docker and Golang.

Now I want to auto generate unique identity for my application for each device when I run my application for first time on a device. I was thinking about using permanent MAC or Serial Number, is that good approach and will all device have permanent MAC or Serial Number? If not then what is the better way to achieve this.


Solution

  • There's absolutely no guarantee that your device will even have have a serial number or MAC address, not to mention a unique one.

    Regarding serials, every device manufacturer does its own thing. Those devices that have software-accessible serial numbers usually have them burnt into an EEPROM somewhere which requires special tools to read it. You'd need to know the procedure and run tools for each device you target.

    Regarding MACs, if your device has a WiFi or Ethernet interface then the manufacturer probably has allocated a globally unique MAC address for it. However, it would be up to you to find the relevant network interface and read its MAC address. This would be rather cumbersome as you'd have to discover the system for network interfaces, determine if it's a physical interface (vs a virtual one like dial-up, bridge, vpn, etc) and read its MAC. Finally, some devices don't have any physical WiFi or Ethernet interfaces at all - they may come with a GSM module or LoRA or something else entirely.

    I'd recommend not relying on MAC or serial. Generate your own GUID on first launch, store it in configuration and use it for subsequent identification.

    PS - I'm assuming that you're targeting somewhat larger devices running Linux or other desktop OS. Microcontrollers generally don't support Go, and certainly not Docker.