Maintain sensors and TCP server mapping in Nodered

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.

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 and msg.port properties in every message sent to the node.

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.


Use context to store the MQTT config data.

You can consider using dynamic tcp node.

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

Did you read the link I posted?

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.