# Modbus choosing server by msg.payload

**URL:** <https://discourse.nodered.org/t/modbus-choosing-server-by-msg-payload/87154>\
**Category:** General\
**Tags:** modbus\
**Created:** [11 April 2024 10:33 UTC](https://discourse.nodered.org/t/modbus-choosing-server-by-msg-payload/87154 "2024-04-11T10:33:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kreeker](https://avatars.discourse-cdn.com/v4/letter/k/ecb155/32.png) [@Kreeker](https://discourse.nodered.org/u/Kreeker)\
**Post date:** [11 April 2024 10:33 UTC](https://discourse.nodered.org/t/modbus-choosing-server-by-msg-payload/87154/1 "2024-04-11T10:33:48Z")

</div>

Hello,

I'm using **node-red-contrib-modbus** and i have over 60 ModBus TCP servers which I'm trying to connect to on demand selectively (i have no need to connect to them all at the same time). I get the server IP's from excel file that my co-workers are using. I'd like to avoid having 60 diffrently configured ModBus-Getter nodes specificly for each server, because it would mean having to update each node everytime something changes, and adding new nodes if theres a new server added.

Question is: how do i approach this? Which nodes should i use? How do i dynamicly select a server?  
Ideally, i`d like to pass IP, port, unitID, function code, register and quantity via msg.payload object.

Thank you 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:** [11 April 2024 10:59 UTC](https://discourse.nodered.org/t/modbus-choosing-server-by-msg-payload/87154/2 "2024-04-11T10:59:41Z")

</div>

> [@Kreeker](#):
>
> Question is: how do i approach this? Which nodes should i use? How do i dynamicly select a server?

Have you looked at the build in examples?

`ctrl-i` → examples → `node-red-contrib-modbus`

i am not 100% certain but I seem to recall there being a demo flow for this approach.

---

<div class="post-metadata">

**Author:** ![Kreeker](https://avatars.discourse-cdn.com/v4/letter/k/ecb155/32.png) [@Kreeker](https://discourse.nodered.org/u/Kreeker)\
**Post date:** [11 April 2024 11:08 UTC](https://discourse.nodered.org/t/modbus-choosing-server-by-msg-payload/87154/3 "2024-04-11T11:08:40Z")

</div>

Okay, apparently all i needed was a little coffee break x)

The solution was **ModBus Flex Connector node** , which takes following params:  
msg.payload = {  
'connectorType': 'TCP',  
'tcpHost': 'yourIPasString',  
'tcpPort': 'yourPortAsString',  
'unitId': yourUnitIdAsNumber  
}  
It takes a while for the node to connect with new server though.

Cheers!

---

<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:** [10 July 2024 11:09 UTC](https://discourse.nodered.org/t/modbus-choosing-server-by-msg-payload/87154/4 "2024-07-10T11:09:21Z")

</div>

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