# Can the MQTT ClientID be set dynamically?

**URL:** <https://discourse.nodered.org/t/can-the-mqtt-clientid-be-set-dynamically/92312>\
**Category:** General\
**Tags:** mqtt\
**Created:** [11 October 2024 06:49 UTC](https://discourse.nodered.org/t/can-the-mqtt-clientid-be-set-dynamically/92312 "2024-10-11T06:49:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NNNN](https://avatars.discourse-cdn.com/v4/letter/n/3be4f8/32.png) [@NNNN](https://discourse.nodered.org/u/NNNN)\
**Post date:** [11 October 2024 06:49 UTC](https://discourse.nodered.org/t/can-the-mqtt-clientid-be-set-dynamically/92312/1 "2024-10-11T06:49:19Z")

</div>

I've seen an example of a dynamic configuration [here](https://discourse.nodered.org/t/dynamically-set-mqtt-broker-configurations/89902) but I wonder if the MQTT Client ID can also be set dynamically.  
I want each device to set their ID to the device's serial number, so doing that manually across all devices is not a good solution.  
Is that possible?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [11 October 2024 06:51 UTC](https://discourse.nodered.org/t/can-the-mqtt-clientid-be-set-dynamically/92312/2 "2024-10-11T06:51:05Z")

</div>

Yes. See the full demo in the linked post: [Dynamic MQTT LWT birth, Close & Will Property - #2 by Steve-Mcl](https://discourse.nodered.org/t/dynamic-mqtt-lwt-birth-close-will-property/58951/2) it does that in the "connect with opts" inject

---

<div class="post-metadata">

**Author:** ![NNNN](https://avatars.discourse-cdn.com/v4/letter/n/3be4f8/32.png) [@NNNN](https://discourse.nodered.org/u/NNNN)\
**Post date:** [11 October 2024 07:38 UTC](https://discourse.nodered.org/t/can-the-mqtt-clientid-be-set-dynamically/92312/4 "2024-10-11T07:38:26Z")

</div>

@Steve-Mcl  
Great, thanks for the quick help!

One more follow-up question: Can the TLS configuration also be set dynamically?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [11 October 2024 07:41 UTC](https://discourse.nodered.org/t/can-the-mqtt-clientid-be-set-dynamically/92312/5 "2024-10-11T07:41:58Z")

</div>

> [@NNNN](#):
>
> Can the TLS configuration also be set dynamically

No. not supported.

You can use ENV VARs in the TLS config (env vars get evaluated at launch of node-red) - perhaps that would help?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [25 October 2024 07:42 UTC](https://discourse.nodered.org/t/can-the-mqtt-clientid-be-set-dynamically/92312/6 "2024-10-25T07:42:05Z")

</div>

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