How Change node properties with a function block


#1

I want change URL of WebSocket node with a function block.

my URL on WebSocket was variable, and necessary to change, it is possible?

image


#2

You cannot dynamically change the the url of a websocket endpoint, it is only examined at Node-RED startup.

There really aren't many cases where you would actually want this anyway so you might want to explain why you are wanting to do this, perhaps we can think of alternative approaches.


#3

ok.

i'm monting a equipament that have a HMI and a raspberry, the HMI make de connection with the raspberry via modbus, and read/write variables the system, and raspberry make the connection with the plataform. but the URL must be change, because if i provide my solution for other people, these people must to put on other url of your platoform.
i provided variables on the HMI for change the URL, and the raspberry read this information and change de url on websocket, but before change the url, the raspberry open the web socket, generating error, because the url is not define.


#4

If I've read this right, you want to allow people to change the url before they start the Node-RED based system. Not dynamically. That's because they just need to be able to ensure that the url doesn't clash on their system.

Actually, even that isn't an issue unless you are giving them a FLOW to use in their own instance of Node-RED since they must choose an unused PORT for Node-RED so they would never have clashing URL's in any case.

If you are giving them a flow to use and they may have created their own URL's in their instance of Node-RED, what you need to do is allow a global configuration to be set in their settings.js. To do that, you will need a custom node I think. However, someone got there already since node-red-contrib-uibuilder allows the user to configure a URL and creates a websocket connection on a matching path. While this is generally designed to be used with front-end code and my uibuilderfe.js library, it wouldn't be hard to adjust for other uses.


#5

I solved this problem.

the firt thing i did, was on my dashboard, i create one variable with url on JSON file.

then on node of websocket i call this file, selecting the variable of url.