haughian24
Posts: 5
Joined: Fri Mar 09, 2018 10:46 am

Wifi Bridge to PLC

Fri Mar 09, 2018 11:03 am

I know this topic has been covered 100's of times but I am really struggling.

I would like to connect my Pi to my router which has a static ip address. ---- no problem with that
I have set the Wlan0 on the pi to have a static ip address
so i can ping that ip address from another device connected to the same router. ----- no problem so far

I have a Siemens PLC that has a static ip address. when i connect the PLC to the eth0 on the pi i can ping the ip address from the terminal--- no problem with that bit


i want to be able to bridge the Ethernet to wifi so that i can ping the PLC ip address from another device on the router.

i have tried various methods of bridging the wlan0 to eth0 but then soon as i connect the Ethernet to the pi i then cant even ping the wifi static ip address it defaults to the eth0

the only way i have been able to ping the PLC through the pi is to set the pi up as a access point and bridge the connection then connect a wifi device to the pi and ping it that way but that defeats the point of connecting the pi to my router and means if i had 20 PLC's then i would need 20 wifi usbs connected to my laptop so i could connect to each pi.

The project is to have 20-30 PLC's each connected to a Pi then each on of them connected to the wifi router then from one device be able to ping each individual PLC

i see that most tutorials are for forwarding Internet access from wifi to Ethernet i kind of want to do it the other way?

any suggestions?

i am using a Pi 3 with stretch

Thank You

epoch1970
Posts: 5203
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Wifi Bridge to PLC

Fri Mar 09, 2018 1:17 pm

You use the term bridge a lot, I understand you need to have the PLCs and the workstation on the same network, no routing at all.
If this is not the case, please disregard.

Maybe you could consider this method
This creates a 2-port virtual switch: one port connected to the "main" ethernet network, one port connected to a "satellite" ethernet network, and the wifi link serves as switch fabric.
It is a switch, so all machines are on the same network. The broadcast traffic will go over wifi, so you'd better have a reasonably quiet network and solid wifi coverage.
OpenVPN isn't the only method to tunnel L2 over L3 but it works easily and is portable.

Depending on your application and wifi link quality I think that could scale to 30 machines on the network (30 ports...). Especially if you could deploy physical switches to connect more than one PLC behind each Pi.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

SurferTim
Posts: 1769
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Wifi Bridge to PLC

Fri Mar 09, 2018 1:31 pm

Are you using a bridge or a NAT? I suspect a NAT due to the fact you cannot bridge a wireless client to another interface with Stretch.

I use a NATed network to connect an ethernet interface to the internet using the wireless client interface. Is that what you want? If so, and you want to access the ethernet client devices from wireless devices, you need to install a route on your router to that network. Do you have access to the router's setup?

haughian24
Posts: 5
Joined: Fri Mar 09, 2018 10:46 am

Re: Wifi Bridge to PLC

Fri Mar 09, 2018 7:00 pm

Sorry for the incorrect terminology and the over the top explanation

In simple terms I want to see the IP address of the Pi's eth0 via the built in wifi

i want to connect a laptop either to a router or directly to the wifi of the pi then see the plugged in eth0

SurferTim
Posts: 1769
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Wifi Bridge to PLC

Fri Mar 09, 2018 7:20 pm

haughian24 wrote: Sorry for the incorrect terminology and the over the top explanation

In simple terms I want to see the IP address of the Pi's eth0 via the built in wifi

i want to connect a laptop either to a router or directly to the wifi of the pi then see the plugged in eth0
You can using either a NAT or a bridge ap. The bridge would be the best if you want to have access both ways.

epoch1970
Posts: 5203
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Wifi Bridge to PLC

Fri Mar 09, 2018 7:30 pm

+1 on bridged AP. That will be a direct connection from laptop to the AP on the Pi. On the network: laptop, PLC and the Pi (eth0)
But you're going to end up with 30 different SSIDs if you scale up...
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

haughian24
Posts: 5
Joined: Fri Mar 09, 2018 10:46 am

Re: Wifi Bridge to PLC

Fri Mar 09, 2018 7:52 pm

so i have a sd card set up with the bridged AP and that works fine.

i can connect directly to the Pi wifi the bridge works fine.


if i was to set up the router as a AP
is there a way to get the eth0 ip address if the pi is connected to the AP via wifi and my laptop was connected to the AP via wifi

due to the fact i want to scale it up i dont want to make each pi a AP

if so, how do i do it

Thank you

epoch1970
Posts: 5203
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Wifi Bridge to PLC

Fri Mar 09, 2018 11:07 pm

If the router is the AP, the Pis are clients (STAs in wifi parlance).
- Your laptop, the AP, the wifi card of every Pi are all on the same network.
- The PLCs (anything connected through eth0 on a Pi) must be on a different network. Wifi client bridging is not allowed. So the Pi has to route between its wlan interface and its ethernet interface:
* Source NAT (aka Masquerade) can be used to masquerade the real IP of the PLC with the Pi's wlan0 IP, allowing it to reach the external network. The general use case is "I want internet access".
* Destination NAT (aka "Port forwarding") can be used to connect to the PLC by hitting a specific port on the Pi's wlan0 IP, which gets forwarded to the PLC's IP on the same or another port. The general use case is "I have a web server at home, I want to make it accessible from the Internet"

I doubt your PLCs need much internet access. I believe DNAT might work for you, provided you don't need to forward a ton of ports, or different ports for different PLCs.

If you have a lot of ports/protocols you wish to access on the PLCs, then making the central network aware of the other networks managed by the Pis could be a better option.
In the router, you could declare a Pi's wlan0 IP as the gateway to another network by setting a static route. If the laptop tries to reach a PLC on that network, traffic will go to the main router, and from there to the Pi (wlan0) and from there to the PLC.
(You could also set the same static route directly in your laptop, if you're the only interested party)

In the end you'd need to define, say, 30 networks: 10.0.1.x, 10.0.2.x ... or better 192.168.22.0/29, 192.168.22.4/29 ... and enter the 30 static routes towards the 30 gateways. Then you'll need to configure the IP of each Pi (eth0) and each PLC on their /30 network.
(See this calculator or this table for subnetting info. A /30 IPv4 network has just enough room for 2 hosts (Pi eth0, PLC) and you can cram 64 of these in the space of a common /24 network)
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

haughian24
Posts: 5
Joined: Fri Mar 09, 2018 10:46 am

Re: Wifi Bridge to PLC

Tue Mar 13, 2018 4:46 pm

Thank you!!

i went with the DNAT route and it all worked fine when all devices pi and plc are on a class c network.
192.168.x.x
but soon as i want to connect the pi to the Class B 163.157.122.x making the pi have a static ip address of .54 i only can ping the wifi i cant see the plc any more. which is still on the 192.168.22.10


this is the iptable rule im using.

sudo iptables -t nat -A PREROUTING -p tcp --dport 5555 -i eth0 -j DNAT --to 163.157.122.54:5050

also the pi cant seem to find any other computer on the network through wifi, what would cause this? do i need to put in information about the access point that im using in the dhcpcd file?

Thank you in advance

Return to “Networking and servers”