Integrating Node-Red with external website


Hi everybody!

I'm completely new to node-red but need to create some project that integrates PLC controller with web interface running on external server. I do it using SQL database running on the same server as the website and it works perfectly for displaying charts, data archives etc. My application looks now like this: I have PLC connected to the microcontroller (Siemens SIMATIC IOT2040) and these two devices communicate fine. I have the IOT connected to the Internet and send data gathered from PLC to the external SQL server using "mysql" node - it also works great.

I've unfortunately faced totally different problem. I would like to get some signals from external website via node-red but compeletely have no idea how to do so. The idea is to create some html form with mainly buttons, but also maybe text fields and receive them in node-red. I tried to use http node with post method but it didn't work - I get no message. As far as I read, the http is mostly used for connecting node-red program with locally running websites but is there any way to connect it with external website? I eventually thought about setting some record in SQL database via html button and read that value in node-red via "mysql" node but it doesn't look like a good solution for me...

Thank you in advance for all reponses!



Perhaps if you could export your flow and paste it into this thread, we could provide better suggestions. Please use 3 backtics on separate lines before and after the pasted json string, so that it formats properly.

It sounds like you are on the right track -- the external system generates the form with the buttons/text, and submits the data to node-red. Your flow then starts with an http in node listening for POSTs, processes the data, and ends with an http response node (the returned msg can be empty, but the returned status must be 200 to get a successful response).

One thing to watch for is that you do NOT overwrite or change the msg.res field on the original msg coming from the http in node. That information is used to respond to the correct http client that submitted the request.



I am unsure about exactly what you want to do. Do you mean that the form runs on node-red and then based on what is entered it has to go and fetch data from the external site, or do you mean the form runs on the external website and when the user submits the form it has to send data to node-red?



I need the second option you described - the form runs on external website and when user submits it, the data should be send to node-red.



In that case the next question is can the machine running node red be accessed from the website server? If they are both on the same local network then that should not be a problem, but if the website server is across the internet from the node-red server then to post from the website server to node-red would require opening up the node-red server to the internet, to some extent, with all the security implications of that. If you don't understand the security implications of that then don't do it that way, there are other ways which can be consider if necessary.



There is certainly quite a lot to do in order to have any chance of reasonably security when connecting to Node-RED over the Internet. It isn't a job to be undertaken lightly but that is (should be) true of any system you connect to the Internet.

My advice is to make use of external tools to ensure the security of the connection and add lots of sanity and error checks against any incoming data.

As a minimum, you need to ensure that any connection can only happen over HTTPS (TLS) & to trim and sanitise incoming data. Since Node-RED isn't designed as a web service as such, you should consider (strongly) adding something between Node-RED and the Internet. Either a reverse proxy such as NGINX or HAproxy configured to terminate and secure incoming connections - or the tools that Cloudflare offer for securing web apps. I would even consider using both if the data and service has any value whatsoever.