- Fixed disappearing GCode in Web.
- More efficient GCode scrolling with very large files.
- Fully functional soft-limited jogging.
- - Added basic Wifi configuration to admin tab.
- - Fixed broken hostname change redirect.
- - Split admin page.
+ - Added client and access-point Wifi configuration.
+ - Fixed broken hostname Web redirect after change.
+ - Split admin page -> General & Network.
+ - Improved calculation of junction velocity limits.
## v0.3.19
- Fixed stopping problems. #127
#!/bin/bash -e
AP=false
+DISABLE=false
SSID=
PASS=
CHANNEL=7
WPA_CFG=/etc/wpa_supplicant/wpa_supplicant.conf
-function query_ssid() {
+function query_config() {
if [ -e $WLAN0_CFG ]; then
- grep wpa-ssid $WLAN0_CFG | sed 's/^[[:space:]]*wpa-ssid "\([^"]*\)"/\1/'
+ SSID=$(grep wpa-ssid $WLAN0_CFG |
+ sed 's/^[[:space:]]*wpa-ssid "\([^"]*\)"/\1/')
+ echo "{\"ssid\": \"$SSID\", \"mode\": \"client\"}"
+
else
- if [ -e $HOSTAPD_CFG ]; then
- grep ^ssid $HOSTAPD_CFG | sed 's/^ssid="\(.*\)$"/\1/'
+ if [ -e $HOSTAPD_CFG -a -e /etc/default/hostapd ]; then
+ SSID=$(grep ^ssid= $HOSTAPD_CFG | sed 's/^ssid=\(.*\)$/\1/')
+ CHANNEL=$(grep ^channel= $HOSTAPD_CFG |
+ sed 's/^channel=\(.*\)$/\1/')
+
+ echo -n "{\"ssid\": \"$SSID\", "
+ echo "\"channel\": $CHANNEL, \"mode\": \"ap\"}"
+
+ else
+ echo "{\"mode\": \"disabled\"}"
fi
fi
+
+}
+
+
+function disable_wifi() {
+ rm -f $WLAN0_CFG $HOSTAPD_CFG /etc/default/hostapd
}
function configure_wifi() {
- # Disable AP
- service hostapd stop || true
- rm -f /etc/default/hostapd
-
- configure_wlan0 > $WLAN0_CFG
- configure_wpa > $WPA_CFG
- configure_dhcpcd > $DHCPCD_CFG
- service dhcpcd restart
+ disable_wifi
+ configure_wlan0 > $WLAN0_CFG
+ configure_wpa > $WPA_CFG
+ configure_dhcpcd > $DHCPCD_CFG
}
function configure_ap() {
- # Disable wifi config
- rm -f $WLAN0_CFG
+ disable_wifi
# Install packages
(
echo 1 > /proc/sys/net/ipv4/ip_forward
# Enable IP masquerading
- iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
+ iptables -t nat -F
+ iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables-save > /etc/iptables/rules.v4
-
- # Start services
- service dhcpcd restart
- service dnsmasq restart
- service hostapd restart
}
echo "OPTIONS:"
echo
echo " -a Configure access point."
+ echo " -d Disable wifi."
echo " -r Reboot when done."
echo " -s <SSID> Set SSID."
echo " -p <PASS> Set password."
echo " -c <CHANNEL> Set wifi channel."
- echo " -g Report SSID and exit."
+ echo " -j Report wifi config as JSON data."
echo
}
while [ $# -ne 0 ]; do
case "$1" in
-a) AP=true ;;
+ -d) DISABLE=true ;;
-r) REBOOT=true; ;;
-s) SSID="$2"; shift ;;
-p) PASS="$2"; shift ;;
-c) CHANNEL="$2"; shift ;;
- -g) query_ssid; exit 0 ;;
+ -j) query_config; exit 0 ;;
-h)
usage
done
-# Check args
-function clean_str() {
- echo "$1" | tr -d '\n\r"'
-}
+if $DISABLE; then
+ disable_wifi
-SSID=$(clean_str "$SSID")
-PASS=$(clean_str "$PASS")
+else
+ # Check args
+ function clean_str() {
+ echo "$1" | tr -d '\n\r"'
+ }
-LANG=C LC_ALL=C # For correct string byte length
+ SSID=$(clean_str "$SSID")
+ PASS=$(clean_str "$PASS")
-if [ ${#SSID} -eq 0 -o 32 -lt ${#SSID} ]; then
- echo "Invalid or missing SSID '$SSID'"
- exit 1
-fi
+ LANG=C LC_ALL=C # For correct string byte length
-if [ ${#PASS} -lt 8 -o 128 -lt ${#PASS} ]; then
- echo "Invalid passsword"
- exit 1
-fi
+ if [ ${#SSID} -eq 0 -o 32 -lt ${#SSID} ]; then
+ echo "Invalid or missing SSID '$SSID'"
+ exit 1
+ fi
-echo "$CHANNEL" | grep '^[0-9]\{1,2\}' > /dev/null
-if [ $? -ne 0 ]; then
- echo "Invalid channel '$CHANNEL'"
- exit 1
-fi
+ if [ ${#PASS} -lt 8 -o 128 -lt ${#PASS} ]; then
+ echo "Invalid passsword"
+ exit 1
+ fi
+ echo "$CHANNEL" | grep '^[0-9]\{1,2\}' > /dev/null
+ if [ $? -ne 0 ]; then
+ echo "Invalid channel '$CHANNEL'"
+ exit 1
+ fi
-# Execute
-if $AP; then
- echo "Configuring Wifi access point"
- configure_ap
-else
- echo "Configuring Wifi"
- configure_wifi
+ # Execute
+ if $AP; then
+ echo "Configuring Wifi access point"
+ configure_ap
+
+ else
+ echo "Configuring Wifi"
+ configure_wifi
+ fi
fi
h2 Wifi Setup
.pure-form.pure-form-aligned
.pure-control-group
- label(for="ssid") SSID
+ label(for="wifi_mode") Mode
+ select(name="wifi_mode", v-model="wifi_mode",
+ title="Select client or access point mode")
+ option(value="disabled") Disabled
+ option(value="client") Client
+ option(value="ap") Access Point
+ button.pure-button.pure-button-primary(@click="wifiConfirm = true",
+ v-if="wifi_mode == 'disabled'") Set
+ .pure-control-group(v-if="wifi_mode == 'ap'")
+ label(for="wifi_ch") Channel
+ select(name="wifi_ch", v-model="wifi_ch")
+ each ch in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
+ option(value="#{ch}")= ch
+ .pure-control-group(v-if="wifi_mode != 'disabled'")
+ label(for="ssid") Network (SSID)
input(name="ssid", v-model="wifi_ssid")
- .pure-control-group
+ .pure-control-group(v-if="wifi_mode != 'disabled'")
label(for="wifi_pass") Password
input(name="wifi_pass", v-model="wifi_pass", type="password")
button.pure-button.pure-button-primary(@click="wifiConfirm = true") Set
- message(:show.sync="wifiConfirm")
+ message.wifi-confirm(:show.sync="wifiConfirm")
h3(slot="header") Configure Wifi and reboot?
div(slot="body")
p
| automatically reboot.
table
tr
+ th Mode
+ td {{wifi_mode}}
+ tr(v-if="wifi_mode == 'ap'")
+ th Channel
+ td {{wifi_ch}}
+ tr(v-if="wifi_mode != 'disabled'")
th SSID
td {{wifi_ssid}}
- tr
+ tr(v-if="wifi_mode != 'disabled'")
th Auth
- td {{wifi_pass ? 'Password' : 'Open'}}
+ td {{wifi_pass ? 'WPA2' : 'Open'}}
div(slot="footer")
button.pure-button(@click="wifiConfirm = false") Cancel
current: '',
password: '',
password2: '',
+ wifi_mode: 'client',
wifi_ssid: '',
+ wifi_ch: undefined,
wifi_pass: '',
wifiConfirm: false,
rebooting: false
}.bind(this));
api.get('wifi').done(function (config) {
+ this.wifi_mode = config.mode;
this.wifi_ssid = config.ssid;
+ this.wifi_ch = config.channel;
}.bind(this));
},
this.wifiConfirm = false;
this.rebooting = true;
- api.put('wifi', {
+ var config = {
+ mode: this.wifi_mode,
+ channel: this.wifi_ch,
ssid: this.wifi_ssid,
pass: this.wifi_pass
+ }
- }).fail(function (error) {
+ api.put('wifi', config).fail(function (error) {
alert('Failed to configure WiFi: ' + JSON.stringify(error));
})
}
class WifiHandler(bbctrl.APIHandler):
def get(self):
- ssid = ''
+ data = {'ssid': '', 'channel': 0}
try:
- ssid = call_get_output(['config-wifi', '-g'])
+ data = json.loads(call_get_output(['config-wifi', '-j']))
except: pass
- self.write_json({'ssid': ssid})
+ self.write_json(data)
def put(self):
- if 'ssid' in self.json and 'pass' in self.json:
- if subprocess.call(['config-wifi', '-s', self.json['ssid'],
- '-p', self.json['pass']]) == 0:
+ if 'mode' in self.json:
+ cmd = ['config-wifi', '-r']
+ mode = self.json['mode']
+
+ if mode == 'disabled': cmd += ['-d']
+ elif 'ssid' in self.json:
+ cmd += ['-s', self.json['ssid']]
+
+ if mode == 'ap':
+ cmd += ['-a']
+ if 'channel' in self.json:
+ cmd += ['-c', self.json['channel']]
+
+ if 'pass' in self.json:
+ cmd += ['-p', self.json['pass']]
+
+ if subprocess.call(cmd) == 0:
self.write_json('ok')
return
margin-bottom 1em
clear both
+
+.wifi-confirm table
+ th
+ text-align right
+
+ th, td
+ padding 0 4px
+
+
.cheat-sheet
table
border-collapse collapse