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

Check network connection and switch Wi-Fi to AP mode on Duet 3

Scheduled Pinned Locked Moved
Gcode meta commands
4
9
346
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.
  • undefined
    Nazar
    last edited by Nazar 20 May 2024, 23:35

    Hello,

    I am hoping to get some assistance with creating a macro for my Duet 3 mainboard. The macro should do the following:

    1. Check if there is an active network connection (either Ethernet or Wi-Fi)
    2. If no network connection is established, enable the Access Point (AP) mode on the Duet 3's Wi-Fi module

    This Macro is called from config.g through runonce.g:

    echo >"0:/sys/runonce.g" "M98 P""0:/sys/networktest.g"""
    

    However, when attempting to run this macro, I am encountering an error message that says "SPI timeout".

    I would greatly appreciate any help or guidance on how to properly write this macro and resolve the SPI timeout error at line 17 (M589).

    Thank you

    while network.interfaces[0].actualIP = "0.0.0.0" && network.interfaces[1].actualIP = "0.0.0.0" && iterations < 30
      G4 S1
    
    
    
    if network.interfaces[0].actualIP != "0.0.0.0" || network.interfaces[1].actualIP != "0.0.0.0"
      M99
      abort
    
    
    M552 I0 S0
    G4 S1
    M552 I1 S-1
    G4 S2
    M552 I1 S0
    G4 S1
    M589 S"Printer" P"1234567890" I192.168.0.1
    G4 S1
    M552 I1 S2
    
    
    
    M291 S2 R"Connection was not established" P"WiFi module was automatically switched to Access Point Mode"
    
    undefined 1 Reply Last reply 21 May 2024, 10:44 Reply Quote 0
    • undefined
      T3P3Tony administrators @Nazar
      last edited by 21 May 2024, 10:44

      @Nazar do you get SPI timeout when running the macro normally, not via runonce?

      What happens if you run each step of the macro by itself, at which point do you get SPI timeout?

      www.duet3d.com

      undefined 1 Reply Last reply 22 May 2024, 03:47 Reply Quote 0
      • undefined
        Nazar @T3P3Tony
        last edited by Nazar 22 May 2024, 03:47

        @T3P3Tony

        Dear Tony,

        Thank you for your reply, I have added echo commands to the script and ran it as a separate macro from DWC, the machine was not able to send the M589 command, the WiFi module did not switch to AP mode as was commanded and I have manually restarted it.

        During the test machine was connected through WiFi and I was testing network.interfaces[0] (Ethernet)

        Please let me know if there is any other test I should perform.

        Thank you for your help!

        The Macro:

        echo >"0:/macros/report.txt" "Start"
        
        var it = 0
        
        ;while network.interfaces[0].actualIP = "0.0.0.0" && network.interfaces[1].actualIP = "0.0.0.0" && iterations < 30
        while network.interfaces[0].actualIP = "0.0.0.0" && iterations <= 30
          set var.it = var.it + 1
          echo >>"0:/macros/report.txt" "1st Loop Iteration: "^var.it
          G4 S.1
        
        echo >>"0:/macros/report.txt" "1st Loop Out"
        
        
        
        ;if network.interfaces[0].actualIP != "0.0.0.0" || network.interfaces[1].actualIP != "0.0.0.0"
        if network.interfaces[0].actualIP != "0.0.0.0"
          echo >>"0:/macros/report.txt" "IF - Network Connected"
          M99
          abort
        else
          echo >>"0:/macros/report.txt" "Else - Network not Connected"
        
        echo >>"0:/macros/report.txt" " "
        echo >>"0:/macros/report.txt" "After IF"
        echo >>"0:/macros/report.txt" " "
        
        
        M98 P"0:/sys/led/statusoff.g"
        M98 P"0:/sys/led/dimmwhite.g"
        M98 P"0:/sys/led/red.g"
        
        
        
        M552 I1 S-1
        echo >>"0:/macros/report.txt" "Line 35 "^result
        M552 I1 S0
        echo >>"0:/macros/report.txt" "Line 37 "^result
        M552 I1 S2
        echo >>"0:/macros/report.txt" "Line 39 "^result
        
        
        
        M552 I0 S0
        echo >>"0:/macros/report.txt" "Line 44 "^result
        G4 S1
        
        M552 I1 S-1
        echo >>"0:/macros/report.txt" "Line 48 "^result
        G4 S2
        
        M552 I1 S0
        echo >>"0:/macros/report.txt" "Line 52 "^result
        G4 S1
        
        M589 S"Printer" P"1234567890" I192.168.0.1
        echo >>"0:/macros/report.txt" "Line 56 "^result
        G4 S1
        
        M552 I1 S2
        echo >>"0:/macros/report.txt" "Line 60 "^result
        
        
        
        M291 S2 R"Connection was not established" P"WiFi module was automatically switched to Access Point Mode"
        

        report.txt:

        Start
        1st Loop Iteration: 1
        1st Loop Iteration: 2
        1st Loop Iteration: 3
        1st Loop Iteration: 4
        1st Loop Iteration: 5
        1st Loop Iteration: 6
        1st Loop Iteration: 7
        1st Loop Iteration: 8
        1st Loop Iteration: 9
        1st Loop Iteration: 10
        1st Loop Iteration: 11
        1st Loop Iteration: 12
        1st Loop Iteration: 13
        1st Loop Iteration: 14
        1st Loop Iteration: 15
        1st Loop Iteration: 16
        1st Loop Iteration: 17
        1st Loop Iteration: 18
        1st Loop Iteration: 19
        1st Loop Iteration: 20
        1st Loop Iteration: 21
        1st Loop Iteration: 22
        1st Loop Iteration: 23
        1st Loop Iteration: 24
        1st Loop Iteration: 25
        1st Loop Iteration: 26
        1st Loop Iteration: 27
        1st Loop Iteration: 28
        1st Loop Iteration: 29
        1st Loop Iteration: 30
        1st Loop Iteration: 31
        1st Loop Out
        Else - Network not Connected
         
        After IF
         
        Line 35 0
        Line 37 0
        Line 39 0
        Line 44 0
        Line 48 0
        Line 52 0
        Line 56 2
        Line 60 0
        
        undefined 1 Reply Last reply 22 May 2024, 15:55 Reply Quote 0
        • undefined
          droftarts administrators @Nazar
          last edited by 22 May 2024, 15:55

          @Nazar I think it's the second part of the macro that you're having problems with? These are the commands, in order, that your macro is doing. I've removed the echo commands, and added comments:

          M552 I1 S-1 ; turn off WiFi (no pause after)
          M552 I1 S0 ; turn on WiFi to idle (no pause after)
          M552 I1 S2 ; turn on WiFi to AP 
           
          M552 I0 S0 ; disable Ethernet
          G4 S1 ; pause
           
          M552 I1 S-1 ; turn off WiFi
          G4 S2 ; pause
           
          M552 I1 S0
          G4 S1 ; pause
           
          M589 S"Printer" P"1234567890" I192.168.0.1 ; configure AP
          G4 S1 ; pause
           
          M552 I1 S2 ; turn on WiFi in AP mode
          

          I think you're doing these in the wrong order, which is why the M589 command fails ("Line 56" result is "2", which is an error). Try this sequence (I don't have a 6HC with WiFi adapter to test, unfortunately):

          M552 I0 S0 ; disable Ethernet (no pause after needed)
          M552 I1 S-1 ; turn off WiFi
          G4 S2 ; pause
          
          M552 I1 S0 ; turn on WiFi to idle
          G4 S2 ; pause
           
          M589 S"Printer" P"1234567890" I192.168.0.1 ; configure AP
          G4 S2 ; pause
           
          M552 I1 S2 ; turn on WiFi in AP mode
          

          I tend to leave a 2 second pause between changing WiFi module status, to be on the safe side.

          Also, in the first part of your macro, you are only waiting 0.1 seconds between each loop, so 30 iterations is only 3 seconds to get an IP address. You may want to give it a bit longer.

          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

          undefined 1 Reply Last reply 22 May 2024, 17:46 Reply Quote 0
          • undefined
            Nazar @droftarts
            last edited by 22 May 2024, 17:46

            Dear @droftarts,

            Thank you for your reply and advice regarding the M552 commands order, I have changed the script accordingly and rerun the test. Unfortunately, it didn't work, so I have added echo to see where it failed. It failed at the same place as before at the M589 command line.

            Thank you for your advice regarding the wait time to obtain the IP address, I set it to 0.1 sec on purpose to speed up the process of testing.

            echo >"0:/macros/report.txt" "Start"
             
            var it = 0
            while network.interfaces[0].actualIP = "0.0.0.0" && iterations <= 30
              set var.it = var.it + 1
              echo >>"0:/macros/report.txt" "1st Loop Iteration: "^var.it
              G4 S.1
             
            echo >>"0:/macros/report.txt" "1st Loop Out"
             
            
            if network.interfaces[0].actualIP != "0.0.0.0"
              echo >>"0:/macros/report.txt" "IF - Network Connected"
              M99
              abort
            else
              echo >>"0:/macros/report.txt" "Else - Network not Connected"
             
            
            
            M98 P"0:/sys/led/statusoff.g"
            M98 P"0:/sys/led/dimmwhite.g"
            M98 P"0:/sys/led/red.g"
            
            
            echo >>"0:/macros/report.txt" " "
            echo >>"0:/macros/report.txt" "After LED"
            echo >>"0:/macros/report.txt" " "
             
            
            M552 I0 S0 ; disable Ethernet (no pause after needed)
            echo >>"0:/macros/report.txt" "Result: "^result
            M552 I1 S-1 ; turn off WiFi
            echo >>"0:/macros/report.txt" "Result: "^result
            G4 S2 ; pause
             
            M552 I1 S0 ; turn on WiFi to idle
            echo >>"0:/macros/report.txt" "Result: "^result
            G4 S2 ; pause
             
            M589 S"Printer" P"1234567890" I192.168.0.1 ; configure AP
            echo >>"0:/macros/report.txt" "Result: "^result
            G4 S2 ; pause
             
            M552 I1 S2 ; turn on WiFi in AP mode
            echo >>"0:/macros/report.txt" "Result: "^result
            
            
            M291 S2 R"Connection was not established" P"WiFi module was automatically switched to Access Point Mode"
            
            Start
            1st Loop Iteration: 1
            1st Loop Iteration: 2
            1st Loop Iteration: 3
            1st Loop Iteration: 4
            1st Loop Iteration: 5
            1st Loop Iteration: 6
            1st Loop Iteration: 7
            1st Loop Iteration: 8
            1st Loop Iteration: 9
            1st Loop Iteration: 10
            1st Loop Iteration: 11
            1st Loop Iteration: 12
            1st Loop Iteration: 13
            1st Loop Iteration: 14
            1st Loop Iteration: 15
            1st Loop Iteration: 16
            1st Loop Iteration: 17
            1st Loop Iteration: 18
            1st Loop Iteration: 19
            1st Loop Iteration: 20
            1st Loop Iteration: 21
            1st Loop Iteration: 22
            1st Loop Iteration: 23
            1st Loop Iteration: 24
            1st Loop Iteration: 25
            1st Loop Iteration: 26
            1st Loop Iteration: 27
            1st Loop Iteration: 28
            1st Loop Iteration: 29
            1st Loop Iteration: 30
            1st Loop Iteration: 31
            1st Loop Out
            Else - Network not Connected
             
            After LED
             
            Result: 0
            Result: 0
            Result: 0
            Result: 2
            Result: 0
            
            undefined 1 Reply Last reply 22 May 2024, 18:02 Reply Quote 0
            • undefined
              droftarts administrators @Nazar
              last edited by 22 May 2024, 18:02

              @Nazar Please step through the commands I posted, sending them one by one in the console. Please post any error messages that are reported.

              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

              undefined 1 Reply Last reply 15 Jul 2024, 03:55 Reply Quote 0
              • undefined
                Nazar @droftarts
                last edited by Nazar 15 Jul 2024, 03:55

                @droftarts Thank you for your reply and trying to help!

                Here is a console screenshot from Pronterface:

                All responses from turning machine ON. Unfortunately we can see that macro doesn't work.

                Disconnected.
                Connecting...
                Printer is now online.
                HTTP is enabled on port 80
                FTP is disabled
                TELNET is disabled
                Done!
                WiFi is disabled.
                Executing runonce.g...
                Network stopped
                Error: Failed to configure access point parameters: SPI timeout
                Error: Failed to configure access point parameters: SPI timeout
                
                Turn off the current WiFi mode before selecting a new one
                Done!
                Error: Cannot delete file 0:/sys/runonce.g because it is open
                Error: Cannot delete file 0:/sys/runonce.g because it is open
                
                RepRapFirmware for Duet 3 MB6HC is up and running.
                >>> m552i0
                SENDING:M552I0
                Ethernet is disabled, configured IP address: 0.0.0.0, actual IP address: 0.0.0.0
                >>> m552i1
                SENDING:M552I1
                WiFi module is being started
                >>> m552i1
                SENDING:M552I1
                WiFi module is being started
                

                Sending the same commands manually through Pronterface:

                SENDING:M552I0
                Ethernet is disabled, configured IP address: 0.0.0.0, actual IP address: 0.0.0.0
                >>> m552i1
                SENDING:M552I1
                WiFi module is being started
                >>> m552i1
                SENDING:M552I1
                WiFi module is being started
                >>> M552 I0 S0
                SENDING:M552 I0 S0
                >>> M552 I1 S-1
                SENDING:M552 I1 S-1
                WiFi module stopped
                >>> M552 I1 S0
                SENDING:M552 I1 S0
                WiFi module started
                >>> M589 S"Printer" P"1234567890" I192.168.0.1
                SENDING:M589 S"Printer" P"1234567890" I192.168.0.1
                >>> M552 I1 S2
                SENDING:M552 I1 S2
                WiFi module is providing access point Printer, IP address 192.168.0.1
                

                Sending commands manually works.

                Macro that is used to test the network:

                ;echo >"0:/macros/report.txt" "Start"
                 
                var it = 0
                ;while network.interfaces[0].actualIP = "0.0.0.0" && iterations <= 30
                while network.interfaces[0].actualIP = "0.0.0.0" && network.interfaces[1].actualIP = "0.0.0.0" && iterations < 30
                  set var.it = var.it + 1
                  ;echo >>"0:/macros/report.txt" "1st Loop Iteration: "^var.it
                  G4 S1
                 
                ;echo >>"0:/macros/report.txt" "1st Loop Out"
                 
                 
                ;if network.interfaces[0].actualIP != "0.0.0.0"
                if network.interfaces[0].actualIP != "0.0.0.0" || network.interfaces[1].actualIP != "0.0.0.0"
                  ;echo >>"0:/macros/report.txt" "IF - Network Connected"
                  M99
                  abort
                else
                  ;echo >>"0:/macros/report.txt" "Else - Network not Connected"
                 
                 
                 
                M98 P"0:/sys/led/statusoff.g"
                M98 P"0:/sys/led/dimmwhite.g"
                M98 P"0:/sys/led/red.g"
                 
                 
                ;echo >>"0:/macros/report.txt" " "
                ;echo >>"0:/macros/report.txt" "After LED"
                ;echo >>"0:/macros/report.txt" " "
                 
                 
                M552 I0 S0 ; disable Ethernet (no pause after needed)
                ;echo >>"0:/macros/report.txt" "Result: "^result
                M552 I1 S-1 ; turn off WiFi
                ;echo >>"0:/macros/report.txt" "Result: "^result
                G4 S2 ; pause
                 
                M552 I1 S0 ; turn on WiFi to idle
                ;echo >>"0:/macros/report.txt" "Result: "^result
                G4 S2 ; pause
                 
                M589 S"Printer" P"1234567890" I192.168.0.1 ; configure AP
                ;echo >>"0:/macros/report.txt" "Result: "^result
                G4 S2 ; pause
                 
                M552 I1 S2 ; turn on WiFi in AP mode
                ;echo >>"0:/macros/report.txt" "Result: "^result
                 
                 
                M291 S2 R"Connection was not established" P"WiFi module was automatically switched to Access Point Mode"
                

                Thank you for all the help! I hope to resolve this ASAP.

                dc42undefined 1 Reply Last reply 15 Jul 2024, 06:03 Reply Quote 0
                • dc42undefined
                  dc42 administrators @Nazar
                  last edited by 15 Jul 2024, 06:03

                  @Nazar does the macro work if you invoke it manually instead of from runonce.g ?

                  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

                  undefined 1 Reply Last reply 16 Jul 2024, 03:01 Reply Quote 0
                  • undefined
                    Nazar @dc42
                    last edited by 16 Jul 2024, 03:01

                    @dc42, thank you for your prompt reply, I highly apreciate it!

                    Macro runs automatically after machine’s restart

                    Printer is now online.
                    Done!
                    WiFi is disabled.
                    Executing runonce.g...
                    Network stopped
                    Error: Failed to configure access point parameters: SPI timeout
                    Error: Failed to configure access point parameters: SPI timeout
                    
                    Turn off the current WiFi mode before selecting a new one
                    Done!
                    Error: Cannot delete file 0:/sys/runonce.g because it is open
                    Error: Cannot delete file 0:/sys/runonce.g because it is open
                    
                    RepRapFirmware for Duet 3 MB6HC is up and running.
                    

                    Calling Macro through Pronterface

                    >>> M98 P"0:/sys/networktest.g"
                    SENDING:M98 P"0:/SYS/NETWORKTEST.G"
                    WiFi module stopped
                    Error: Failed to configure access point parameters: SPI timeout
                    Error: Failed to configure access point parameters: SPI timeout
                    
                    Turn off the current WiFi mode before selecting a new one
                    - Connection was not established -
                    WiFi module was automatically switched to Access Point Mode
                    Send M292 to continue
                    

                    Calling Macro through Pronterface but before turning off WiFi and Ethernet

                    >>> m552i0s0
                    SENDING:M552I0S0
                    >>> m552i1s-1
                    SENDING:M552I1S-1
                    WiFi module stopped
                    >>> M98 P"0:/sys/networktest.g"
                    SENDING:M98 P"0:/SYS/NETWORKTEST.G"
                    Error: Failed to configure access point parameters: SPI timeout
                    Error: Failed to configure access point parameters: SPI timeout
                    
                    Turn off the current WiFi mode before selecting a new one
                    - Connection was not established -
                    WiFi module was automatically switched to Access Point Mode
                    Send M292 to continue
                    Disconnected.
                    

                    Unfortunately neither worked.

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