units set , wifi fix

This commit is contained in:
saifullah-N
2022-12-24 12:45:09 +05:30
parent dd54584857
commit 9daae2923d
4 changed files with 57 additions and 34 deletions

View File

@@ -10,6 +10,7 @@ from tornado import gen
import re import re
import bbctrl import bbctrl
from urllib.request import urlopen from urllib.request import urlopen
import iw_parse
def call_get_output(cmd): def call_get_output(cmd):
@@ -150,43 +151,65 @@ class NetworkData(bbctrl.APIHandler):
'wifi': wifiName 'wifi': wifiName
}) })
class WifiHandler(bbctrl.APIHandler): class NetworkHandler(bbctrl.APIHandler):
def get(self):
data = {'ssid': '', 'channel': 0}
try:
data = json.loads(call_get_output(['config-wifi', '-j']))
except: pass
self.write_json(data)
def get(self):
try:
ipAddresses = subprocess.check_output(
"ip -4 addr | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'", shell=True).decode().split()
ipAddresses.remove("127.0.0.1")
regex = re.compile(r'/255$/')
filtered = [i for i in ipAddresses if not regex.match(i)]
ipAddresses = filtered[0]
except:
ipAddresses = "Not Connected"
hostname = socket.gethostname()
try:
wifi = json.loads(call_get_output(['config-wifi', '-j']))
except:
wifi = {'enabled': False}
try:
lines = iw_parse.call_iwlist().decode("utf-8").split("\n")
wifi['networks'] = iw_parse.get_parsed_cells(lines)
except:
wifi['networks'] = []
self.write_json({
'ipAddresses': ipAddresses,
'hostname': hostname,
'wifi': wifi
})
def put(self): def put(self):
if self.get_ctrl().args.demo: if self.get_ctrl().args.demo:
raise HTTPError(400, 'Cannot configure WiFi in demo mode') raise HTTPError(400, 'Cannot configure WiFi in demo mode')
if 'mode' in self.json: if not 'wifi' in self.json:
cmd = ['config-wifi', '-r'] raise HTTPError(400, 'Payload is missing wifi config information')
mode = self.json['mode']
if mode == 'disabled': cmd += ['-d'] wifi = self.json['wifi']
elif 'ssid' in self.json: cmd = ['config-wifi', '-r']
cmd += ['-s', self.json['ssid']]
if mode == 'ap': if not wifi['enabled']:
cmd += ['-a'] cmd += ['-d']
if 'channel' in self.json: else:
cmd += ['-c', self.json['channel']] if 'ssid' in wifi:
cmd += ['-s', wifi['ssid']]
if 'pass' in self.json: if 'password' in wifi:
cmd += ['-p', self.json['pass']] cmd += ['-p', wifi['password']]
if subprocess.call(cmd) == 0: if subprocess.call(cmd) == 0:
self.write_json('ok') self.write_json('ok')
return return
raise HTTPError(400, 'Failed to configure wifi') raise HTTPError(400, 'Failed to configure wifi')
class UsernameHandler(bbctrl.APIHandler): class UsernameHandler(bbctrl.APIHandler):
def get(self): self.write_json(get_username()) def get(self): self.write_json(get_username())
@@ -613,7 +636,7 @@ class Web(tornado.web.Application):
(r'/api/shutdown', ShutdownHandler), (r'/api/shutdown', ShutdownHandler),
(r'/api/hostname', HostnameHandler), (r'/api/hostname', HostnameHandler),
(r'/api/wifi', NetworkData), (r'/api/wifi', NetworkData),
(r'/api/network', WifiHandler), (r'/api/network', NetworkHandler),
(r'/api/remote/username', UsernameHandler), (r'/api/remote/username', UsernameHandler),
(r'/api/remote/password', PasswordHandler), (r'/api/remote/password', PasswordHandler),
(r'/api/config/load', ConfigLoadHandler), (r'/api/config/load', ConfigLoadHandler),

View File

@@ -23,7 +23,7 @@
}; };
const namesByKey = { const namesByKey = {
"junction-accel": "Default type", "units":"units",
"probing-prompts": "Show safety prompts", "probing-prompts": "Show safety prompts",
"probe-xdim": "Probe block width", "probe-xdim": "Probe block width",
"probe-ydim": "Probe block length", "probe-ydim": "Probe block length",

View File

@@ -16,13 +16,13 @@
for a variety of support resources, and to find our contact information. for a variety of support resources, and to find our contact information.
</p> </p>
<Button <!-- <Button
touch touch
variant="raised" variant="raised"
on:click={() => (showRemoteDiagnosticsDialog = true)} on:click={() => (showRemoteDiagnosticsDialog = true)}
> >
<Label>Remote Diagnostics</Label> <Label>Remote Diagnostics</Label>
</Button> </Button> -->
<h2>Discussion Forum</h2> <h2>Discussion Forum</h2>
<p> <p>

View File

@@ -12,7 +12,7 @@
</script> </script>
<ScreenRotationDialog bind:open={showScreenRotationDialog} /> <ScreenRotationDialog bind:open={showScreenRotationDialog} />
<SetTimeDialog bind:open={showSetTimeDialog} /> <!-- <SetTimeDialog bind:open={showSetTimeDialog} /> -->
<div class="settings-view"> <div class="settings-view">
<h1>Settings</h1> <h1>Settings</h1>
@@ -32,7 +32,7 @@
</Button> </Button>
</div> </div>
<div class="pure-control-group"> <!-- <div class="pure-control-group">
<label for="set-time" /> <label for="set-time" />
<Button <Button
name="set-time" name="set-time"
@@ -42,15 +42,15 @@
> >
<Label>Change Time & Timezone</Label> <Label>Change Time & Timezone</Label>
</Button> </Button>
</div> </div> -->
</fieldset> </fieldset>
<h2>Gamepads / Joypads</h2> <h2>Units</h2>
<fieldset> <fieldset>
<ConfigTemplatedInput key={`settings.junction-accel`} /> <ConfigTemplatedInput key={`settings.units`} />
<div class="tip"> <div class="tip">
If your gamepad doesn't work as expected, try one of the other Note, units sets both the machine default units and the units used in motor configuration. GCode program-start,
types. set below, may also change the default machine units.
</div> </div>
</fieldset> </fieldset>