Generating unique ID for each sketch upload?

robtillaart:
Problem with the random generator is that it is not so random at all, it is an algorithm and unless every sketch has an unique seed you will get the same signature for every board.

Furthermore if your boards have used the EEPROM before (or in a factory test who knows) your code will probably not write your signature, so you need an erasor sketch that writes 0xFF to EEPROM first otherwise previous values could be identical ... AVRdude can also do that.

It is quite hard to make this process automatic AND robust (failproof). I think I would use some makefile with AVRdude to write the signature to EEPROM after uploading the sketch, and that makefile would increment the EEPROM file every time called. It can keep track of the numbers applied on which day etc.
Or let some SED command change a signature in the source to some sequence number.

How many boards do you intend to label this way?
Rob

Hi Rob, I agree this is a hard problem to have a robust solution. The reference does suggest using randomSeed(analogRead(0)) (or some unused analog input). I did notice some noise in the unused analog input but the noise is minimal (+/-5) so collision is likely, plus you need an unused analog input.

To solve the issue with pre-existing values in the EEPROM, I added another EEPROM header that contains a 4-byte signature header that identfies this sketch(e.g. "APP1") so I can at least tell if my sketch was the last one to write to these bytes. If the header doesn't match, then I generate new values.

All-in-all, the hardest paroblem to solve is the run-time random number generation, and I don't want to depend on any external tools, if possible at all.

Thanks,

  • K.