diff --git a/app/package.json b/app/package.json
index 8b32f9aa..e4229e37 100644
--- a/app/package.json
+++ b/app/package.json
@@ -10,6 +10,7 @@
"react-dom": "^16.13.1",
"react-dropzone": "^11.4.2",
"react-keyed-file-browser": "^1.14.0",
+ "react-qr-code": "^2.0.7",
"react-router-dom": "^5.2.0",
"react-scripts": "^3.4.1",
"react-semantic-toasts": "^0.6.5",
diff --git a/app/src/components/Admin.js b/app/src/components/Admin.js
index d067846d..58843847 100644
--- a/app/src/components/Admin.js
+++ b/app/src/components/Admin.js
@@ -7,7 +7,9 @@ import {
Divider,
Form,
Header,
+ Icon,
Loader,
+ Modal,
Placeholder,
Table
} from "semantic-ui-react";
@@ -33,6 +35,7 @@ import {
WROLModeMessage
} from "./Common";
import {Route} from "react-router-dom";
+import QRCode from "react-qr-code";
class Settings extends React.Component {
@@ -40,10 +43,15 @@ class Settings extends React.Component {
super(props);
this.state = {
disabled: false,
+ hotspot_encryption: 'WPA',
+ qrCodeValue: '',
+ qrOpen: false,
ready: false,
download_on_startup: null,
hotspot_on_startup: null,
+ hotspot_password: null,
+ hotspot_ssid: null,
hotspot_status: null,
throttle_on_startup: null,
throttle_status: null,
@@ -51,6 +59,7 @@ class Settings extends React.Component {
}
this.handleSubmit = this.handleSubmit.bind(this);
+ this.handleHotspotChange = this.handleHotspotChange.bind(this);
}
async componentDidMount() {
@@ -60,11 +69,13 @@ class Settings extends React.Component {
disabled: settings.wrol_mode,
download_on_startup: settings.download_on_startup,
hotspot_on_startup: settings.hotspot_on_startup,
+ hotspot_password: settings.hotspot_password,
+ hotspot_ssid: settings.hotspot_ssid,
hotspot_status: settings.hotspot_status,
throttle_on_startup: settings.throttle_on_startup,
throttle_status: settings.throttle_status,
timezone: {value: settings.timezone, label: settings.timezone},
- });
+ }, this.handleHotspotChange);
}
async handleSubmit(e) {
@@ -72,19 +83,24 @@ class Settings extends React.Component {
let settings = {
download_on_startup: this.state.download_on_startup,
hotspot_on_startup: this.state.hotspot_on_startup,
+ hotspot_password: this.state.hotspot_password,
+ hotspot_ssid: this.state.hotspot_ssid,
throttle_on_startup: this.state.throttle_on_startup,
timezone: this.state.timezone.value,
}
await saveSettings(settings);
}
- handleTimezoneChange = async (timezone) => {
- this.setState({timezone: timezone});
+ handleInputChange = async (e, name, value) => {
+ if (e) {e.preventDefault()}
+ this.setState({[name]: value});
}
- handleInputChange = async (e, name, checked) => {
- e.preventDefault();
- this.setState({[name]: checked});
+ handleHotspotChange = async () => {
+ let {hotspot_ssid, hotspot_encryption, hotspot_password} = this.state;
+ // Special string which allows a mobile device to connect to a specific Wi-Fi.
+ let qrCodeValue = `WIFI:S:${hotspot_ssid};T:${hotspot_encryption};P:${hotspot_password};;`;
+ this.setState({qrCodeValue});
}
render() {
@@ -92,7 +108,16 @@ class Settings extends React.Component {
return
}
- let {disabled, download_on_startup, hotspot_on_startup, throttle_on_startup, timezone} = this.state;
+ let {
+ disabled,
+ download_on_startup,
+ hotspot_on_startup,
+ hotspot_password,
+ hotspot_ssid,
+ qrCodeValue,
+ throttle_on_startup,
+ timezone,
+ } = this.state;
return (
@@ -138,11 +163,41 @@ class Settings extends React.Component {
onChange={(e, d) => this.handleInputChange(e, 'throttle_on_startup', d.checked)}
/>
+
+
+ this.setState({hotspot_ssid: d.value}, this.handleHotspotChange)}
+ />
+
+ this.setState({hotspot_password: d.value}, this.handleHotspotChange)}
+ />
+ this.setState({qrOpen: false})}
+ onOpen={() => this.setState({qrOpen: true})}
+ open={this.state.qrOpen}
+ trigger={}
+ >
+
+ Scan this code to join the hotspot
+
+
+
+
+
+
+
this.handleInputChange(null, 'timezone', v)}
/>
diff --git a/wrolpi/admin.py b/wrolpi/admin.py
index cbff952a..c1ea968a 100644
--- a/wrolpi/admin.py
+++ b/wrolpi/admin.py
@@ -2,7 +2,7 @@ import enum
import subprocess
from wrolpi.cmd import which
-from wrolpi.common import logger
+from wrolpi.common import logger, WROLPI_CONFIG
from wrolpi.vars import DEFAULT_CPU_FREQUENCY, DOCKERIZED
logger = logger.getChild(__name__)
@@ -59,7 +59,7 @@ def enable_hotspot():
elif status == HotspotStatus.disconnected:
# Radio is on, but not connected. Good, turn it into a hotspot.
cmd = (SUDO, NMCLI, 'device', 'wifi', 'hotspot', 'ifname', 'wlan0',
- 'ssid', 'WROLPi', 'password', 'wrolpi hotspot')
+ 'ssid', WROLPI_CONFIG.hotspot_ssid, 'password', WROLPI_CONFIG.hotspot_password)
subprocess.check_call(cmd)
return True
elif status == HotspotStatus.unavailable:
diff --git a/wrolpi/common.py b/wrolpi/common.py
index a23a7c35..8c56482a 100644
--- a/wrolpi/common.py
+++ b/wrolpi/common.py
@@ -262,6 +262,8 @@ class WROLPiConfig(ConfigFile):
default_config = dict(
download_on_startup=True,
hotspot_on_startup=True,
+ hotspot_password='wrolpi hotspot',
+ hotspot_ssid='WROLPi',
throttle_on_startup=False,
timezone=str(DEFAULT_TIMEZONE),
wrol_mode=False,
@@ -283,6 +285,22 @@ class WROLPiConfig(ConfigFile):
def hotspot_on_startup(self, value: bool):
self.update({'hotspot_on_startup': value})
+ @property
+ def hotspot_password(self) -> str:
+ return self._config['hotspot_password']
+
+ @hotspot_password.setter
+ def hotspot_password(self, value: str):
+ self.update({'hotspot_password': value})
+
+ @property
+ def hotspot_ssid(self) -> str:
+ return self._config['hotspot_ssid']
+
+ @hotspot_ssid.setter
+ def hotspot_ssid(self, value: str):
+ self.update({'hotspot_ssid': value})
+
@property
def throttle_on_startup(self) -> bool:
return self._config['throttle_on_startup']
diff --git a/wrolpi/conftest.py b/wrolpi/conftest.py
index 49bd2d29..d7552df3 100644
--- a/wrolpi/conftest.py
+++ b/wrolpi/conftest.py
@@ -83,7 +83,7 @@ def test_directory() -> pathlib.Path:
@pytest.fixture(autouse=True)
-def test_config(test_directory):
+def test_config(test_directory) -> pathlib.Path:
"""
Create a test config based off the example config.
"""
diff --git a/wrolpi/root_api.py b/wrolpi/root_api.py
index 77e93f71..6b9342e7 100644
--- a/wrolpi/root_api.py
+++ b/wrolpi/root_api.py
@@ -119,6 +119,8 @@ def get_settings(_: Request):
settings = {
'download_on_startup': config.download_on_startup,
'hotspot_on_startup': config.hotspot_on_startup,
+ 'hotspot_password': config.hotspot_password,
+ 'hotspot_ssid': config.hotspot_ssid,
'hotspot_status': admin.hotspot_status().name,
'media_directory': get_media_directory(),
'throttle_on_startup': config.throttle_on_startup,
diff --git a/wrolpi/schema.py b/wrolpi/schema.py
index a1969cdd..4b01b9ef 100644
--- a/wrolpi/schema.py
+++ b/wrolpi/schema.py
@@ -16,6 +16,8 @@ class SettingsResponse:
class SettingsRequest:
download_on_startup: Optional[bool] = None
hotspot_on_startup: Optional[bool] = None
+ hotspot_password: Optional[str] = None
+ hotspot_ssid: Optional[str] = None
hotspot_status: Optional[bool] = None
media_directory: Optional[str] = None
throttle_on: Optional[bool] = None
diff --git a/wrolpi/test/test_admin.py b/wrolpi/test/test_admin.py
index cc7fd2be..76d52552 100644
--- a/wrolpi/test/test_admin.py
+++ b/wrolpi/test/test_admin.py
@@ -4,6 +4,7 @@ from unittest.mock import call
from wrolpi import admin
from wrolpi.admin import HotspotStatus
+from wrolpi.common import WROLPI_CONFIG
from wrolpi.test.common import skip_circleci
@@ -68,6 +69,31 @@ def test_enable_hotspot_connected():
)
+def test_change_hotspot(test_config):
+ """The hotspot can be configured."""
+ with mock.patch('wrolpi.admin.hotspot_status') as mock_hotspot_status, \
+ mock.patch('wrolpi.admin.subprocess') as mock_subprocess, \
+ mock.patch('wrolpi.admin.NMCLI', PosixPath('/usr/bin/nmcli')):
+ mock_subprocess.check_output.return_value = 0
+ mock_hotspot_status.return_value = HotspotStatus.disconnected
+ assert admin.enable_hotspot() is True
+ mock_subprocess.check_call.assert_called_once_with(
+ (PosixPath('/usr/bin/sudo'), PosixPath('/usr/bin/nmcli'), 'device', 'wifi', 'hotspot', 'ifname', 'wlan0',
+ 'ssid', 'WROLPi', 'password', 'wrolpi hotspot'))
+
+ WROLPI_CONFIG.hotspot_ssid = 'New SSID'
+ WROLPI_CONFIG.hotspot_password = '$uper Secure *#'
+ with mock.patch('wrolpi.admin.hotspot_status') as mock_hotspot_status, \
+ mock.patch('wrolpi.admin.subprocess') as mock_subprocess, \
+ mock.patch('wrolpi.admin.NMCLI', PosixPath('/usr/bin/nmcli')):
+ mock_subprocess.check_output.return_value = 0
+ mock_hotspot_status.return_value = HotspotStatus.disconnected
+ assert admin.enable_hotspot() is True
+ mock_subprocess.check_call.assert_called_once_with(
+ (PosixPath('/usr/bin/sudo'), PosixPath('/usr/bin/nmcli'), 'device', 'wifi', 'hotspot', 'ifname', 'wlan0',
+ 'ssid', 'New SSID', 'password', '$uper Secure *#'))
+
+
def test_throttle_on():
with mock.patch('wrolpi.admin.subprocess') as mock_subprocess, \
mock.patch('wrolpi.admin.CPUFREQ_SET', PosixPath('/usr/bin/cpufreq-set')):
diff --git a/wrolpi/test/test_root_api.py b/wrolpi/test/test_root_api.py
index 45f27bf1..a50dce75 100644
--- a/wrolpi/test/test_root_api.py
+++ b/wrolpi/test/test_root_api.py
@@ -200,6 +200,14 @@ def test_hotspot_settings(test_session, test_client, test_config):
config = get_config()
assert config.hotspot_on_startup is True
+ # Hotspot password can be changed.
+ mock_admin.disable_hotspot.return_value = True
+ content = {'hotspot_password': 'new password', 'hotspot_ssid': 'new ssid'}
+ request, response = test_client.patch('/api/settings', content=json.dumps(content))
+ assert response.status_code == HTTPStatus.NO_CONTENT
+ assert config.hotspot_password == 'new password'
+ assert config.hotspot_ssid == 'new ssid'
+
@skip_circleci
def test_throttle_toggle(test_session, test_client, test_config):
diff --git a/wrolpi/version.py b/wrolpi/version.py
index fcf670a8..732a278f 100644
--- a/wrolpi/version.py
+++ b/wrolpi/version.py
@@ -1,4 +1,4 @@
-__version__ = '0.4.5-beta'
+__version__ = '0.4.6-beta'
import subprocess