2

I have an oscilloscope that I want to access from my laptop. The scope only has a LAN connection, and my laptop is connected to my wifi. I can't connect the scope to my wifi router because I want the scope to be mobile. A direct LAN connection between laptop and scope is possible, but also not desired because it would make my laptop less mobile.

The scope is a Rigol DS1054Z, with a browser interface and LXI interface (I'll probably use python-vxi11). The following setup works (I can access the scope's internal server when I enter its IP in a browser running on the laptop), but the scope isn't mobile but tied to the router:

Router---(Wifi)---Laptop
     |---(LAN)----scope

And this is what I get when I enter the scope's IP in the browser: enter image description here

To make the scope mobile, I want to connect it to a raspberry pi and have a wireless interface for the scope. The network would look like this:

Router - (Wifi)---Laptop
              |--- [wlan0 RPi eth0] --- scope

To sum up my overall goal:

  • connect the scope to the raspberry pi using a normal LAN cable
  • configure the pi to act as a bridge between its eth0 and wlan0 interfaces
  • let my wifi router (DHCP) assign an IP address to the scope (this might be optional
  • connect to the scope from my laptop

What I've tried: I installed bridge-utils on the pi, and added /etc/network/interfaces.d/br0 with the following contents:

auto br0
iface br0 inet dhcp
    pre-up ifup wlan0
    bridge_ports eth0 wlan0
    bridge_fd 5
    bridge_stp no

As far as I understand it (and my understanding of networking is only very very very basic), this should glob up wlan0 and eth0 and magically make the scope appear in the network.

Once I restart the pi, I can see the br0 is indeed up:

$ ifconfig
br0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether b8:27:eb:86:3c:ee  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether b8:27:eb:86:3c:ee  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 2  bytes 78 (78.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2  bytes 78 (78.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.178.46  netmask 255.255.255.0  broadcast 192.168.178.255
        ether b8:27:eb:d3:69:bb  txqueuelen 1000  (Ethernet)
        RX packets 70  bytes 9163 (8.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 57  bytes 9372 (9.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

I can't see the scope appear in my router's list of devices. I guess it's just not enough yet. Is the bridge approach suitable in the first place?

  • 1
    You cannot bridge a wireless interface which is in station mode. You can, however, route through it. – Torin Dec 16 '18 at 2:30
3

Edited my answer to make it more useful.

I don't think the bridge will work (you're device will not know how to use the bridge interface).

A few google searches however led to the following (they all seem to be suggesting the same set-up):

1: make sure you revert your changes.

2: Install dnsmask

sudo apt-get install dnsmasq

3: Make sure your wifi on your pi automatically connects by editing wpa_supplicant.conf:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Replace the ssid and password to match your network:

network={
    ssid="networkname"
    psk="networkpassword"
}

4: Configure the "bridge"

sudo nano /etc/dhcpcd.conf

Make sure you're using correct interface names, you can find yours by invoking ifconfig. Assuming your routers network is not 192.168.220.0.

note: the source mentions eth0, while providing an example with wlan0!

Within this file we need to add the following lines, make sure you replace eth0 with the correct interface of your ethernet.

interface wlan0
static ip_address=192.168.220.1/24
static routers=192.168.220.0

5: restart

sudo service dhcpcd restart

6: Make sure the wired connection is routed through the wireless adapter

sudo nano --backup /etc/dnsmasq.conf

The --backup ensures we create a backup of the original file (dnsmasq.conf~)

interface=eth0       # Use interface eth0  
listen-address=192.168.220.1   # Specify the address to listen on  
bind-interfaces      # Bind to the interface
server=8.8.8.8       # Use Google DNS  
domain-needed        # Don't forward short names  
bogus-priv           # Drop the non-routed address spaces.  
dhcp-range=192.168.220.50,192.168.220.150,12h # IP range and lease time

7: Make sure the traffic is forwarded:

sudo nano /etc/sysctl.conf

Uncomment the line

#net.ipv4.ip_forward=1

In order to get

net.ipv4.ip_forward=1

Enable the changes without reboot:

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

8: Add firewall rules to forward eth0 traffic to wlan0

sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE  
sudo iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT  

Make the changes permanent:

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

9: Load rules after a (re)boot:

sudo nano /etc/rc.local

Insert before exit 0

iptables-restore < /etc/iptables.ipv4.nat

10: start dnsmasq:

sudo service dnsmasq start

11: reboot

sudo reboot

These steps are copied from https://pimylifeup.com/raspberry-pi-wifi-bridge/amp/

  • I followed the steps above, but service dnsmasq start showed an error: Couldn't assign requested adress. Then I changed the interface in dhcpcd.conf to eth0 (because wlan0 gets an IP from the router's DHCP server) and the error disappeared. I could then ping the scope from my pi, but not from my laptop. – Christoph Dec 16 '18 at 19:13
  • "Assuming your routers network is not 192.168.220.0." - this sentence is confusing to me. Is the following written on the assumption that my router's network is not 192.168.220.0 (so it's safe to use that IP for other purposes) or are you assuming that the router's network is different, and I should adapt the following to suit my router's network? – Christoph Dec 16 '18 at 19:21
  • It assumes your router is on a different network, so it is safe to use this internal network on the wlan0 interface. It is perdectly fine to have multiple IP addresses assigned to a single interface. In this case it is the way to internally forward traffic from eth0 to wlan0. Therefore you should not change interfaces. – Kasper Agg Dec 16 '18 at 19:23
  • My conclusion then is that I should change the IP to be in the router's IP range? That'd be 192.168.178.xxx, as shown in the screenshot I edited into my question. – Christoph Dec 16 '18 at 19:26
  • No, this other range is intentional not be confused with the destination network. – Kasper Agg Dec 16 '18 at 19:27
1

You need NAT instead of bridge. I don't think bridging to a Wifi station interface works (as Carey said).

1.

Router - (Wifi)---Laptop
             |--- [wlan0 RPi eth0] --- scope

After setting up your connection like that, you need to setup NAT network between Pi and scope.

To setup NAT network, allow me to introduce a script linux-router. It's designed to make things(dnsmasq, iptables, forwarding) easier for human, so we don't have to manually do it. (Agg's answer has already provide the way to manually do it)

Run one command on Pi to setup a NAT network:

# lnxrouter -i eth0

the script will do all the stuff needed to setup a NAT network 192.168.18.0/24 between Pi and scope. The Pi's eth0 IP is 192.168.18.1

You can see the scope's IP 192.168.18.x from that script's output after scope automatically bootstrap.

2.

To access scope from laptop, you have to log into your wifi router and edit routing table.

Route 192.168.18.0/24 network through Pi's wlan0 IP (it should be 192.168.178.x according to the image you post).

(If you can't or don't want to log into wifi router, setting routing table of laptop also works. Linux and Mac allow users to customize routing table, not sure about Windows.)

3.

If you just need to access the scope's "web interface and LXI interface", you can setup reverse proxy on Pi, so no need to edit routing table.

There should be port 80 for web and another port for LXI open on scope. Set two ports open on Pi to reverse-proxy the traffic to the ports on scope. So your laptop can access scope by entering Pi's wlan0 IP and ports.

If scope support setting IP manually (or IPv6 link-local fe80:: address), no need to set DHCP or forwarding on Pi.

Reverse proxy is like:

laptop-->--(Port A)Pi-->--(web)scope
laptop-->--(Port B)Pi-->--(LXI)scope
  • I guess both answers are converging towards more or less the same solution, just from a different perspective and level of detail? I can set an IP for my scope manually. I could even give a pi a fixed manually set IP in the wifi network, if that makes things easier. – Christoph Dec 17 '18 at 9:21
  • @Christoph If so, I believe reverse proxy is the easist (though I didn't set one before) – garywill Dec 17 '18 at 11:01
1

This solution was suggested by a friend and it worked without much hassle.

Overview

enter image description here

Raspberry Pi setup

  • I started with a fresh download of raspbian stretch lite 2018-11-13
  • enable ssh (place a file called ssh in the boot partition)
  • set up wifi (place an appropriate wpa_supplicant.conf in the boot partition)
  • set a static IP for eth0 in /etc/dhcpcd.conf:

    interface eth0
    static ip_address=192.168.220.1/24
    static routers=192.168.178.1
    

    and restart dhcpcd:

    sudo service dhcpcd restart
    
  • in /etc/sysctl.conf, enable IPv4 forwarding by uncommenting the line

    #net.ipv4.ip_forward=1
    

    to get

    net.ipv4.ip_forward=1
    

    apply:

    sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
    
  • I also rebooted after this step, I'm not 100% sure if that's strictly necessary.

Oscilloscope setup

The scope gets a static IP in the new subnet. This can be configured with the scope's utility menu, as described in the manual.

enter image description here

Router setup

How these steps are done depends on your router:

  • Router's DHCP is configured to always give the RPi's wlan0 the same address. In this case 192.168.178.46. Alternative assign a static IP to the RPi's wlan0.
  • Add a route to 192.168.220.0, subnet mask 255.255.255.0, via 192.168.178.46(RPi's wlan0).

Laptop setup

Nothing to do regarding the network, as long as it's in the wifi router's wifi.

I used https://pypi.org/project/ds1054z/ to take the following

screenshot:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.