Cloud functions
Get device name
This gives you the device name that is stored in the cloud.
SYSTEM_THREAD(ENABLED);
SerialLogHandler logHandler;
bool nameRequested = false;
// Open a serial terminal and see the IP address printed out
void subscriptionHandler(const char *topic, const char *data)
{
Log.info("topic=%s data=%s", topic, data);
}
void setup()
{
Particle.subscribe("particle/device/name", subscriptionHandler);
}
void loop() {
if (Particle.connected() && !nameRequested) {
nameRequested = true;
Particle.publish("particle/device/name");
}
}
Instead of fetching the name from the cloud each time, you can fetch it and store it in retained memory or EEPROM. The DeviceNameHelperRK library makes this easy. The link includes instructions and the library is available in Particle Workbench by using Particle: Install Library or in the Web IDE by searching for DeviceNameHelperRK.
Requesting the device name uses two data operations, one for the request and one for the response.