Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    Using Raspberry Pi3 with Duet 2 Ethernet

    Scheduled Pinned Locked Moved
    Duet Hardware and wiring
    6
    24
    3.6k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • nikkerundefined
      nikker
      last edited by

      I literally just tried that lol. Although the Duet 2 reports an IP address and HTTP on port 80 i could not get it to connect. I used the IP address that the post had and maybe that was the problem. My network uses 192.168.50.XX with my router at 192.168.50.1 and the raspberry pi at 192.168.50.16. I tried to connect to 192.168.50.16 (rapsberry pi) and also specifying port 80 using 192.168.50.16 but no luck. Just in case I also tried the IP address the duet 2 was reporting but it didnt work either. Do i need to assign the static address and gateway to match my router?

      1 Reply Last reply Reply Quote 0
      • DocTruckerundefined
        DocTrucker
        last edited by DocTrucker

        Thinking a little further I'd set up the raspberry pi like a mini router. If that is what that guide does (didn't look at it in full) then for the duet the gateway and subnet addresses are relating to the network that the pi is creating. Therefore I would set the first three of the four parts of the IP adresses that the dhcp on the pi issues as unique rather than matching your home network. Then all you need to do is forward port 80 connections to the pi from your wifi network to the duet. When on your home network just talk to the address of the pi as if it were your duet.

        I'm doubtfull the machine name addressing would work like this - ie [machine name].local. You may need to forward some more ports and spoof the duet's mac address to achieve that.

        Running 3 P3Steel with Duet 2. Duet 3 on the shelf looking for a suitable machine. One first generation Duet in a Logo/Turtle style robot!

        1 Reply Last reply Reply Quote 0
        • nikkerundefined
          nikker
          last edited by

          I am fine with having to use the IP address for now... I am just trying to get a basic setup going so start tuning everything for my Voron 2.1 build. I will try it a bit more and post my results in a few. Thanks all for your help.

          incogizmoundefined 1 Reply Last reply Reply Quote 1
          • incogizmoundefined
            incogizmo @nikker
            last edited by incogizmo

            @nikker upvote for running a Voron, my 1.5 is jealous of your 2.1.

            Raspberry Pi's cant actually bridge the connections due to technical limitations, to achieve this you need to set up another IP range that is hidden behind the Pi.

            You do this by creating a DHCP server and assigning a DHCP range on the ethernet interface of the Pi. You then enable ip_forwarding in the linux kernel and then create iptables rules, enable MASQUERADE then you need to add your port forwards.

            When you followed the instructions in the link @DocTrucker provided where did you get up to?

            did you run a command that resembled the following?

            iptables -A PREROUTING -t nat -i <ethernet_interface> -p tcp --dport 80 -j DNAT --to-destination <duet_ip>:80

            When it is all setup correctly you normal network will not be aware or have any connection to the Duet network. To access the duet you need to enter the Pi's ip address and it will automagically redirect the traffic to and from the Duet.

            1 Reply Last reply Reply Quote 0
            • nikkerundefined
              nikker
              last edited by

              I am getting lost in all the post i am going through. I am reflashing an SD card with the last version of jessie and will start again with the link @DocTrucker provided. Stay tuned lol

              incogizmoundefined 1 Reply Last reply Reply Quote 0
              • incogizmoundefined
                incogizmo @nikker
                last edited by

                @nikker Only follow the first post in that link. Then run the iptables command I provided filling in the blanks.

                1 Reply Last reply Reply Quote 0
                • nikkerundefined
                  nikker
                  last edited by

                  @incogizmo two quick questions, in your iptables command "iptables -A PREROUTING -t nat -i <ethernet_interface> -p tcp --dport 80 -j DNAT --to-destination <duet_ip>:80" my ethernet interface is eth0 but that do i use for the duet_ip? is this an IP address i need to specify in config.g as the static IP and if following the first link where in the process do I type this command or does this replace the command "sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE"?

                  Thanks again for your help!

                  1 Reply Last reply Reply Quote 0
                  • nikkerundefined
                    nikker
                    last edited by

                    To anyone trying to do a similar setup, i got it working. When following the link that @DocTrucker provided, the command "iptables -A PREROUTING -t nat -i <ethernet_interface> -p tcp --dport 80 -j DNAT --to-destination <duet_ip>:80" is in addition to "sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE" and comes after. I have a paneldue connected and it told me the IP address that was being provided so I used that. All is working now!

                    Big thanks to @DocTrucker and @incogizmo !! Stay tuned for a post in a few weeks when I share my Voron 2.1

                    incogizmoundefined 1 Reply Last reply Reply Quote 1
                    • incogizmoundefined
                      incogizmo @nikker
                      last edited by

                      @nikker yes you were right both commands are needed. awesome work glad to hear 🙂

                      Also just looking over your previous post, it would be best to set a static IP on your Duet, otherwise there is a possibility DHCP will eventually provide your duet a different IP address. If this happens your port forwarding will break.

                      1 Reply Last reply Reply Quote 0
                      • nikkerundefined
                        nikker
                        last edited by nikker

                        So after some more tinkering, here are the steps used to use the Raspberry Pi 3's Wifi to connect a Duet 2 Ethernet to a network.

                        • Start with 2017-07-05-raspbian-jessie-lite (I read that with stretch it may not work or be harder... I used what was recommended here https://www.raspberrypi.org/forums/viewtopic.php?t=132674

                        • Get Wifi setup by placing a template wpa_supplicant.conf on the /boot as well as an empty file called "ssh" to enable the SSH server for headless setup (Details on how to do this in the link above).

                        • I use Bitvise SSH to connect to the RPI3.

                        • I opted to use a spare Alfa AWUS052NH high power diversity USB WiFi since I have two of them laying around. This creates a wlan0 and wlan1 but sometimes they get switched around. To keep each device with the same wlanX name I used the instruction on these link https://raspberrypi.stackexchange.com/questions/24318/how-do-i-stop-two-wireless-dongles-switching-between-wlan0-and-wlan1 I think this still only applies to Jessie and may not work with Raspbian Strech. Skip this is you are only using the RPI3's internal Wifi.

                        • Next setup a static IP for eth0 interface "sudo nano /etc/network/interfaces" and paste this. Make sure to comment out #iface eth0 inet manual

                        #iface eth0 inet manual
                        allow-hotplug eth0
                        iface eth0 inet static
                        address 192.168.1.1
                        netmask 255.255.255.0
                        network 192.168.1.0
                        broadcast 192.168.1.255

                        • update packages and install dnsmasq:
                          sudo apt-get update"
                          sudo apt-get install dnsmasq -y

                        • Copy and save the original dnsmasq.conf
                          sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig

                        • Configure the new dnsmasq.conf
                          sudo nano /etc/dnsmasq.conf and paste the following:

                        interface=eth0 # Use interface eth0
                        listen-address=192.168.1.1 # Explicitly specify the address to listen on
                        bind-interfaces # Bind the interface to make sure we aren't sending thingselsewhere
                        server=8.8.8.8 # Forward DNS requests to Google DNS
                        domain-needed # Don't forward short names
                        bogus-priv # Never forward addresses in the non-routed address spaces.
                        dhcp-range=192.168.1.50,192.168.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with a 12 hour lease time

                        • Enable IPv4 forwarding:
                          sudo nano /etc/sysctl.conf and uncomment the line net.ipv4.ip_forward=1

                        • Setup IP tables. I used wlan1 for the USB Wifi dongle and my Duet will be setup with a static IP of 192.168.1.50 which will be setup in config.g on the Duet 2.
                          sudo iptables -t nat -A POSTROUTING -o wlan1 -j MASQUERADE
                          sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.50:80

                        • Configure it to load on reboot by first saving it to a file:
                          sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

                        • Then create a 'hook' file with a line to restore the ip tables on boot and add the following line:
                          iptables-restore < /etc/iptables.ipv4.nat

                        After a reboot you should automatically connect to your wifi and, assuming it has internet access, anything plugged into your Pi's ethernet port will have internet access as well.

                        You may also want to change some settings using sudo raspi-config and change user pi default password, change the hostname and expand the file system.

                        1 Reply Last reply Reply Quote 0
                        • nikkerundefined
                          nikker
                          last edited by

                          @incogizmo I managed to break it lol... should have left it along but the IP addresses used in the first link bothered me I tried to set things up using the IP addresses above for the RPI /duet but it didnt work. I also tried to start back at step one from a new flash and repeate what I originally did but no luck. I think the issue is with the Duet 2. It is reporting an IP address but It must not be getting forwarded from the RPI3. Is there anything I should check as well in the config.g?

                          incogizmoundefined 1 Reply Last reply Reply Quote 0
                          • incogizmoundefined
                            incogizmo @nikker
                            last edited by incogizmo

                            @nikker Looking at the steps you did previously dnsmasq and the dhcp setup is not required if you hard set the ip address on your Duet, remember to set the netmask and gateway however:

                            From the config details you posted in your previous post

                            M552 S1 P192.168.1.50 #set Duet IP address
                            M553 P255.255.255.0 #set subnet mask
                            M554 P192.168.1.1 #set gateway
                            

                            Key is making sure the gateway on the Duet is set to the ip the Pi has on eth0.
                            What is the network address you use on your wireless network? Without getting too much into routing / subnetting, if your wireless network IP is 192.168.1.x you will have problems.

                            Removing DHCP/dnsmasq from your setup means you can remove the following steps:

                            update packages and install dnsmasq:
                            sudo apt-get update"
                            sudo apt-get install dnsmasq -y

                            Copy and save the original dnsmasq.conf
                            sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig

                            Configure the new dnsmasq.conf
                            sudo nano /etc/dnsmasq.conf and paste the following:

                            interface=eth0 # Use interface eth0
                            listen-address=192.168.1.1 # Explicitly specify the address to listen on
                            bind-interfaces # Bind the interface to make sure we aren't sending thingselsewhere
                            server=8.8.8.8 # Forward DNS requests to Google DNS
                            domain-needed # Don't forward short names
                            bogus-priv # Never forward addresses in the non-routed address spaces.
                            dhcp-range=192.168.1.50,192.168.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with a 12 hour lease time

                            1 Reply Last reply Reply Quote 0
                            • nikkerundefined
                              nikker
                              last edited by nikker

                              @incogizmo i started again with a fresh flash and still no luck, RPI3 address on my network is 192.168.50.16 and when i enter that in chrome nothing loads. I do have another duet 2 wifi running on my network right now as well but I didnt think the MAC addresses were the same. I setup my config.g as you had above (my home network is using 192.168.50.X so there shouldnt be any issues with the RPI3's 192.168.1.X) and performed the steps above with the exception of the dnsmasq and dhcp setup.

                              My /etc/network/interfaces looks like this (I am not using an external wifi adapter at the moment as I am trying to keep it simple so only have wlan0 for now:

                              auto lo
                              iface lo inet loopback

                              #iface eth0 inet manual
                              allow-hotplug eth0
                              iface eth0 inet static
                              address 192.168.1.1
                              netmask 255.255.255.0
                              network 192.168.1.0
                              broadcast 192.168.1.255

                              allow-hotplug wlan0
                              iface wlan0 inet manual
                              wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

                              allow-hotplug wlan1
                              iface wlan1 inet manual
                              wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

                              my /etc/iptables.ipv4.nat file contains this:

                              Generated by iptables-save v1.4.21 on Thu Dec 13 06:32:18 2018
                              *nat
                              :PREROUTING ACCEPT [2:772]
                              :INPUT ACCEPT [2:772]
                              :OUTPUT ACCEPT [3:228]
                              :POSTROUTING ACCEPT [0:0]
                              -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.1.50:80
                              -A POSTROUTING -o wlan0 -j MASQUERADE
                              COMMIT
                              Completed on Thu Dec 13 06:32:18 2018

                              I am not sure why wlan1 keeps coming up on a fresh flash even though I have never plugged one in. Is there something i need to configure in raspi-config? If i ping 192.168.1.50 on the RPI3 I see the green light on the Duet 2 ethernet port light up but other than when I ping only the orange light is solid.

                              1 Reply Last reply Reply Quote 0
                              • incogizmoundefined
                                incogizmo
                                last edited by

                                When you ping the Duet from the PI do you get a ping reply?

                                If this is working then there is a problem with the ip forwarding, in this case please send the output from the following commands

                                sudo iptables -L
                                sudo iptables -L -t nat
                                grep ip_forward /etc/sysctl.conf
                                ifconfig
                                

                                If the ping reply is not working then it is likely a network configuration issue on the ethernet side, either on the duet of the PI. If you dont get a ping reply can you send your duet config and the output from ifconfig on the pi?

                                1 Reply Last reply Reply Quote 0
                                • nikkerundefined
                                  nikker
                                  last edited by nikker

                                  Yeah when I ping the Duet 2 at 192.168.1.50 from the RPI3 this is what I get until I stop it with ctrl+c:

                                  pi@raspberrypi:~ $ ping 192.168.1.50
                                  PING 192.168.1.50 (192.168.1.50) 56(84) bytes of data.
                                  64 bytes from 192.168.1.50: icmp_seq=1 ttl=128 time=0.659 ms
                                  64 bytes from 192.168.1.50: icmp_seq=2 ttl=128 time=0.289 ms
                                  64 bytes from 192.168.1.50: icmp_seq=3 ttl=128 time=0.294 ms
                                  64 bytes from 192.168.1.50: icmp_seq=4 ttl=128 time=0.304 ms
                                  64 bytes from 192.168.1.50: icmp_seq=5 ttl=128 time=0.302 ms
                                  64 bytes from 192.168.1.50: icmp_seq=6 ttl=128 time=0.281 ms
                                  64 bytes from 192.168.1.50: icmp_seq=7 ttl=128 time=0.276 ms
                                  64 bytes from 192.168.1.50: icmp_seq=8 ttl=128 time=0.270 ms
                                  ^C
                                  --- 192.168.1.50 ping statistics ---
                                  8 packets transmitted, 8 received, 0% packet loss, time 7292ms
                                  rtt min/avg/max/mdev = 0.270/0.334/0.659/0.124 ms

                                  here is the output from the commands you asked for,

                                  pi@raspberrypi:~ $ sudo iptables -L
                                  Chain INPUT (policy ACCEPT)
                                  target prot opt source destination

                                  Chain FORWARD (policy ACCEPT)
                                  target prot opt source destination

                                  Chain OUTPUT (policy ACCEPT)
                                  target prot opt source destination

                                  pi@raspberrypi:~ $ sudo iptables -L -t nat
                                  Chain PREROUTING (policy ACCEPT)
                                  target prot opt source destination
                                  DNAT tcp -- anywhere anywhere tcp dpt:http to:192.168.1.50:80

                                  Chain INPUT (policy ACCEPT)
                                  target prot opt source destination

                                  Chain OUTPUT (policy ACCEPT)
                                  target prot opt source destination

                                  Chain POSTROUTING (policy ACCEPT)
                                  target prot opt source destination
                                  MASQUERADE all -- anywhere anywhere

                                  pi@raspberrypi:~ $ grep ip_forward /etc/sysctl.conf
                                  net.ipv4.ip_forward=1

                                  pi@raspberrypi:~ $ ifconfig
                                  eth0 Link encap:Ethernet HWaddr b8:27:eb:1e:44:b6
                                  inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
                                  inet6 addr: fe80::deb:7778:30df:3621/64 Scope:Link
                                  UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
                                  RX packets:9 errors:0 dropped:0 overruns:0 frame:0
                                  TX packets:49 errors:0 dropped:0 overruns:0 carrier:0
                                  collisions:0 txqueuelen:1000
                                  RX bytes:718 (718.0 B) TX bytes:8565 (8.3 KiB)

                                  lo Link encap:Local Loopback
                                  inet addr:127.0.0.1 Mask:255.0.0.0
                                  inet6 addr: ::1/128 Scope:Host
                                  UP LOOPBACK RUNNING MTU:65536 Metric:1
                                  RX packets:0 errors:0 dropped:0 overruns:0 frame:0
                                  TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
                                  collisions:0 txqueuelen:1
                                  RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

                                  wlan0 Link encap:Ethernet HWaddr b8:27:eb:4b:11:e3
                                  inet addr:192.168.50.16 Bcast:192.168.50.255 Mask:255.255.255.0
                                  inet6 addr: fe80::42d8:ee2d:87f2:a2b1/64 Scope:Link
                                  UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
                                  RX packets:467 errors:0 dropped:0 overruns:0 frame:0
                                  TX packets:284 errors:0 dropped:0 overruns:0 carrier:0
                                  collisions:0 txqueuelen:1000
                                  RX bytes:51217 (50.0 KiB) TX bytes:40944 (39.9 KiB)

                                  1 Reply Last reply Reply Quote 0
                                  • nikkerundefined
                                    nikker
                                    last edited by

                                    @incogizmo Im not sure why it worked the first time but I eventually got it to work using some information from this post https://serverfault.com/questions/140622/how-can-i-port-forward-with-iptables

                                    I added
                                    sudo iptables -t nat -A PREROUTING -p tcp -i wlan0 --dport 80 -j DNAT --to-destination 192.168.1.50:80
                                    sudo iptables -A FORWARD -p tcp -d 192.168.1.50 --dport 80 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

                                    and made sure it was saved in /etc/iptables.ipv4.nat and then gave it a reboot, a prayer and bingo. Now to bookmark the two sites and make a backup of the SD card!

                                    incogizmoundefined 1 Reply Last reply Reply Quote 0
                                    • incogizmoundefined
                                      incogizmo @nikker
                                      last edited by incogizmo

                                      @nikker Ahhhh sounds like the default rules were set to DENY, possibly during your first run through you set the default FORWARD rule to accept,
                                      You possibly ran something like iptables -P FORWARD ACCEPT or the ACCEPT rule you provided above.

                                      Anyway really good news hearing its all setup and running reliably. 🙂

                                      1 Reply Last reply Reply Quote 0
                                      • SupraGuyundefined
                                        SupraGuy
                                        last edited by

                                        This seems needlessly complicated, expensive, and troublesome.

                                        Why not just get a wireless bridge device, it's not much more than the cost of the micro-SD card for the Pi, let alone the cost of the Pi itself.

                                        https://www.amazon.com/NETGEAR-N300-Range-Extender-EX2700/dp/B00L0YLRUW/ref=sr_1_4?s=pc&ie=UTF8&qid=1544804805&sr=1-4&keywords=wireless+bridge

                                        Plug in the wireless bridge, plug the Duet Ethernet into it. Configure the wireless network once, and boom.

                                        Personally, I love the Raspberry Pi. It's a great little inexpensive PC for small automation tasks, but I feel that it's utterly wasted as just a bridge when there are dedicated devices which do the job frankly better for way less money.

                                        Lead screw driven printer, powered by Duet 2 Wifi
                                        MPCNC powered by Duet 2 Wifi
                                        CoreXY printer driven by Duet 3 6HC
                                        LowRider CNC powered by Duet 2 Wifi

                                        1 Reply Last reply Reply Quote 0
                                        • arnd13undefined
                                          arnd13
                                          last edited by arnd13

                                          Hi,

                                          the easiest way is to use a bridge. Something like this (small, enough bandwith):

                                          https://www.amazon.de/Vonets-300Mbps-Router-Wireless-Repeater/dp/B0148NO58W/ref=sr_1_3?ie=UTF8&qid=1544824135&sr=8-3&keywords=vonets+var11n-300

                                          Costs about 20 euros and can be powered over the 5 Volt pins of the duet.

                                          I'm using it with my maestro and it's perfect.

                                          1 Reply Last reply Reply Quote 0
                                          • incogizmoundefined
                                            incogizmo
                                            last edited by

                                            Whilst I totally agree simplicity is better, there are situations where it makes sense.
                                            When you are already using the Pi for other things eg motioneye for remote monitoring / recording or octoprint etc.
                                            I would prefer to minimize additional components.

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Unless otherwise noted, all forum content is licensed under CC-BY-SA