IP Address as a variable

I guess I'm reopening up my question from before:

I am collecting data using Modbus TCP. I'd like the remain flexible and let the user enter their own IP address. it was brought up to use environmental variables. But maybe I'm not using the variable properly:

I have a text entry and it's payload is set to $IP
image

Then under host I have this
image

calling the IP.

[{"id":"dbf7fbb9.bab5b8","type":"tab","label":"Configuration","disabled":false,"info":""},{"id":"f5547811.4bbe48","type":"ui_text_input","z":"dbf7fbb9.bab5b8","name":"IP Address Entry","label":"Enter IP Address","tooltip":"","group":"b3ef20e6.67bde","order":0,"width":0,"height":0,"passthru":true,"mode":"text","delay":300,"topic":"test","x":210,"y":120,"wires":[["d9b2798f.888c48","d2eccda6.fa55a","8c43767.d750388"]]},{"id":"d9b2798f.888c48","type":"function","z":"dbf7fbb9.bab5b8","name":"","func":"\nglobal.set(\"IPAddress\", msg.payload)\n\n// global.set(\"1750_1_dc_sp\", msg.payload);\n\n// msg_o = {topic: \"DC Setpoint\", payload: msg.payload};\n\nreturn false;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":400,"y":340,"wires":[[]]},{"id":"d2eccda6.fa55a","type":"ui_text","z":"dbf7fbb9.bab5b8","group":"b3ef20e6.67bde","order":1,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":680,"y":240,"wires":[]},{"id":"8c43767.d750388","type":"change","z":"dbf7fbb9.bab5b8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"IP","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":280,"wires":[[]]},{"id":"38b8a176.32dfce","type":"modbus-read","z":"dbf7fbb9.bab5b8","name":"1750+ 1","topic":"1750 1","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"0","dataType":"Coil","adr":"19","quantity":"27","rate":"1","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"fdbc6bac.988e58","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":620,"y":340,"wires":[[],[]]},{"id":"13f7f91a.ce2587","type":"debug","z":"dbf7fbb9.bab5b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":100,"wires":[]},{"id":"b3ef20e6.67bde","type":"ui_group","name":"Configuration","tab":"a2c64017.1f61b","order":3,"disp":true,"width":"6","collapse":false},{"id":"fdbc6bac.988e58","type":"modbus-client","name":"1750+","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"${IP}","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":1,"commandDelay":1,"clientTimeout":1000,"reconnectOnTimeout":true,"reconnectTimeout":2000,"parallelUnitIdsAllowed":true},{"id":"a2c64017.1f61b","type":"ui_tab","name":"Configuration","icon":"dashboard","disabled":false,"hidden":false}]

Where am I going wrong?

This person did something similar. I thought I did everything the same, I guess not:

self bump

For this to work you will need to set the system environment variable and then restart node red.

How do I set the system environment variable?

How do I restart node red from the node red dashboard?

I don't think it is possible from within node-red.

Restarting node-red has been discussed here many times, a forum search should find it easily.

Maybe this is possible to change the modbus config settings
with a node in the collection called Modbus Flex Connector

I havent used it in a real world example but i did some tests with a modbus software simulator
and seems to work.
Here is the flow that sets, as an example, a different port for that modbus config.

Flow:

[{"id":"c312db7a02c1f4dd","type":"modbus-flex-sequencer","z":"5847b7aa62131d37","name":"","sequences":[{"name":"1","unitid":"1","fc":"FC1","address":"1","quantity":"1"}],"server":"ebeab3422d31a778","showStatusActivities":true,"showErrors":true,"logIOActivities":false,"useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"x":540,"y":80,"wires":[["552a9e388d7eda29"],[]]},{"id":"99da7dfd84cbd186","type":"inject","z":"5847b7aa62131d37","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":160,"y":80,"wires":[["6c8c4aeace8044d9"]]},{"id":"6c8c4aeace8044d9","type":"function","z":"5847b7aa62131d37","name":"","func":"msg.sequences = [\n    {\n        name: \"Foo\",\n        unitid: 1,\n        fc: 3,\n        address: 1,\n        quantity: 1\n    },\n    {\n        name: \"Bar\",\n        unitid: 1,\n        fc: 3,\n        address: 10,\n        quantity: 2\n    },\n    {\n        name: \"Baz\",\n        unitid: 1,\n        fc: 'FC3',\n        address: 20,\n        quantity: 3\n    }]\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":80,"wires":[["c312db7a02c1f4dd"]]},{"id":"e387b5cf3a56528a","type":"debug","z":"5847b7aa62131d37","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1130,"y":80,"wires":[]},{"id":"552a9e388d7eda29","type":"join","z":"5847b7aa62131d37","name":"","mode":"custom","build":"object","property":"responseBuffer.buffer","propertyType":"msg","key":"modbusRequest.name","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":770,"y":80,"wires":[["0cd883411cc554c7"]]},{"id":"0cd883411cc554c7","type":"change","z":"5847b7aa62131d37","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"responseBuffer.buffer","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":940,"y":80,"wires":[["e387b5cf3a56528a"]]},{"id":"602c2fb9189b3c62","type":"modbus-flex-getter","z":"5847b7aa62131d37","d":true,"name":"","showStatusActivities":true,"showErrors":true,"logIOActivities":false,"server":"ebeab3422d31a778","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"x":620,"y":200,"wires":[["167f353c05c28461"],[]]},{"id":"9eb2b47107b96ed8","type":"inject","z":"5847b7aa62131d37","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":250,"y":200,"wires":[["2996681554f2e749"]]},{"id":"2996681554f2e749","type":"function","z":"5847b7aa62131d37","name":"","func":"msg.payload = {\n    name: \"Foo\",\n    fc: 3,\n    address: 1,\n    unitid: 1,\n    quantity: 10,\n}\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":200,"wires":[["602c2fb9189b3c62"]]},{"id":"167f353c05c28461","type":"debug","z":"5847b7aa62131d37","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":910,"y":180,"wires":[]},{"id":"5e8844296c95858c","type":"modbus-flex-connector","z":"5847b7aa62131d37","name":"","maxReconnectsPerMinute":4,"emptyQueue":false,"showStatusActivities":false,"showErrors":false,"server":"ebeab3422d31a778","x":650,"y":360,"wires":[[]]},{"id":"de343ff69f1f4da3","type":"inject","z":"5847b7aa62131d37","name":"Device port 502","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":260,"y":320,"wires":[["b8f8914c9d5d69ae"]]},{"id":"cd1baf7d357f6329","type":"inject","z":"5847b7aa62131d37","name":"Device port 503","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":260,"y":400,"wires":[["a46d180a4664a236"]]},{"id":"b8f8914c9d5d69ae","type":"function","z":"5847b7aa62131d37","name":"","func":"msg.payload = {\n    'connectorType': 'TCP',\n    'tcpHost': '192.168.0.66',\n    'tcpPort': '502',\n    'unitId': 1\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":320,"wires":[["5e8844296c95858c"]]},{"id":"a46d180a4664a236","type":"function","z":"5847b7aa62131d37","name":"","func":"msg.payload = {\n    'connectorType': 'TCP',\n    'tcpHost': '192.168.0.66',\n    'tcpPort': '503',\n    'unitId': 1\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":400,"wires":[["5e8844296c95858c"]]},{"id":"b90d7f7951814165","type":"comment","z":"5847b7aa62131d37","name":"Change Mod. Config Settings","info":"","x":680,"y":300,"wires":[]},{"id":"ebeab3422d31a778","type":"modbus-client","name":"","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"192.168.0.66","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"","unit_id":"0","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":false,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true}]
1 Like

This did it! Thanks!
I can't believe there was a block that helped with this this entire time!. Thanks for the script too! Helped a lot.

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