Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a possibility to store a hardware ID for each Raspberry Pi based device?

Let's say I have 10 custom devices based on Raspberry Pi platform that are used for distributed tasks. At some point, for some reason, I want to erase everything from one of them. How can I re-identify the board after that?

Does Pi have a chip that stores a unique ID like a serial number for every board? If not, can I add a (read-only) memory (that can store a simple value even when not powered) to be able to communicate with it through GPIO at any time?

What are the alternatives?

share|improve this question
    
Please don't ask a question, then on the basis of the answer decide you really wanted to ask, or have another, question. This wastes the time of the people you are asking for help. For this reason, I have rolled your edit back. If you have another question, ask another question. – goldilocks Feb 4 at 16:03
    
@goldilocks: You are correct. I should have split this question in two. – AlexandruIrimiea Feb 4 at 16:22
    
What about 'ZERO'? no MAC address here... any other unique ID? – fcm Jun 6 at 13:08
up vote 19 down vote accepted

Yes each board has a serial number. Methods to retrieve this are described here: How do I get the serial number?

share|improve this answer
    
This is not a complete answer, since it only deals with linux and does not mention windows at all. It would be interesting to know how to so this on windows too. – zespri Feb 5 at 3:06
    
@Savinykh ... linux and Mac OS. Awk, grep and cut are tools available on both OS, but I agree Windows is left out as it lacks these handy command line tools. – ripat Feb 5 at 7:10
7  
You can't run Mac OS on the Pi, so that's not relevant. You can only run the headless Win10 IOT edition on the Pi I believe. Realistically 99% of Pi users are using Linux. – pjc50 Feb 5 at 9:55
    
@ripat, can you run Mac OS on raspberry pi though? I somehow doubt it. – zespri Feb 5 at 13:17

Here is an easier to use one: MAC address via IPv6 NDP auto configuration. This is a universal method that is applicable to any network interface.

Every NIC, including the USB one used on the Pi, have an 48-bit MAC address, for example, 14:cf:92:20:26:3c.

Every 48-bit MAC address have a unique one-to-one mapping to an EUI-64 address by masking off the last two bits in the third byte (92 to 90) and insert the bytes feff in between the third and fourth byte. The aforementioned 48-bit MAC can be mapped to the EUI-64: 14cf:90fe:ff20:263c.

The IPv6 address auto configuration process uses NDP protocol to discover the 64-bit network address in the 128-bit address. This process will give all your devices within the same network the same 64-bit prefix. The aforementioned EUI-64 is used to populate the 64-bit station address, resulting in a 128-bit globally unique IPv6 address. So if you have the IPv6 network prefix 2001:470:d:472::/64, the aforementioned network card, when used in this network, will be guaranteed to have an IPv6 globally routable address 2001:470:d:472:14cf:90fe:ff20:263c. As long as your management tool is configured to use IPv6, just plug this address into it and it should be good to go.

share|improve this answer
    
this is the better way of answering this question in my opinion. MAC is unique. you can hash it a bit if you want, but just relying on the MAC address can be done on any platform. – Havnar Feb 18 at 14:42
    
@Havnar Better than that, this translates the MAC address directly into an globally routable IPv6 address that can be used to send packets to the Pi directly (any application layer protocol, as long as it works over IPv6 which is most of them, will work here) – Maxthon Chan Feb 19 at 2:53
    
I don't know of many people who actually use ipv6 at home or in production really. – Havnar Feb 19 at 9:42
    
@Havnar I have deployed IPv6 tunnel in my home network to the point that all devices within my home, with the exception of the router itself, can function without IPv4 enabled. – Maxthon Chan Feb 19 at 17:55

As in the other answer the Pi has a unique ID, which is related to the MAC.

In practice it is more convenient for networking to have a unique hostname. I use the following script to set the names based on CPUID.

#!/bin/bash
# script to set Pi hostname based on MAC (or Serial number)
# 2015-02-22
# This script should be run as root (or with sudo) to change names
# If run by a user it will report changes, but will NOT implement them

PDIR="$(dirname "$0")"
CURRENT_HOSTNAME=$(cat /etc/hostname)
MAC=$(cat /sys/class/net/eth0/address)
# NOTE the last 6 bytes of MAC and CPUID are identical
CPUID=$(awk '/Serial/ {print $3}' /proc/cpuinfo | sed 's/^0*//')
echo "Current Name" $CURRENT_HOSTNAME
echo "MAC" $MAC
# If you want to specify hostnames create a file PiNames.txt with MAC hostname list
# b8:27:eb:01:02:03 MyPi
# If not found a unique Name based on Serial number will be set
NEW_HOSTNAME=$(awk /$MAC/' {print $2}' $PDIR"/PiNames.txt")
echo "Name found" $NEW_HOSTNAME
if [ $NEW_HOSTNAME == "" ]; then
    NEW_HOSTNAME="pi"$CPUID
fi

if [ $NEW_HOSTNAME = $CURRENT_HOSTNAME ]; then
    echo "Name already set"
else
    echo "Setting Name" $NEW_HOSTNAME
    echo $NEW_HOSTNAME > /etc/hostname
    sed -i "/127.0.1.1/s/$CURRENT_HOSTNAME/$NEW_HOSTNAME/" /etc/hosts
fi
share|improve this answer
    
Though, of course the As and Zeros, without an Ethernet connection, will not have a MAC from that to use! A WiFi adapter will, but moving the adapter between Pis will mean the unique ID will follow the adapter! – SlySven Feb 4 at 23:05
    
@SlySven I don't have a Zero (and can't think of any valid reason yet), but I should modify my script to ignore missing MAC. I assume there will be no /sys/class/net/eth0/address – Milliways Feb 4 at 23:18
    
Another way to identify any Pi's with a unique id is to get its dbus machine-id which is not interface dependent cat /var/lib/dbus/machine-id read more – ripat Feb 5 at 8:13
    
... forgot to credit the "read more" link in my comment above to its author: Lennart Poettering, the father of systemd. – ripat Feb 5 at 8:23

If it wouldn't have an ID (which it has, as it would seem, see Ralph's answer) an alternative could be an I2C serial number chip. Those are really easy to connect (serial interface) and provide a unique serial number.

Some examples:

  • Maxim's I²C/SMBus Silicon Serial Number, e.g. DS2401, DS28CM00
  • Microchip's Unique ID Chip Products, e.g. 24AA02UID, 24AA025UID
  • self-programmed I²C EEPROM
share|improve this answer
    
Might as well just use a socketed I2C EEPROM chip and program an unique ID into that. AT24C32 are fairly cheap when bought in bulk. – Maxthon Chan Feb 19 at 17:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.