Can firmware retrieve a device's "Serial Number"

I have a console that I plan to use to monitor my devices, and I am developing a “Host” class/library that will added to device firmware to generate and publish data to that console.

One key thing I need is a way to identify the device. Each device has multiple identities:

  • Serial Number
  • Device ID
  • Device Name

I would prefer to use the Serial Number because it can not change and it is not “private information”.

Is it possible to obtain the device’s Serial Number (displayed on the Particle Console) via firmware?

It depends on the device. Gen 3 devices (Argon, Boron, and Xenon) can get the serial number from user firmware.

Gen 2 (Electron, Photon, E Series) cannot get the serial number through user firmware.

Usually the device ID is the best unique identifier for a device.

3 Likes

Can you please add a brief example of how to get the serial number for any future searchers who land here and would like the answer without having to search further. Thanks

Hi Rainer,

I've never done this before but I was intrigued so I decided to go ahead and search the docs..
This is what I found:

// EXAMPLE USAGE

void setup()
{
  // Make sure your Serial Terminal app is closed before powering your device
  Serial.begin(9600);
  // Wait for a USB serial connection for up to 30 seconds
  waitFor(Serial.isConnected, 30000);

  String myID = System.deviceID();
  // Prints out the device ID over Serial
  Log.info("deviceID=%s", myID.c_str());
}

void loop() {}

So the trick is in this line:

String myID = System.deviceID();

Source is here

Cheers!
Gustavo.

Hi Gustavo,
Thanks for your interest. I have the deviceID which is a long hex string. What I'm having trouble with is the Serial number, which looks like base 64 encoded, e.g. B40HVN004CTLAEP. The serial number is printed on the outside of the device so it's easy to see but seems to be hard to retrieve programmatically.
The console has it so it must be coming from somewhere but maybe not visible to the firmware.
Thanks,
Rainer

original post > | [gusgonnet](https://community.particle.io/u/gusgonnet) Level 3 | Champion
November 10 | > - | - |

RainerR:

Can you please add a brief example of how to get the serial number

Hi Rainer,

I’ve never done this before but I was intrigued so I decided to go ahead and search the docs…
This is what I found:

// EXAMPLE USAGE

void setup()
{
  // Make sure your Serial Terminal app is closed before powering your device
  Serial.begin(9600);
  // Wait for a USB serial connection for up to 30 seconds
  waitFor(Serial.isConnected, 30000);

  String myID = System.deviceID();
  // Prints out the device ID over Serial
  Log.info("deviceID=%s", myID.c_str());
}

void loop() {}

So the trick is in this line:

String myID = System.deviceID();

Source is here

Cheers!
Gustavo.

1 Like

The API to read the serial number is only exposed in 2.0.0-rc.2 and later. There is example code here:

4 Likes