Change Serial COM Port from webpage

Hi, I am using Node-RED to connect my laptop to a device that has serial communication and is connected to COM5. I am receiving the data in Node-RED through a serial in node and showing the data in a webpage by using uibuilder nodes.
I am looking for a way to change the serial COM port (for example, change "COM5" to "COM6") from the webpage, so that the user does not have to go to the node-red flow to change it. For this, I assume I need to have access to a variable that is associated with the COM port name of the "serial in" node. Do you know how to access this variable or if there is a way to achieve this? Thanks in advance.

image

I don't think this is possible.

Serial port is connected to hardware, it requires proper closing/opening of the port, which is done upon deploy I believe.

Don't think that is is possible with the NR serial port.
Maybe you can do something with Web Serial , it's the possiblity to communicate from you browser (Chrome) with a serial port.

Never used it myself in this way.

Hi, why not change a way to consider the whole thing.
How about change the lap-top to a device which has a fixed com port?
For commercial purpose, I introduce this netGate for you.
PN6400

One possibility is to use environment variables. You could have the user enter a comport number In dashboard, then in your flows, you could write this to a file and reboot node red. In your settings.js file you could read this value in and store it in the in process.env.COMPORT. lastly set the comport to ${COMPORT}

3 Likes

And that's the issue isn't it. To change node-red's com ports, you do have to restart node-red.

Certainly uibuilder can be your front end as long as you can work out the back-end method.

Unfortunately, I'm not aware of a way to "fix" the com port on windows like you can on Linux. But as you say Steve, you could have a function in your settings.js or some other node-red startup script that detects the correct port and sets the environment variable suitably. Not totally dynamic but it would remove the need from the users altogether.

1 Like

Hi, Steve. I created a .env file that is in the .node-red folder. In the webpage, the user can select a COM port. For example, if the user selects COM5, the plotlatlon node writes "COMPORT=COM5" to the .env file. In settings.js, I wrote require('dotenv').config() to include the environment variable from this file. However, when I restart node-red, ${COMPORT} does not update. But when I force it and write process.env.COMPORT = 'COM5', the serial in node starts working. Am I missing something?