Setup RPi WiFi through ExecOnMCode
-
We need a way for our customers to initially setup WiFi on our printers. There are more elegant ways to accomplish this, and it does not cover all use cases, but here is what we came up with using a custom MCode, M2222, which can be input through the PanelDue.
Here is the service code:
[Unit] Description=Duet API listener for Wifi Setup After=duetcontrolserver.service Requires=duetcontrolserver.service [Service] ExecStart=/usr/local/bin/execonmcode -mCode 2222 -command "./scripts/wifi.sh %%S %%P" Restart=always RestartSec=10 [Install] WantedBy=multi-user.target
And here is the bash script which it calls:
#!/bin/bash #oozeBot Wifi Setup Script - v1.0 SSID=$1 PWRD=$2 FILE="/boot/wpa_supplicant.conf" echo "country=US" > $FILE echo "update_config=1" >> $FILE echo "ctrl_interface=/var/run/wpa_supplicant" >> $FILE echo "network={" >> $FILE echo " ssid=\"$SSID\"" >> $FILE echo " psk=\"$PWRD\"" >> $FILE echo "}" >> $FILE
Usage:
M2222 S"SSID" P"Password"
Reboot and the RPi is now connected to WiFi! Feedback is welcome as we would like to make this a more robust solution.
-
@oozebot I believe this will be built in with v3.3 - see https://github.com/Duet3D/DuetSoftwareFramework/tree/v3.3-dev/src/DuetPiManagementPlugin with lots of new M-codes for such network settings.
-
@resam good thing I only spent ~30 minutes on this.. lol