MycroftOS: Refactoring wifi setup system

This commit is contained in:
j1nx 2020-05-28 09:12:54 +02:00
parent c728c35897
commit fe07bf5bfb
11 changed files with 45 additions and 102 deletions

View File

@ -28,12 +28,12 @@ def save_credentials():
create_wpa_supplicant(ssid, wifi_key)
# Call reboot_device() in a thread otherwise the reboot will prevent
# Call reconfigure_device() in a thread otherwise the reconfigure will prevent
# the response from getting to the browser
def sleep_and_reboot():
def sleep_and_reconfigure():
time.sleep(2)
reboot_device()
t = Thread(target=sleep_and_reboot)
reconfigure_device()
t = Thread(target=sleep_and_reconfigure)
t.start()
return render_template('save_credentials.html', ssid = ssid)
@ -43,12 +43,12 @@ def skip_wifi():
empty_wpa_supplicant()
# Call reboot_device() in a thread otherwise the reboot will prevent
# Call reconfigure_device() in a thread otherwise the reconfigure will prevent
# the response from getting to the browser
def sleep_and_reboot():
def sleep_and_reconfigure():
time.sleep(2)
reboot_device()
t = Thread(target=sleep_and_reboot)
reconfigure_device()
t = Thread(target=sleep_and_reconfigure)
t.start()
return render_template('cancelled_wifi.html')
@ -104,9 +104,10 @@ def empty_wpa_supplicant():
os.system('mv wpa_supplicant-wlan0.conf.tmp /etc/wpa_supplicant/wpa_supplicant-wlan0.conf')
def reboot_device():
os.system('reboot')
def reconfigure_device():
os.system('systemctl disable wpa_supplicant@ap0.service')
os.system('systemctl enable wpa_supplicant@wlan0.service')
os.system('systemctl start wpa_supplicant@wlan0.service')
if __name__ == '__main__':
os.system("fbv -f -d 1 /opt/mycroft/wifisetup/static/images/wifi.png > /dev/null 2>&1")
app.run(host = '0.0.0.0', port = '88')

View File

@ -15,45 +15,20 @@ define WIFI_AP_INSTALL_TARGET_CMDS
$(INSTALL) -m 644 -D $(@D)/wpa_supplicant-ap0.conf \
$(TARGET_DIR)/etc/wpa_supplicant/wpa_supplicant-ap0.conf
$(INSTALL) -D -m 644 $(@D)/wpa_supplicant-ap0.service \
$(TARGET_DIR)/usr/lib/systemd/system/wpa_supplicant-ap0.service
mkdir -p $(TARGET_DIR)/etc/systemd/system/sys-subsystem-net-devices-ap0.device.wants
ln -fs ../../../../usr/lib/systemd/system/wpa_supplicant-ap0.service \
$(TARGET_DIR)/etc/systemd/system/sys-subsystem-net-devices-ap0.device.wants/wpa_supplicant-ap0.service
$(INSTALL) -D -m 644 $(@D)/wpa_supplicant@ap0.service \
$(TARGET_DIR)/usr/lib/systemd/system/wpa_supplicant@ap0.service
$(INSTALL) -D -m 644 $(@D)/wifi-setup.service \
$(TARGET_DIR)/usr/lib/systemd/system/wifi-setup.service
ln -fs ../../../../usr/lib/systemd/system/wifi-setup.service \
$(TARGET_DIR)/etc/systemd/system/sys-subsystem-net-devices-ap0.device.wants/wifi-setup.service
$(INSTALL) -D -m 644 $(@D)/dnsmasq.service \
$(TARGET_DIR)/usr/lib/systemd/system/dnsmasq.service
ln -fs ../../../../usr/lib/systemd/system/dnsmasq.service \
$(TARGET_DIR)/etc/systemd/system/sys-subsystem-net-devices-ap0.device.wants/dnsmasq.service
$(INSTALL) -D -m 644 $(@D)/wireless-mode-ap.service \
$(TARGET_DIR)/usr/lib/systemd/system/wireless-mode-ap.service
mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
ln -fs ../../../../usr/lib/systemd/system/wireless-mode-ap.service \
$(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/wireless-mode-ap.service
$(INSTALL) -D -m 644 $(@D)/wireless-mode-client.service \
$(TARGET_DIR)/usr/lib/systemd/system/wireless-mode-client.service
mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
ln -fs ../../../../usr/lib/systemd/system/wireless-mode-client.service \
$(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/wireless-mode-client.service
$(INSTALL) -D -m 644 $(@D)/nginx.service \
$(TARGET_DIR)/usr/lib/systemd/system/nginx.service
mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
ln -fs ../../../../usr/lib/systemd/system/nginx.service \
$(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/nginx.service
$(INSTALL) -D -m 644 $(@D)/iptables.service \
$(TARGET_DIR)/usr/lib/systemd/system/iptables.service
mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
ln -fs ../../../../usr/lib/systemd/system/iptables.service \
$(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/iptables.service
endef
$(eval $(generic-package))

View File

@ -1,18 +1,15 @@
[Unit]
Description=MycroftOS-WiFiSetup webbased configurator
BindsTo=sys-subsystem-net-devices-ap0.device
After=sys-subsystem-net-devices-ap0.device
Description=MycroftOS WiFi Setup - webbased configurator
After=wpa_supplicant@ap0.service
Wants=wpa_supplicant@ap0.service
Conflicts=wpa_supplicant@wlan0.service
Before=network.target
Wants=network.target
# check existence of configuration file
ConditionPathExists= /etc/wpa_supplicant/wpa_supplicant-ap0.conf
ConditionPathExists=!/etc/wpa_supplicant/wpa_supplicant-wlan0.conf
[Service]
Type=idle
WorkingDirectory=/opt/mycroft/wifisetup
ExecStart=/usr/bin/python3 app.py > /dev/null 2>&1
[Install]
WantedBy=sys-subsystem-net-devices-ap0.device
WantedBy=multi-user.target

View File

@ -1,16 +0,0 @@
[Unit]
Description=Wireless mode set AP
Before=wpa_supplicant@.service
Before=systemd-networkd.service
Wants=network.target
# check existence of configuration file
ConditionPathExists= /etc/wpa_supplicant/wpa_supplicant-ap0.conf
ConditionPathExists=!/etc/wpa_supplicant/wpa_supplicant-wlan0.conf
[Service]
Type=oneshot
ExecStart=/bin/ln -sf wifi.network.ap /etc/systemd/network/wifi.network
[Install]
WantedBy=multi-user.target

View File

@ -1,15 +0,0 @@
[Unit]
Description=Wireless mode set client
Before=wpa_supplicant@.service
Before=systemd-networkd.service
Wants=network.target
# check existence of configuration file
ConditionPathExists=/etc/wpa_supplicant/wpa_supplicant-wlan0.conf
[Service]
Type=oneshot
ExecStart=/bin/ln -sf wifi.network.client /etc/systemd/network/wifi.network
[Install]
WantedBy=multi-user.target

View File

@ -2,7 +2,7 @@ ctrl_interface=/var/run/wpa_supplicant
update_config=1
network={
ssid="MycroftOS-WiFiSetup"
ssid="MYCROFT"
mode=2
key_mgmt=NONE
}

View File

@ -1,18 +0,0 @@
[Unit]
Description=WPA supplicant daemon (interface-specific version)
Requires=sys-subsystem-net-devices-ap0.device
After=sys-subsystem-net-devices-ap0.device
Before=network.target
Wants=network.target
# check existence of configuration file
ConditionPathExists=!/etc/wpa_supplicant/wpa_supplicant-wlan0.conf
# NetworkManager users will probably want the dbus version instead.
[Service]
Type=simple
ExecStart=/usr/sbin/wpa_supplicant -c/etc/wpa_supplicant/wpa_supplicant-ap0.conf -iap0
[Install]
WantedBy=sys-subsystem-net-devices-ap0.device

View File

@ -0,0 +1,18 @@
[Unit]
Description=WPA supplicant daemon (interface-specific version)
Requires=sys-subsystem-net-devices-wlan0.device
After=sys-subsystem-net-devices-wlan0.device
Conflicts=wpa_supplicant@wlan0.service
Before=network.target
Wants=network.target
# NetworkManager users will probably want the dbus version instead.
[Service]
Type=simple
ExecStartPre=/usr/sbin/iw dev wlan0 interface add ap0 type __ap
ExecStart=/usr/sbin/wpa_supplicant -c/etc/wpa_supplicant/wpa_supplicant-ap0.conf -Dnl80211,wext -iap0
ExecStopPost=/usr/sbin/iw dev ap0 del
[Install]
Alias=multi-user.target.wants/wpa_supplicant@%i.service

View File

@ -1,4 +1,4 @@
enable wpa_supplicant@wlan0.service
enable wpa_supplicant@ap0.service
enable firstboot.service
enable prepare_system.service
@ -20,8 +20,8 @@ enable mycroft-audio.service
enable mycroft-skills.service
enable mycroft-enclosure.service
enable mycroft-gui.service
enable mycroft-splash-quit.service
disable mycroft-splash-quit.service
disable getty@.service
disable mosquitto.service
disable motion.service
@ -31,3 +31,4 @@ disable snapclient.service
disable snapserver.service
disable spotifyd.service
disable wpa_supplicant@wlan0.service