Macro for setting up your network
-
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
-
Thanks for the macro. I edited your post to put it in a code block so that it displays correctly.
-
@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
-
-
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 -
@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.
-
@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).
-
@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
-
@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.
-
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?
-
@mrehorstdmd I think this is to do we the number of AJAX tries etc