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

    Macro for setting up your network

    Scheduled Pinned Locked Moved
    Gcode meta commands
    9
    19
    1.3k
    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.
    • Macgyverundefined
      Macgyver
      last edited by Phaedrux

      Good Day all

      Here is a little side project I was working on, Thanks to @dc42 for letting me know about the S7 switch I completely missed in the documentation.

      It does force the users to be aware that DUET will connect to the 2.4Ghz network reliability, It prompts only for required information as needed. I have done a little testing on it here in my environment and it works well for me. Hopefully others can find it useful.

      Not sure why its not showing properly in the preview however everything between Start and end macro is required.

      ---- Start Macro
      
      ;WIFI_CONFIG macro v1.1
      ;
      ; Author: Dr Jay (3D Emergency Room)
      ; Created: December 16, 2023
      ; Last Updated: December 16, 2023
      ;
      ; This macro helps configure WiFi settings on Duet boards
      ; Supports both Client and Access Point modes
      ;
      ; IMPORTANT WIFI REQUIREMENTS:
      ; - ONLY 2.4GHz networks are supported
      ; - 5GHz networks will NOT work
      ; - Dual-band networks must be split into separate 2.4GHz and 5GHz networks
      ;
      ; How to identify a 2.4GHz network:
      ; 1. Check your router settings - look for separate network names for 2.4GHz and 5GHz
      ; 2. Network names often end with "-2.4G" or "-2G" to distinguish them
      ; 3. 2.4GHz networks typically show lower but more stable signal strength
      ; 4. If using a dual-band router, ensure you've separated the bands with different SSIDs
      
      ; Initialize variables
      var ssid = ""
      var password = ""
      var ip = ""
      var gateway = ""
      var subnet = ""
      var mode = 0
      var dhcp_mode = true                                  ; Track if using DHCP
      
      ; Choose wireless mode
      M291 P"Choose WiFi mode" R"Mode Selection" S4 K{"Client","Access Point"}
      set global.result = input
      set var.mode = global.result
      
      if var.mode == 0
          ; CLIENT MODE
          M291 P"WiFi Client Setup" R"Welcome" S3
          
          ; WARNING about 2.4GHz requirement
          M291 P"WARNING: Your network MUST be 2.4GHz. 5GHz and dual-band networks will NOT work!" R"Network Requirement" S3
          M291 P"Common 2.4GHz names end with: -2.4G, -2G, _2.4GHz" R"Network Identification" S3
          M291 P"For dual-band routers: Split bands into separate networks" R"Router Setup" S3
          M291 P"Recommended: Use WPA2-PSK security and channels 1, 6, or 11" R"Network Settings" S3
          M291 P"Make sure you are connecting to a 2.4GHz network. Continue?" R"Confirm" S4 K{"Yes","No"}
          set global.result = input
          if global.result == 1
              M291 P"Setup cancelled" R"Cancelled" S3
              M99
          
          ; Prompt for SSID
          M291 P"Enter WiFi network name (SSID)" R"Network Name" S7
          set global.result = input
          if global.result == ""
              M291 P"Setup cancelled" R"Cancelled" S3
              M99
          set var.ssid = global.result
          
          ; Prompt for password
          M291 P"Enter WiFi password" R"Network Password" S7
          set global.result = input
          if global.result == ""
              M291 P"Setup cancelled" R"Cancelled" S3
              M99
          set var.password = global.result
          
          ; Ask about custom IP
          M291 P"Use custom IP configuration?" R"IP Config" S4 K{"No (DHCP)","Yes"}
          set global.result = input
          if global.result == 1
              set var.dhcp_mode = false
              ; Get IP address
              M291 P"Enter IP address (e.g. 192.168.1.100)" R"IP Address" S7
              set global.result = input
              if global.result == ""
                  M291 P"Using DHCP" R"Info" S3
                  set var.dhcp_mode = true
              else
                  set var.ip = global.result
                  
                  ; Get gateway
                  M291 P"Enter gateway address (e.g. 192.168.1.1)" R"Gateway" S7
                  set global.result = input
                  set var.gateway = global.result
                  
                  ; Get subnet mask
                  M291 P"Enter subnet mask (e.g. 255.255.255.0)" R"Subnet" S7
                  set global.result = input
                  set var.subnet = global.result
          
          ; Configure WiFi
          M291 P"Configuring WiFi..." R"Please Wait" S3
          M552 S0                                           ; Disable network
          G4 P1000                                          ; Wait 1 second
          
          M587 S{var.ssid} P{var.password}                 ; Configure WiFi
          
          ; Set custom IP if provided
          if !var.dhcp_mode
              M552 P{var.ip}                               ; Set IP address
              M553 P{var.subnet}                           ; Set subnet mask
              M554 P{var.gateway}                          ; Set gateway
          
          G4 P2000                                          ; Wait 2 seconds
          M552 S1                                           ; Enable network
      else
          ; ACCESS POINT MODE
          M291 P"WiFi Access Point Setup" R"Welcome" S3
          
          ; Prompt for AP name
          M291 P"Enter Access Point name" R"AP Name" S7
          set global.result = input
          if global.result == ""
              M291 P"Setup cancelled" R"Cancelled" S3
              M99
          set var.ssid = global.result
          
          ; Prompt for AP password (minimum 8 characters)
          M291 P"Enter AP password (min 8 chars)" R"AP Password" S7
          set global.result = input
          if global.result == "" || strlen(global.result) < 8
              M291 P"Invalid password - minimum 8 characters" R"Error" S3
              M99
          set var.password = global.result
          
          ; Configure Access Point
          M291 P"Creating Access Point..." R"Please Wait" S3
          M552 S0                                           ; Disable network
          G4 P1000                                          ; Wait 1 second
          
          M589 S{var.ssid} P{var.password}                 ; Configure Access Point
          
          G4 P2000                                          ; Wait 2 seconds
          M552 S1                                           ; Enable network
      
      ; Report network status
      M552                                                  ; Report current network status
      
      ; Final message
      if var.mode == 0
          M291 P"WiFi client setup complete. Check connection status above." R"Complete" S3
      else
          M291 P"Access Point created. SSID: " ^ {var.ssid} R"Complete" S3
      
      ; Clear sensitive data
      set var.ssid = ""
      set var.password = ""
      set var.ip = ""
      set var.gateway = ""
      set var.subnet = ""
      
      ; Recommend power cycle
      M291 P"Please power cycle your printer to ensure network settings are properly applied" R"Power Cycle" S3
      
      
      --- End macro
      
      1 Reply Last reply Reply Quote 3
      • Phaedruxundefined
        Phaedrux Moderator
        last edited by

        Thanks for the macro. I edited your post to put it in a code block so that it displays correctly.

        Z-Bot CoreXY Build | Thingiverse Profile

        Macgyverundefined 1 Reply Last reply Reply Quote 0
        • Macgyverundefined
          Macgyver @Phaedrux
          last edited by

          @Phaedrux thank you for the assist,

          I am working on a couple of things so you may see more coming in the future if they have a cool factor I am aiming for

          stuartofmtundefined OwenDundefined 2 Replies Last reply Reply Quote 1
          • Phaedruxundefined Phaedrux pinned this topic
          • stuartofmtundefined
            stuartofmt @Macgyver
            last edited by stuartofmt

            @Macgyver

            I'm curious about the assertion that dual band networks will not work. Is this precautionary? The reason I ask is that, from memory (I'm now using SBC), I've routinely used Duet2 on dual band SSID. In theory (and in practice with many other devices) the WIFI will connect using whatever frequency is available to the client (typically with 5GHz preferred if the client supports both). In the case of a Duet2 this would be 2.4GHz.
            Of course, my memory could be very fallible πŸ™‚

            Phaedruxundefined oliofundefined 2 Replies Last reply Reply Quote 0
            • Phaedruxundefined
              Phaedrux Moderator @stuartofmt
              last edited by

              @stuartofmt I think what seems to happen sometimes with dual band networks is that the router erroneously steers the Duet to the 5ghz network even though the Duet can't use it. I'm not sure if that's ever been definitively confirmed though.

              Z-Bot CoreXY Build | Thingiverse Profile

              stuartofmtundefined 1 Reply Last reply Reply Quote 0
              • stuartofmtundefined
                stuartofmt @Phaedrux
                last edited by

                @Phaedrux said in Macro for setting up your network:

                @stuartofmt I think what seems to happen sometimes with dual band networks is that the router erroneously steers the Duet to the 5ghz network even though the Duet can't use it. I'm not sure if that's ever been definitively confirmed though.

                I suspect that some different network issue(s) may have been explained away as such. Unless the client was sitting "right on top of the router antenna" - it should not be possible for a 2.4GHz client to even "see" a 5Ghz signal. Still ... stranger things have happened.

                I'm just a bit leery of pointing people towards what might be an unnecessary complication (i.e. splitting SSIDs into separate frequency bands).

                1 Reply Last reply Reply Quote 1
                • OwenDundefined
                  OwenD @Macgyver
                  last edited by

                  @Macgyver
                  It's a pity M587.2 doesn't have an option to return an array with just SSID names.
                  Then you could cut out incorrect entries.

                  Unfortunately it only gives a text output full of unnecessary information (for a macro) or a json return

                  1 Reply Last reply Reply Quote 0
                  • oliofundefined
                    oliof @stuartofmt
                    last edited by

                    @stuartofmt it's been a problem 2008-2012ish in some networks I've been on, but I can say its never been a problem for a Duet2Wifi, Duet3mini, or any of the ESP8266/ESP32 modules for the STM port.

                    <>RatRig V-Minion Fly Super5Pro RRF<> V-Core 3.1 IDEX k*****r <> RatRig V-Minion SKR 2 Marlin<>

                    1 Reply Last reply Reply Quote 0
                    • mrehorstdmdundefined
                      mrehorstdmd
                      last edited by

                      Is there any possibility that the browser being used to access the web server has some effect on reliability of the connection?

                      I have had a lot of trouble keeping a Duet2 WiFi board connected to my mixed 2.4/5GHz network for the last few years. About a year ago I switched to a mesh network with no change in the connection behavior. The mesh router has a dedicated 2.4 GHz IOT network that I use for the Duet and things like light bulbs, appliances, etc. The Chrome browser in my laptop would connect and I could access the control panel for between 30 seconds and maybe 2 minutes at a time, then the connection would fail. It got a bit better when I shut off the VPN (even though I had local network sharing enabled) on the laptop, but still not what anyone would call reliable. I gave up on ever getting it to work reliably.

                      I recently tried the Mullvad browser that is based on Firefox (I think) and Duet board miraculously stays connected for up to an hour, maybe more, at a time, so it seems the browser used plays a part in the reliability of the connection.

                      Or am I completely wrong?

                      https://drmrehorst.blogspot.com/

                      jay_s_ukundefined dc42undefined 2 Replies Last reply Reply Quote 0
                      • jay_s_ukundefined
                        jay_s_uk @mrehorstdmd
                        last edited by

                        @mrehorstdmd I think this is to do we the number of AJAX tries etc

                        Owns various duet boards and is the main wiki maintainer for the Teamgloomy LPC/STM32 port of RRF. Assume I'm running whatever the latest beta/stable build is

                        1 Reply Last reply Reply Quote 0
                        • dc42undefined
                          dc42 administrators @mrehorstdmd
                          last edited by

                          @mrehorstdmd if you have a PanelDue In your machine, is the network connection more reliable if you leave it on the Setup page?

                          Duet WiFi hardware designer and firmware engineer
                          Please do not ask me for Duet support via PM or email, use the forum
                          http://www.escher3d.com, https://miscsolutions.wordpress.com

                          mrehorstdmdundefined 1 Reply Last reply Reply Quote 0
                          • mrehorstdmdundefined
                            mrehorstdmd @dc42
                            last edited by

                            @dc42 There's no Panel Due. This particular controller is in the sand table.

                            I have gone through all the posts on wifi problems and played with ajax retries, it didn't seem to do much good. I also shut off the VPN when I am connecting to the table. The Mullvad browser just seems to work about 10x more reliably than Chrome.

                            https://drmrehorst.blogspot.com/

                            dc42undefined 1 Reply Last reply Reply Quote 0
                            • Phaedruxundefined
                              Phaedrux Moderator
                              last edited by

                              @mrehorstdmd

                              When you're unable to connect, are you still able to ping the Duet IP?

                              Does the chrome dev console show any errors?

                              Z-Bot CoreXY Build | Thingiverse Profile

                              mrehorstdmdundefined 1 Reply Last reply Reply Quote 0
                              • mrehorstdmdundefined
                                mrehorstdmd @Phaedrux
                                last edited by

                                @Phaedrux I don't have access to the table right now- it's over at my brother's distillery tasting room and I don't know when it will be back.

                                https://drmrehorst.blogspot.com/

                                droftartsundefined 1 Reply Last reply Reply Quote 0
                                • droftartsundefined
                                  droftarts administrators @mrehorstdmd
                                  last edited by

                                  @mrehorstdmd another thread talks about connection weirdness when using VPN, maybe it’s related to that?
                                  https://forum.duet3d.com/topic/37190/duet-2-wifi-don-t-connect-to-android

                                  Ian

                                  Bed-slinger - Mini5+ WiFi/1LC | RRP Fisher v1 - D2 WiFi | Polargraph - D2 WiFi | TronXY X5S - 6HC/Roto | CNC router - 6HC | Tractus3D T1250 - D2 Eth

                                  stuartofmtundefined 1 Reply Last reply Reply Quote 0
                                  • stuartofmtundefined
                                    stuartofmt @droftarts
                                    last edited by

                                    @mrehorstdmd
                                    Are you are taking about using a VPN to connect to your home wifi? or are you using an outbound VPN connection from home to the internet?
                                    Assuming the former - just some colour commentary regarding VPN from a phone into the home network...

                                    You need to be careful when testing from the same location as the home wifi. For some (maybe most ?) VPN - the phone needs to be connected ONLY to mobile data i.e. not connected with the home wifi.

                                    In my own case: I can connect with VPN (using my iphone) from a remote location to my home wifi and access DWC without issue.
                                    If I return home (and the phone connects to my home wifi) - I cannot connect using VPN (not that I'd need to). I use Chrome without issues.

                                    Having said that, it looks you might be using Mullvad VPN to provide outbound VPN.

                                    Since it looks like you have tested both Chrome and Mullvad Browser - I'd be especially careful to make sure (when checking Chrome) that the Mullvad VPN services are totally disabled. There have been reports of poor interaction between Chrome and Mullvad VPN (e.g. inability to access certain sites). I think they are unlikely to be a factor - but you never know ... πŸ™‚

                                    mrehorstdmdundefined 1 Reply Last reply Reply Quote 0
                                    • mrehorstdmdundefined
                                      mrehorstdmd @stuartofmt
                                      last edited by mrehorstdmd

                                      @stuartofmt I don't try to control the sand table table from my phone, only laptop. The laptop has Mullvad VPN but I shut that off when accessing the table. I have found that using the Mullvad browser keeps the connection to the table working for better than an hour at a time, where Chrome drops the connection every few (5-10 , usually closer to 5) minutes. In the past I had the VPN running with local network sharing enabled. The connection would drop every 30 sec to 1 minute that way. When I disabled the VPN the connection would stay up for 5-10 minutes. I am using my home wifi network, not a direct connection to the Duet board. There's no VPN running on the router, just on specific computers on the network.

                                      In the last couple years I have scoured all the posts about Duet2 wifi connection issues and have tried everything short of replacing the board to no avail -until I tried the Mullvad browser. AFAIK, the Mullvad browser is based on firefox with a bunch of security/anonymity stuff taken from Tor. Maybe there's something in there that makes a difference.

                                      https://drmrehorst.blogspot.com/

                                      1 Reply Last reply Reply Quote 0
                                      • dc42undefined
                                        dc42 administrators @mrehorstdmd
                                        last edited by

                                        @mrehorstdmd this might be a function of how many concurrent HTTP connections the browser tries to open to the web server on the Duet. Are you using the latest version 2.1 wifi firmware on the Duet?

                                        Duet WiFi hardware designer and firmware engineer
                                        Please do not ask me for Duet support via PM or email, use the forum
                                        http://www.escher3d.com, https://miscsolutions.wordpress.com

                                        mrehorstdmdundefined 1 Reply Last reply Reply Quote 0
                                        • mrehorstdmdundefined
                                          mrehorstdmd @dc42
                                          last edited by

                                          @dc42 I think so. I don't have the table here, but I'll probably be going to visit it later today. I'll check then. IRIC, the last time I updated firmware was about a year ago.

                                          https://drmrehorst.blogspot.com/

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