Use constant with ip address stored in node configuration (http request)

Hi
I use following flow to control a music streamer by gpio button.

As I use more then one "http request node" and ther will come more, I would like to replace the IP Adress in "http request" node by a variable or constant. Best would be I could edit the adress in dashboard.

Is this possible and when yes how?

Its in the built in help...
image

Basically, clear the node settings URL field, then pass it into the HTTP request via msg.url

Thank. What I forgot to mention, my url looks like this

http://192.168.1.122:11000/Preset?id=2 and I only want to replace the bold section.

you can make your msg.url whatever you want

e.g.

function node...

msg.url = "http://" + msg.ip + ":" + msg.port + "/Preset?id=2"
return msg.

Or

use a change node to contruct the URL

Or

the http-request node itself supports mustache syntax (again, its in the help) but to get you moving...
set the URL field to http://{{ip}}:{{port}}/Preset?id=2


NOTE: All of these examples assume the IP is in msg.ip and port is in msg.port

1 Like

Thanks

I did following for testing. But the msg.ip and msg.port are not defined in the other flows.
So I think i have to find a way to make them defined, what needs more to know about the node red
system, and some study from me.

[{"id":"482d7c90.87f404","type":"inject","z":"538c0a77.5b11b4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":160,"wires":[["5a6d815a.0cef","3d16c25f.6f56ae"]]},{"id":"5a6d815a.0cef","type":"debug","z":"538c0a77.5b11b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":160,"wires":[]},{"id":"3d16c25f.6f56ae","type":"http request","z":"538c0a77.5b11b4","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://{{ip}}:{{port}}/Preset?id=2","tls":"","persist":false,"proxy":"","authType":"","x":630,"y":220,"wires":[[]]},{"id":"a67b305f.b5248","type":"ui_button","z":"538c0a77.5b11b4","name":"","group":"81edf5e0.aee808","order":2,"width":0,"height":0,"passthru":false,"label":"Preset2","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":160,"y":240,"wires":[["3d16c25f.6f56ae"]]},{"id":"11da751a.83e30b","type":"change","z":"538c0a77.5b11b4","name":"","rules":[{"t":"set","p":"ip","pt":"msg","to":"192.168.1.122","tot":"str"},{"t":"set","p":"port","pt":"msg","to":"11000","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":40,"wires":[["a1a93a46.e0ac58"]]},{"id":"ad5f4e7f.ea2aa","type":"inject","z":"538c0a77.5b11b4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":40,"wires":[["11da751a.83e30b"]]},{"id":"a1a93a46.e0ac58","type":"debug","z":"538c0a77.5b11b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"ip","targetType":"msg","statusVal":"","statusType":"auto","x":620,"y":40,"wires":[]},{"id":"17fdbb9.ef44644","type":"inject","z":"538c0a77.5b11b4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":190,"y":100,"wires":[["7ed59f41.f787"]]},{"id":"7ed59f41.f787","type":"debug","z":"538c0a77.5b11b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"ip","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":100,"wires":[]},{"id":"81edf5e0.aee808","type":"ui_group","name":"Presets","tab":"5b0d07a7.12a4d8","order":2,"disp":true,"width":"6","collapse":false,"className":""},{"id":"5b0d07a7.12a4d8","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]