From 9daae2923d8cb37ddaf3797cd7057ddc585eee0a Mon Sep 17 00:00:00 2001
From: saifullah-N
Date: Sat, 24 Dec 2022 12:45:09 +0530
Subject: [PATCH] units set , wifi fix
---
src/py/bbctrl/Web.py | 71 ++++++++++++-------
.../components/ConfigTemplatedInput.svelte | 2 +-
.../src/components/HelpView.svelte | 4 +-
.../src/components/SettingsView.svelte | 14 ++--
4 files changed, 57 insertions(+), 34 deletions(-)
diff --git a/src/py/bbctrl/Web.py b/src/py/bbctrl/Web.py
index 42074c6..d31eb77 100644
--- a/src/py/bbctrl/Web.py
+++ b/src/py/bbctrl/Web.py
@@ -10,6 +10,7 @@ from tornado import gen
import re
import bbctrl
from urllib.request import urlopen
+import iw_parse
def call_get_output(cmd):
@@ -150,43 +151,65 @@ class NetworkData(bbctrl.APIHandler):
'wifi': wifiName
})
-class WifiHandler(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)
+class NetworkHandler(bbctrl.APIHandler):
+ 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):
if self.get_ctrl().args.demo:
raise HTTPError(400, 'Cannot configure WiFi in demo mode')
- if 'mode' in self.json:
- cmd = ['config-wifi', '-r']
- mode = self.json['mode']
+ if not 'wifi' in self.json:
+ raise HTTPError(400, 'Payload is missing wifi config information')
- if mode == 'disabled': cmd += ['-d']
- elif 'ssid' in self.json:
- cmd += ['-s', self.json['ssid']]
+ wifi = self.json['wifi']
+ cmd = ['config-wifi', '-r']
- if mode == 'ap':
- cmd += ['-a']
- if 'channel' in self.json:
- cmd += ['-c', self.json['channel']]
+ if not wifi['enabled']:
+ cmd += ['-d']
+ else:
+ if 'ssid' in wifi:
+ cmd += ['-s', wifi['ssid']]
- if 'pass' in self.json:
- cmd += ['-p', self.json['pass']]
+ if 'password' in wifi:
+ cmd += ['-p', wifi['password']]
- if subprocess.call(cmd) == 0:
- self.write_json('ok')
- return
+ if subprocess.call(cmd) == 0:
+ self.write_json('ok')
+ return
raise HTTPError(400, 'Failed to configure wifi')
-
class UsernameHandler(bbctrl.APIHandler):
def get(self): self.write_json(get_username())
@@ -613,7 +636,7 @@ class Web(tornado.web.Application):
(r'/api/shutdown', ShutdownHandler),
(r'/api/hostname', HostnameHandler),
(r'/api/wifi', NetworkData),
- (r'/api/network', WifiHandler),
+ (r'/api/network', NetworkHandler),
(r'/api/remote/username', UsernameHandler),
(r'/api/remote/password', PasswordHandler),
(r'/api/config/load', ConfigLoadHandler),
diff --git a/src/svelte-components/src/components/ConfigTemplatedInput.svelte b/src/svelte-components/src/components/ConfigTemplatedInput.svelte
index 4b41474..5e11fc4 100644
--- a/src/svelte-components/src/components/ConfigTemplatedInput.svelte
+++ b/src/svelte-components/src/components/ConfigTemplatedInput.svelte
@@ -23,7 +23,7 @@
};
const namesByKey = {
- "junction-accel": "Default type",
+ "units":"units",
"probing-prompts": "Show safety prompts",
"probe-xdim": "Probe block width",
"probe-ydim": "Probe block length",
diff --git a/src/svelte-components/src/components/HelpView.svelte b/src/svelte-components/src/components/HelpView.svelte
index 5e339f5..233e1cb 100644
--- a/src/svelte-components/src/components/HelpView.svelte
+++ b/src/svelte-components/src/components/HelpView.svelte
@@ -16,13 +16,13 @@
for a variety of support resources, and to find our contact information.
-
+ -->
Discussion Forum
diff --git a/src/svelte-components/src/components/SettingsView.svelte b/src/svelte-components/src/components/SettingsView.svelte
index 7407f47..626bf4c 100644
--- a/src/svelte-components/src/components/SettingsView.svelte
+++ b/src/svelte-components/src/components/SettingsView.svelte
@@ -12,7 +12,7 @@
-
+
Settings
@@ -32,7 +32,7 @@
-
+
-
Gamepads / Joypads
+
Units