Get Device Serial Number from firmware

Trying to work out how to get the device serial number, I’ve come up with the following but looks like the hal system space is not available in the user space. Is there something I can do to make it available?

#include <Particle.h>
#include "deviceid_hal.h"


Logger l("app");

Serial1LogHandler debugOutput(57600,LOG_LEVEL_WARN, {
      { "app", LOG_LEVEL_ALL }

void setup(){
  char buf[15] = {};
  int len;
  len=hal_get_device_serial_number(buf, sizeof(buf), nullptr); 
  l.trace("Serial %.*s",len,buf);

void loop(){

Try System.deviceID() instead. Or if you need it in C string format, System.deviceID().c_str().

Can’t use that as I need it to match what is printed on the label stuck on the Particle.

This has been asked before, and IIRC there is not a way to get the barcode number from software.

So we can retrieve the serial number when the device is in listening mode and connected to a USB terminal by typing the letter “i”. With this being known there must be a way to do this within the firmware.

I would like to rename the device’s advertising name with “SomeName-123456” with the last six of the serial as is currently used in the advertised name. I would just like to replace “Argon” with our product name.

@rickkas7 any thoughts on how this can be done?

Listening mode is built into the firmware and executes in that context. It has access to more than what is exposed to user mode programs. As far as I can tell Device serial number is not exposed. Only Device ID, which is also unique, but not the same as serial number. I suspect that to get serial number from your code you would have to modify DeviceOS.

Thank you @picsil

If the device ID was displayed on the front of the device, the device ID would be more useful…

I’m not going to take on the adventure of modifying the device OS, so I’ll have to work with what I’ve got.

I completely agree. I’m not entirely sure what the point of having both is.