Duet3D Logo

    Duet3D

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • Documentation
    • Order

    Setup RPi WiFi through ExecOnMCode

    DSF Development
    2
    3
    115
    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.
    • oozeBot
      oozeBot last edited by oozeBot

      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.

      resam 1 Reply Last reply Reply Quote 0
      • resam
        resam @oozeBot last edited by

        @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.

        oozeBot 1 Reply Last reply Reply Quote 1
        • oozeBot
          oozeBot @resam last edited by

          @resam good thing I only spent ~30 minutes on this.. lol

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