Modbus read node dynamic configuration

Hello everyone!
My english is not really good, so forgive me if I'm not clear enough.
Main question is: is it possible to set the modbus read configuration dynamically?

I have a modbus read node which connects to an ION8650, and reads several registers. Then I have other nodes to transform data and store in my oracle database.
Currently, I have configured the modbus read node manually, and it works correctly.

What I want to do is:
To have in my database, a table with a list of devices with their IP address, port, slave id, etc.
And set the modbus read node taking the information from the database.

Is that possible?
If yes, could somebody guide me on how to do that?

Thanks in advance,
Tomas

Hello.

Yes it is possible. I do not know if you figured it out.

i think i have done hat you need.
i am doing something similar right now,

first you need teh node-red-contrib-modbus pacakge.

right now i am doing this with 10 "dynamic" modbuss adresses..
i do not curently get the adress from a database, but it is added "dynamically"

here is link to a flow which i belive have what you want.

Modbus flow link

Great, thanks a lot!!! Today, I will try with that flow...

Well, I have checked the flow you sent me, but I was not able to understand the logic.
I'm new with node-red. I don't see any database connection in that flow.

No it is not, but It ca be .

The ip address now is from fixed field , but that could be replaced with a variable which comes from a database .

Do not know what you use , but could use node-red-contrib-mysql node to get data from a database , and there should be an example there how to get data .

I will look at it later and could create a example flow .

i tried creating a simpler flow. hope this is easier to understand.

where i run a SQL select staement against a datbase, using the "node-red-node-mysql" , depending on what node you are using for communicationg with database, this can varey.

in this case i set msg.topic as the sql statement like . msg.topic = "select * from table"
the result is an array of objects, where each object is a row from the table,

so in this case row one goes to mdbus 1 and row 2 to modbus 2.
so if i have a table that have a column named "IP" which has the ip adress.

then i would set modbus 1 'tcpHost' to msg.payload[0].IP
and modbus 2 'tcpHost' to msg.payload[1].IP
[0] is the first object in the array, [1] second etc.

Debug nodes, is realy great to see how the data is ouptut from nodes, ( just set it to "complete msg object, if you want ot se more than just payload)

[{"id":"95dd177d.0ec428","type":"function","z":"786aa205.67036c","name":"set ip MODSBUS 1 ","func":"\n//msg.payload is the output from the DB node, based on teh sql query. \n// in this case it was a select * from table.\n// this returns an array of objects where each object is a row from the table. \n // so msg.payload[0] would be row 1, msg.payload[1] is row 2 etc. \n \n // msg.payload[0].IP gets the value of the column IP\nlet IPfromDB = msg.payload[0].IP;\n\n// this is the payload and objects the modbus node require to be dynamically configured\n//, as seen in the help documentation in the sidebar for the nodemodbus-flex-connector.\n\nmsg.payload = { 'connectorType': 'TCP', 'tcpHost': IPfromDB, 'tcpPort': '502' ,'unitId': 1 };\n\n\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":770,"y":1300,"wires":[["c04e4eef.d43cd"]]},{"id":"c65ab527.cd31d8","type":"function","z":"786aa205.67036c","name":"Set IP MODBUS 2","func":"\n//msg.payload is the output from the DB node, based on teh sql query. \n// in this case it was a select * from table.\n// this returns an array of objects where each object is a row from the table. \n // so msg.payload[0] would be row 1, msg.payload[1] is row 2 etc. \n \n // msg.payload[1].IP gets the value of the column IP\nlet IPfromDB = msg.payload[1].IP;\n\nmsg.payload = { 'connectorType': 'TCP', 'tcpHost': IPfromDB, 'tcpPort': '502' ,'unitId': 1 };\n\n\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":770,"y":1360,"wires":[["bffc1174.11d6f"]]},{"id":"c2581f78.3ab79","type":"comment","z":"786aa205.67036c","name":"node-red-node-mysql","info":"This gets kicked off from another flow, the the localIpadress is set","x":440,"y":1260,"wires":[]},{"id":"c04e4eef.d43cd","type":"modbus-flex-connector","z":"786aa205.67036c","name":"RIO1","maxReconnectsPerMinute":4,"emptyQueue":false,"showStatusActivities":true,"showErrors":true,"server":"ab37667f.3b2f58","x":1010,"y":1300,"wires":[[]]},{"id":"bffc1174.11d6f","type":"modbus-flex-connector","z":"786aa205.67036c","name":"RIO2","maxReconnectsPerMinute":4,"emptyQueue":false,"showStatusActivities":true,"showErrors":true,"server":"fdab6cca.05a03","x":1010,"y":1360,"wires":[[]]},{"id":"cb8cb957.9889c8","type":"mysql","z":"786aa205.67036c","mydb":"66c70f7d.c4693","name":"","x":440,"y":1300,"wires":[["95dd177d.0ec428","c65ab527.cd31d8","e4e99373.7d716","dff4296d.e93f28"]]},{"id":"259a2600.834f3a","type":"inject","z":"786aa205.67036c","name":"set msg topic as SQL statement","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"select * from table","payload":"","payloadType":"date","x":210,"y":1300,"wires":[["cb8cb957.9889c8"]]},{"id":"e4e99373.7d716","type":"debug","z":"786aa205.67036c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":1240,"wires":[]},{"id":"dff4296d.e93f28","type":"debug","z":"786aa205.67036c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":710,"y":1180,"wires":[]},{"id":"66c70f7d.c4693","type":"MySQLdatabase","z":"","name":"","host":"127.0.0.1","port":"3306","db":"databasename","tz":""}]

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