Spark method to get the Core Name?

I would like to get the Spark Name that is displayed in the list of cores. I found the Spark.deviceID method, but do we have any methods available to get the name? I suspect the name is only know to the cloud. Any suggestions?

If you use spark list in Spark-cli, the list of cores in your account will appear.

That’s an API endpoint and you can reach it via other means. :slight_smile:

@kennethlimcp Thanks for the reply. I was not specific enough in my question. I want to do this from the core. I have an LCD display connected and I wanted to display the Spark Cloud Name on the display. I can use

Spark.deviceID()

which returns the long hex id as a string, but I what I am looking for is an easy way to get the name that the core is associated with in the cloud.

Similar to the output from spark list and when you are using the IDE and show the cores.


This requires information stored in the cloud since core names are really a value stored in the server side of things.

@dave might have some inputs on this.

1 Like

Hey Guys!

This has been on my backlog for a long time, so I’m just going to build it and sneak it in now. It’ll be included in our next push. :slight_smile: When it gets released you can get your core name by:

  • Spark.subscribe to the topic: “spark/device/name”
  • Spark.publish with the topic: “spark/device/name”

When you publish that event, the cloud will send you an event back with your core name. We’ll put a nicer wrapper on it, but for now that’ll be a quick workaround for getting that info.

Thanks,
David

6 Likes

Awesome Dave, I look forward to it!

Thanks!

1 Like

Awesome!
Thank you for doing that!
For the NooBs like me.

void getSparkCoreName(){
    sparkCoreName = "";
    sparkCoreName.concat(String(Spark.deviceID()));
    Spark.subscribe("spark/device/name", myHandler);
    Spark.publish("spark/device/name", "What's my name?");
}

void myHandler(const char *event, const char *data)
{
    sparkCoreName = data;
}
1 Like

to retrieve the device name:
Spark.subscribe to the topic: "spark/device/name"
Spark.publish with the topic: "spark/device/name"
This works for me on the core (compiled on master) but apparently not on the photon (compiled on v0.4.2). Is it my code or is it not available on the photon or v0.4.2?

1 Like

Hi @bpr,

Hmm, no reason why this shouldn’t work on the Photon. It’s possible that the photon firmware treats subscriptions slightly differently, and might not handle a subscribe immediately followed by a publish / event gracefully. Does it work if you introduce some delay between the two?

Thanks,
David

Yes i tried both 1 sec and 2 sec using the millis method and spark.process

1 Like

I’ll admit I haven’t tried this, but the Docs say to use this?

    Spark.subscribe("spark/", handler);
    Spark.publish("spark/device/name");
1 Like

Thats slightly different. Thanks @mumblepins I’ll try that tonight, though the other code worked on the core.

As best as I can tell neither set of code works on the photon firmware versions develop or v0.4.2 or on the Web IDE. It does work on the core using the Web IDE but not with firmware develop. So unless I’m mistaken, this feature is not available on the develop or v0.4.2 branches. Hope someone can steer me right or that it gets added to the newer firmware (or some other way of identifying the device in an easily “human readable” way

@bpr, have you tested this same behavior using the Web IDE or Particle-cli?

windows 7 toolchain and web ide

@bpr i tested and it seems to not be working though the message was published.

Not sure if this is a :cloud: or firmware issue with the Photon.

The issue has been fixed in the develop branch. Will be available as part of 0.4.4. Thanks to everyone involved for helping nail it!

3 Likes