Device ID stored in core?

Hey guys,

How could I get the device ID of a core without having to connect to the Internet? I mean, is there any function in the firmware which automatically prints the Core ID? How could I do it?

Thanks!

Here’s the relevant code snippet from the wifi credentials reader that outputs the core id:

https://github.com/spark/core-firmware/blob/master/src/wifi_credentials_reader.cpp#L78-L93

Thanks!
David

Thanks Dave!!

I’m a beginner, and I don’t really know how to implement this code, sorry :frowning:
Can I directly use this code in the void() part to get the device id? Or it work in a diferent way?

If you put your Core in Listening Mode, you can connect to it via Serial over USB. Then type the letter i and your Core ID comes up.

Listening mode: Power the Core, press and hold the Mode button until the RGB led slowly flashes blue.

You may need to install some drivers first:

Any more questions just ask! :wink:

1 Like

Thanks BDub, I’ve read your post on how to intall USB Driver on Windows & Serial Debugging and I found it very useful, but that is not exactly what I’m searching for.

I’m searching a way to get the device ID of a Core without having to connect it to any external device. I don’t know if I am explaining myself :blush:

Hi @lia - the Core does broadcast its ID through a multicast UDP datagram when it comes online, so it is possible to write an app on your computer/smartphone that will listen for the broadcast and pull down the ID. However, I don’t know the syntax; @zachary, do you have this written down somewhere?

I think we posted about that here:

Here you go:

String getCoreID()
{
  String coreIdentifier = "";
  char id[12];
  memcpy(id, (char *)ID1, 12);
  char hex_digit;
  for (int i = 0; i < 12; ++i)
  {
    hex_digit = 48 + (id[i] >> 4);
    if (57 < hex_digit)
     hex_digit += 39;
     coreIdentifier = coreIdentifier + hex_digit;
    hex_digit = 48 + (id[i] & 0xf);
   if (57 < hex_digit)
     hex_digit += 39;
   coreIdentifier = coreIdentifier + hex_digit;
 }
 return coreIdentifier;
}

You can then get the core ID like so:

String thisCoreID = getCoreID();
Serial.print("The unique ID of this core is ");
Serial.println(thisCoreID);

I think you're referring to void loop()? The void part is the return value of the method. In the case of loop() it returns nothing to the code that calls or executes it, so its void. In the method above that gets the core identifier, it need to return the core id as a string, hence why it is String getCoreID() rather than void getCoreID(). Hope that helps.

2 Likes

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 :spark: code needs underscores added to private vars.]

4 Likes

No guys @dermotos @bko he does not want to physically connect the core to anything to get the ID out.

There is a way to get ALL of your ID's if you know your access_token. You can put this right in your browser's address bar and get the ID's
https://api.spark.io/v1/devices?access_token=1234123412341234

Returns:

[
  {
    "id": "1234123412341234",
    "name": "Technobly1",
    "last_app": null,
    "connected": true
  },
  {
    "id": "2345234523452345",
    "name": "Technobly2",
    "last_app": null,
    "connected": true
  },
  {
    "id": "3456346534653465",
    "name": "Technobly3",
    "last_app": null,
    "connected": false
  }
]

You can get your access token(s) by doing a Basic HTTP Auth GET request like this:

If you need more info on any of that, just ask... gotta make sure this is heading in the right direction first :wink:

Just re-read you said you don’t want to connect it to the internet and you don’t want to physically connect to it via serial.

Can you please explain what your use case is for getting the ID in this way? Once you have the ID I would think you’re then going to use it, right… so connect it to the internet? Maybe there is a large number of Core’s you are trying to get ID’s for? Maybe there is a better solution here if we know the way in which you want to ultimately use the :spark: Core.

Thanks guys! I know I explained myself very bad. What I was searching for is what @bko and @dermotos posted. It worked!
Thanks to all

3 Likes

Hi David,

ID displayed via Browser URL per your instructions. Thanks So Much !

1 Like