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