# Updating a variable whenever the device name changes

**URL:** <https://community.particle.io/t/updating-a-variable-whenever-the-device-name-changes/55286>\
**Category:** Cloud\
**Created:** [March 21, 2020, 9:37pm UTC](https://community.particle.io/t/updating-a-variable-whenever-the-device-name-changes/55286 "2020-03-21T21:37:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![oraclerouter](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/oraclerouter/32/30494_2.png) [@oraclerouter](https://community.particle.io/u/oraclerouter)\
**Post date:** [March 21, 2020, 9:37pm UTC](https://community.particle.io/t/updating-a-variable-whenever-the-device-name-changes/55286/1 "2020-03-21T21:37:31Z")

</div>

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)](https://community.particle.io/t/how-to-include-device-name-not-just-device-id-in-sms-when-using-messaging-cloud-api-twilio/36038)

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?

---

<div class="post-metadata">

**Author:** ![oraclerouter](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/oraclerouter/32/30494_2.png) [@oraclerouter](https://community.particle.io/u/oraclerouter)\
**Post date:** [March 22, 2020, 3:32am UTC](https://community.particle.io/t/updating-a-variable-whenever-the-device-name-changes/55286/2 "2020-03-22T03:32:16Z")

</div>

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

```auto
 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

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [March 22, 2020, 6:43am UTC](https://community.particle.io/t/updating-a-variable-whenever-the-device-name-changes/55286/3 "2020-03-22T06:43:45Z")

</div>

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.

> [@oraclerouter](#):
>
> not sure if this is by design or _ **I’m doing something wrong** _.

The latter part of that sentence is the answer 😉

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

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

---

<div class="post-metadata">

**Author:** ![oraclerouter](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/oraclerouter/32/30494_2.png) [@oraclerouter](https://community.particle.io/u/oraclerouter)\
**Post date:** [March 25, 2020, 2:09pm UTC](https://community.particle.io/t/updating-a-variable-whenever-the-device-name-changes/55286/4 "2020-03-25T14:09:46Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [March 25, 2020, 2:20pm UTC](https://community.particle.io/t/updating-a-variable-whenever-the-device-name-changes/55286/5 "2020-03-25T14:20:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![oraclerouter](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/oraclerouter/32/30494_2.png) [@oraclerouter](https://community.particle.io/u/oraclerouter)\
**Post date:** [March 25, 2020, 2:33pm UTC](https://community.particle.io/t/updating-a-variable-whenever-the-device-name-changes/55286/6 "2020-03-25T14:33:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/3/2/3291e3c9351789fe8620ae5bcec8d3fec67ff221.png) [@system](https://community.particle.io/u/system)\
**Post date:** [September 24, 2020, 2:33am UTC](https://community.particle.io/t/updating-a-variable-whenever-the-device-name-changes/55286/7 "2020-09-24T02:33:52Z")

</div>

Closed on September 24, 2020, 2:33am UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
