EEPROM.get returns bad data

(deleted)

EEPROM.get(0, serial_number);

serial_number is a String.

The six bytes of a String will look like what you describe.

Use the c_str() method.

Better still, don’t use Strings.

(Hint: data that you don’t recognise isn’t necessarily bad)

  if (serial_number.length() == 7) {
    Serial.println("Found valid serial in EEPROM");

A discriminating test for validity.

(deleted)

One of many approaches to create a random serial number:

char serial_number[8]="SN-XXXX";
serial_number[3]=random(48,58);  //stores random ASCII digit '0' to '9' in position x of SN-xXXX;

(deleted)

Can this part be written in one line ?

reply #4