Allow disabling the internal WiFi so a USB dongle can be used.
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Thu, 8 Oct 2020 02:01:14 +0000 (19:01 -0700)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Thu, 8 Oct 2020 19:28:51 +0000 (12:28 -0700)
CHANGELOG.md
scripts/config-wifi
src/js/admin-network-view.js
src/pug/templates/admin-network-view.pug
src/py/bbctrl/Web.py

index 4bc0b97a72b19efb462d7a566ad9f19121493ef1..405a65cf7cc830bfc3f2bcbd87da9a647a067cd6 100644 (file)
@@ -14,6 +14,7 @@ Buildbotics CNC Controller Firmware Changelog
  - Clear planner coolant and spindle state on stop.
  - Fix web disconnect problem when downloading a bug report.
  - Fix for jogging on touch screens.
+ - Allow disabling the internal WiFi so a USB dongle can be used.
 
 ## v0.4.14
  - Handle file uploads with '#' or '?' in the name.
index 018c676f7101005dd2fae778ea5cef72705d7f61..f76300cd405333868b992c06cbdf60d537968908 100755 (executable)
@@ -6,19 +6,28 @@ SSID=
 PASS=
 CHANNEL=7
 REBOOT=false
+DISABLE_INTERNAL_WIFI=false
 
 WLAN0_CFG=/etc/network/interfaces.d/wlan0
 HOSTAPD_CFG=/etc/hostapd/hostapd.conf
 DNSMASQ_CFG=/etc/dnsmasq.conf
 DHCPCD_CFG=/etc/dhcpcd.conf
 WPA_CFG=/etc/wpa_supplicant/wpa_supplicant.conf
+MOD_DISABLE=/etc/modprobe.d/blacklist-internal-wifi.conf
 
 
 function query_config() {
+    if [ -e $MOD_DISABLE ]; then
+      INTERNAL=false
+    else
+      INTERNAL=true
+    fi
+
     if [ -e $WLAN0_CFG ]; then
         SSID=$(grep wpa-ssid $WLAN0_CFG |
                    sed 's/^[[:space:]]*wpa-ssid "\([^"]*\)"/\1/')
-        echo "{\"ssid\": \"$SSID\", \"mode\": \"client\"}"
+        echo -n "{\"ssid\": \"$SSID\", \"mode\": \"client\", "
+        echo "\"internal\": $INTERNAL}"
 
     else
         if [ -e $HOSTAPD_CFG -a -e /etc/default/hostapd ]; then
@@ -27,7 +36,8 @@ function query_config() {
                           sed 's/^channel=\(.*\)$/\1/')
 
             echo -n "{\"ssid\": \"$SSID\", "
-            echo "\"channel\": $CHANNEL, \"mode\": \"ap\"}"
+            echo -n "\"channel\": $CHANNEL, \"mode\": \"ap\" "
+            echo "\"internal\": $INTERNAL}"
 
         else
             echo "{\"mode\": \"disabled\"}"
@@ -177,6 +187,7 @@ function usage() {
     echo
     echo "  -a             Configure access point."
     echo "  -d             Disable wifi."
+    echo "  -x             Disable internal wifi."
     echo "  -r             Reboot when done."
     echo "  -s <SSID>      Set SSID."
     echo "  -p <PASS>      Set password."
@@ -191,6 +202,7 @@ while [ $# -ne 0 ]; do
     case "$1" in
         -a) AP=true ;;
         -d) DISABLE=true ;;
+        -x) DISABLE_INTERNAL_WIFI=true ;;
         -r) REBOOT=true; ;;
         -s) SSID="$2"; shift ;;
         -p) PASS="$2"; shift ;;
@@ -253,6 +265,18 @@ else
         echo "Configuring Wifi"
         configure_wifi
     fi
+
+    if $DISABLE_INTERNAL_WIFI; then
+      if [ ! -e $MOD_DISABLE ]; then
+        echo -e "blacklist brcmfmac\nblacklist brcmutil" > $MOD_DISABLE
+        REBOOT=true;
+      fi
+    else
+      if [ -e $MOD_DISABLE ]; then
+        rm $MOD_DISABLE
+        REBOOT=true;
+      fi
+    fi
 fi
 
 
index 4bc71cb66f61b894a224c863685fa4d1152abdc9..bf029cf823363a9498a9fa061ad925b768d2a51c 100644 (file)
@@ -48,6 +48,7 @@ module.exports = {
       password: '',
       password2: '',
       wifi_mode: 'client',
+      wifi_internal: true,
       wifi_ssid: '',
       wifi_ch: undefined,
       wifi_pass: '',
@@ -67,9 +68,10 @@ module.exports = {
     }.bind(this));
 
     api.get('wifi').done(function (config) {
-      this.wifi_mode = config.mode;
-      this.wifi_ssid = config.ssid;
-      this.wifi_ch = config.channel;
+      this.wifi_mode     = config.mode;
+      this.wifi_internal = config.internal;
+      this.wifi_ssid     = config.ssid;
+      this.wifi_ch       = config.channel;
     }.bind(this));
   },
 
@@ -162,10 +164,11 @@ module.exports = {
       this.rebooting = true;
 
       var config = {
-        mode:    this.wifi_mode,
-        channel: this.wifi_ch,
-        ssid:    this.wifi_ssid,
-        pass:    this.wifi_pass
+        mode:     this.wifi_mode,
+        internal: this.wifi_internal,
+        channel:  this.wifi_ch,
+        ssid:     this.wifi_ssid,
+        pass:     this.wifi_pass
       }
 
       api.put('wifi', config).fail(function (error) {
index eba33708a74b38fa830e42ee50ea18409e7a5fef..de1e9669716f1c31993a69076e2fcd2f28be4ccd 100644 (file)
@@ -81,6 +81,11 @@ script#admin-network-view-template(type="text/x-template")
         button.pure-button.pure-button-primary(@click="wifiConfirm = true",
           v-if="wifi_mode == 'disabled'") Set
 
+      .pure-control-group(v-if="wifi_mode != 'disabled'",
+        title="Use the intenral WiFi.  Disable to use a USB WiFi dongle")
+        label(for="internal") Internal WiFi
+        input(type="checkbox", v-model="wifi_internal")
+
       .pure-control-group(v-if="wifi_mode == 'ap'")
         label(for="wifi_ch") Channel
         select(name="wifi_ch", v-model="wifi_ch")
index 9815c361809c7153acbb93c4f0cca391a253d1c0..26747834cdeeffe6e1aa9ff50c404b3b5cdc5c91 100644 (file)
@@ -194,6 +194,9 @@ class WifiHandler(bbctrl.APIHandler):
             elif 'ssid' in self.json:
                 cmd += ['-s', self.json['ssid']]
 
+                if 'internal' in self.json and not self.json['internal']:
+                    cmd += ['-x']
+
                 if mode == 'ap':
                     cmd += ['-a']
                     if 'channel' in self.json: