Wifi config error handling
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Tue, 28 Jan 2020 18:03:23 +0000 (10:03 -0800)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Tue, 28 Jan 2020 22:47:07 +0000 (14:47 -0800)
CHANGELOG.md
scripts/config-wifi
src/js/admin-network-view.js

index ac9005d52aeb4f7e34a95578fc2b475693a1baf5..d52449773339dec393a3a641c965e75c5cf40c27 100644 (file)
@@ -3,6 +3,8 @@ Buildbotics CNC Controller Firmware Changelog
 
 ## v0.4.13
  - Support for OMRON MX2 VFD.
+ - Better error handling in WiFi configuration.
+ - Fix open WiFi access.
 
 ## v0.4.12
  - Segments straddle arc in linearization.
index d6be64ffdaadcd7d57e7f2d3b85c5a7fc6fa2506..018c676f7101005dd2fae778ea5cef72705d7f61 100755 (executable)
@@ -53,8 +53,9 @@ function configure_wlan0() {
     echo "  wpa-pairwise CCMP TKIP"
     echo "  wpa-group CCMP TKIP"
     echo "  wpa-ssid \"$SSID\""
+
     if [ ${#PASS} -ne 0 ]; then
-        echo "  wpa-psk \"$PASS\""
+      echo "  wpa-psk \"$PASS\""
     fi
 }
 
@@ -230,9 +231,11 @@ else
         exit 1
     fi
 
-    if [ ${#PASS} -lt 8 -o 128 -lt ${#PASS} ]; then
+    if [ ${#PASS} -ne 0 ]; then
+      if [ ${#PASS} -lt 8 -o 128 -lt ${#PASS} ]; then
         echo "Invalid passsword"
         exit 1
+      fi
     fi
 
     echo "$CHANNEL" | grep '^[0-9]\{1,2\}' > /dev/null
@@ -241,7 +244,6 @@ else
         exit 1
     fi
 
-
     # Execute
     if $AP; then
         echo "Configuring Wifi access point"
index 4268d35c46966bd2e1a38313738164c5315f1d80..1dae7b27ca1b67b80bf911ca0253fa86b7c2936f 100644 (file)
@@ -116,12 +116,12 @@ module.exports = {
 
     set_password: function () {
       if (this.password != this.password2) {
-        api.alert('Passwords to not match');
+        alert('Passwords to not match');
         return;
       }
 
       if (this.password.length < 6) {
-        api.alert('Password too short');
+        alert('Password too short');
         return;
       }
 
@@ -139,13 +139,33 @@ module.exports = {
     config_wifi: function () {
       this.wifiConfirm = false;
 
+      if (!this.wifi_ssid.length) {
+        alert('SSID not set');
+        return;
+      }
+
+      if (32 < this.wifi_ssid.length) {
+        alert('SSID longer than 32 characters');
+        return;
+      }
+
+      if (this.wifi_pass.length && this.wifi_pass.length < 8) {
+        alert('WiFi password shorter than 8 characters');
+        return;
+      }
+
+      if (128 < this.wifi_pass.length) {
+        alert('WiFi password longer than 128 characters');
+        return;
+      }
+
       this.rebooting = true;
 
       var config = {
-        mode: this.wifi_mode,
+        mode:    this.wifi_mode,
         channel: this.wifi_ch,
-        ssid: this.wifi_ssid,
-        pass: this.wifi_pass
+        ssid:    this.wifi_ssid,
+        pass:    this.wifi_pass
       }
 
       api.put('wifi', config).fail(function (error) {