I'm pretty new to all of this so please excuse my ignorance.
I'm running Node-Red on a Raspberry Pi 4 (Standard Raspbian Operating System) and I'm trying to retrieve some data from a PLC and then send that data via MQTT. The Raspberry Pi is connected to the PLC via an ethernet cable and the Raspberry Pi is connected to my Wifi for an internet connection.
The PLC is a Siemens PLC so I'm using the node-red-contrib-s7 library to communicate with it.
I have been able to successfully communicate with the PLC via the ethernet connection and retrieve data. Separately I've been able to successfully send and receive MQTT messages over WiFi, but when I try and do both, one of them doesn't work.
This is the basic flow at the moment:
All I want to do at the moment is log an MQTT message (over WiFi) and at the same time log data from the PLC (over the LAN connection with an ethernet cable).
When I first set up this flow, the PLC connection was working, but the MQTT connection didn't work. Then I rebooted the Raspberry Pi, and when it started up, the MQTT connection was working but the PLC connection wouldn't work.
Is this not working because I'm trying to send and receive data over two different Network Interfaces? Is it possible to use two Network Interfaces at once? Or is there a way of defining which network interface you want Node Red to use? Or have I made some other silly mistake?
I am guessing the PLC and the WiFi are different IP addresses?
Then you need the RasPi to do is basic NAT (Network Address Translating)
Really that could be done with a WAP.
I'm not sure I get why you are complicating things.
Even if the PLC and WiFi are on the same IP range, why do you have/use a RasPi?
Seems overkill to me.
I will do some googling on the topics you have given me to look at and see what I can do. Thanks!
The reason is that the PLC has no way to connect to the internet. I'm using the RasPi as a way to retrieve data from the PLC and send it to a server on the cloud which the PLC is unable to do on it's own. If there's a simpler way I'm all ears!
There's no need to bridge these two interfaces, as a fact, I would advice against it for security reasons.
You need two different IPs from different subnets for your PLC network (connected to LAN I presume) and your normal intranet (connected to Wifi). Two IPs from the same subnet won't work, at least not without further manual tuning (static routes and proper gateway configuration).
What is your raspberry pi's IP address on those 2 interfaces? I wonder if you've lost connection to the PLC because your pi's IP changed when you rebooted it. Or, if you're using the same IP range for both connections (wired and wireless), maybe that screws things up?
Something that's worked for me before (with a different brand of PLC) was to use the modbus node (node-red-contrib-modbus). With this scheme, the PLC was programmed with a modbus write instruction, and the data went from the PLC over a wired (ethernet connection) to the pi, into like imaginary registers in the modbus node in node-red. Then I was able to read those out , and send them to other computers, etc over wifi with MQTT, http out, etc. It did take some messing around with, and the modbus node was a little quirky (for example, I had to space out writes to the modbus node's registers by a couple milliseconds to make sure data going in didn't ever get dropped). But in the end it did work.
If you copy and paste here the output of running ifconfig on the Pi's terminal window, it could give some clues.
This is a valid question although I can imagine also why you would want to connect it directly to the Raspberry. For instance the WiFi router might be in a difficult place to draw a cable to. Or perhaps the WiFi router is just a 3G/LTE box with no ethernet port.
Do something equal to what you want and I found the solution in a forum too
The solution to your problem is to lower the wlan0 metric to a value of, for example, 50. And to do this you must edit the file ** / etc / dhcpcd.conf ** in sudo mode, go to the end of the file and download the wlan0 metric from 500 to 50.