This is already in the core firmware in
You call it like this:
String myIDStr = Spark.deviceID();
...
Serial1.print(myIDStr);
I had trouble and had to factory reset when I called deviceID() in loop but calling it to initialize a global worked fine.
[EDIT: don’t redefine the symbol “id” if you want your core to work. I think a bunch of the code needs underscores added to private vars.]