# Maintain sensors and TCP server mapping in Nodered

**URL:** <https://discourse.nodered.org/t/maintain-sensors-and-tcp-server-mapping-in-nodered/82319>\
**Category:** General\
**Created:** [25 October 2023 04:44 UTC](https://discourse.nodered.org/t/maintain-sensors-and-tcp-server-mapping-in-nodered/82319 "2023-10-25T04:44:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![shershah](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@shershah](https://discourse.nodered.org/u/shershah)\
**Post date:** [25 October 2023 04:44 UTC](https://discourse.nodered.org/t/maintain-sensors-and-tcp-server-mapping-in-nodered/82319/1 "2023-10-25T04:44:59Z")

</div>

Hi All,

I have different kind of sensors mapped with different tcp server. Currently I have configured all the tcp server and based on sensorId using switch block, I am communicating with TCP server.

How can I make it dynamic?  
I want to push all the tcp server and sensor mapping details through mqtt and save it in nodered. then based on sensor id, get the tcp server details, make the connection dynamically. I may update the mapping details in future.

Thanks in advance.

---

<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:** [25 October 2023 05:33 UTC](https://discourse.nodered.org/t/maintain-sensors-and-tcp-server-mapping-in-nodered/82319/2 "2023-10-25T05:33:39Z")

</div>

As you have provided very little detail, I will assume you are going to make requests to these sensors using the TCP request node.

As stated in the built in help:

> If you leave tcp host or port blank they must be set by using the `msg.host` and `msg.port` properties in every message sent to the node.

---

<div class="post-metadata">

**Author:** ![shershah](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@shershah](https://discourse.nodered.org/u/shershah)\
**Post date:** [25 October 2023 09:47 UTC](https://discourse.nodered.org/t/maintain-sensors-and-tcp-server-mapping-in-nodered/82319/3 "2023-10-25T09:47:07Z")

</div>

Hi Steve,

How do I maintain the sensor and tcp server mapping? I want to create a flow to push tcp and sensor mapping details from cloud through MQTT and save it somewhere in Nodered cache.

Once I get the sensor request, I can fetch tcp details for the cache for the mapped sensor and can make the request dynamically.

I hope Now I am clear about my requirements. Its more about creating a separate flow and how to create cache. In future I may update the cache.

Thanks in advance.

Regards,  
Shershah

---

<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:** [25 October 2023 09:57 UTC](https://discourse.nodered.org/t/maintain-sensors-and-tcp-server-mapping-in-nodered/82319/4 "2023-10-25T09:57:42Z")

</div>

> [@shershah](#):
>
> How do I maintain the sensor and tcp server mapping

Use [context](https://nodered.org/docs/user-guide/context) to store the MQTT config data.

---

<div class="post-metadata">

**Author:** ![Josh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/josh/32/62208_2.png) [@Josh](https://discourse.nodered.org/u/Josh)\
**Post date:** [25 October 2023 09:58 UTC](https://discourse.nodered.org/t/maintain-sensors-and-tcp-server-mapping-in-nodered/82319/5 "2023-10-25T09:58:48Z")

</div>

You can consider using dynamic tcp node. [https://flows.nodered.org/node/node-red-contrib-tcp-client](https://flows.nodered.org/node/node-red-contrib-tcp-client)

---

<div class="post-metadata">

**Author:** ![shershah](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@shershah](https://discourse.nodered.org/u/shershah)\
**Post date:** [25 October 2023 11:34 UTC](https://discourse.nodered.org/t/maintain-sensors-and-tcp-server-mapping-in-nodered/82319/6 "2023-10-25T11:34:02Z")

</div>

Can we maintain some cache like redis cache? We context data will be available after restart or can be shared between multiple instance of Nodered

---

<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:** [25 October 2023 11:38 UTC](https://discourse.nodered.org/t/maintain-sensors-and-tcp-server-mapping-in-nodered/82319/7 "2023-10-25T11:38:54Z")

</div>

> [@shershah](#):
>
> Can we maintain some cache like redis cache

Did you read the link I posted?

> [@Steve-Mcl](#):
>
> Use [context](https://nodered.org/docs/user-guide/context)

In particular the part about persisting context titled "Saving context data to the file-system"

And you could always use redis or sqlite or my/mssql or even regular files. Plenty of contrib nodes based on storage and retrieval of data.

---

<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:** [24 December 2023 11:39 UTC](https://discourse.nodered.org/t/maintain-sensors-and-tcp-server-mapping-in-nodered/82319/8 "2023-12-24T11:39:37Z")

</div>

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