Ethernet and WiFi at the same time?

Hi everyone,

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:
image

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?

Thanks in advance for your thoughts!

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.

Doing it that way you would need to set up a bridge (between eth0 and wlan0) on the RPi. If you google RPi bridging you will find what you need.

Thanks guys,

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! :stuck_out_tongue:

Thanks again for your help

Errrrrrr..... Sorry?

If the IP can be configured, then there isn't a problem.

It doesn't need to connect to the internet.

Say:

You local IP range is 10.0.0.1

You set it to ....... 10.0.0.33 (hey, I'm exotic)

And the set the node siemens PLC to the correct IP address and all should work.

You don't need to bridge (thanks @Bobo for that term) anything.

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).

1 Like

Why don't you do it the usual way, which is to connect the PLC to the router instead of to the PC?

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.

Yes, it is possible, but it does make life more difficult, so unless there is a good reason it would be easier if it were connected to the router.

Agree 100%.

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.

** Code: [Select all] (https://www.raspberrypi.org/forums/viewtopic.php?t=216917) **

sudo nano /etc/dhcpcd.conf

** Code: [Select all] (https://www.raspberrypi.org/forums/viewtopic.php?t=216917) **

interface wlan0

metric 50

After restarting the system, you should have internet access.

I found this and I share it for your project is not mine is from another forum.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.