Check network connection and switch Wi-Fi to AP mode on Duet 3
-
Hello,
I am hoping to get some assistance with creating a macro for my Duet 3 mainboard. The macro should do the following:
- Check if there is an active network connection (either Ethernet or Wi-Fi)
- 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"
-
@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?
-
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
-
@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
-
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
-
@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
-
@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.
-
@Nazar does the macro work if you invoke it manually instead of from runonce.g ?
-
@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.