Updating a variable whenever the device name changes

I want to take this a step further -> How to include Device Name (Not just Device ID) in SMS when using Messaging Cloud API (Twilio)

I need to make sure that whenever the device name changes, I update the device name in the next SMS that is send after the name change. Also, lets say the user has more than one device. How do I make sure I only update for that specific device?

Also, not sure if this is by design or I’m doing something wrong.
I placed the code below in the loop section

 Particle.subscribe("particle/device/name", handler);
    Particle.publish("particle/device/name");

it works but whenever i change the name I won’t get the new name to display until the module reboots.
Is this a limitation of particle/device/name

That “whenever” part of that request is not possible.
The devices don’t get notified when their name gets changed.
If you really intend to change your devices’ names that often (which is not common practice), your devices need to poll for potential changes in a rate that fits your intended frequency of name changes.

The latter part of that sentence is the answer :wink:

Particle.subscribe() shall only be called once (normally via setup()) for each subscription.

And Particle.publish() also has a rate limit of 1/sec.

As always thanks for the insight.

For a Boron, how much data usage does the Particle.subscribe() take up? Also, wouldn’t it make sense to run a Particle.unsubscribe() at the end of the void setup() once the name is acquired to save data?

As long no subscribed event occures no data is transmitted, so no need to unsubscribe.

But you yourself said you want to know whenenever the name changes so you must put up with the extra data cost.

I got a semi workaround. In my app whenever the renameDevice api is called it will also run a function after that to reboot the device.