Compare commits
5 Commits
bb06a9f97d
...
642f262426
Author | SHA1 | Date |
---|---|---|
j1nx | 642f262426 | |
j1nx | 94769cf11f | |
j1nx | 802cb2c61e | |
j1nx | 3eb5e33826 | |
j1nx | 0191ffb463 |
|
@ -4,7 +4,7 @@
|
|||
#
|
||||
################################################################################
|
||||
|
||||
MYCROFT_SKILL_OVOS_SETUP_VERSION = 033a02171221e33af25eadfdbb6780885c2995b7
|
||||
MYCROFT_SKILL_OVOS_SETUP_VERSION = 5153d5345f046e6dec71896975c18d6081758d79
|
||||
MYCROFT_SKILL_OVOS_SETUP_SITE = https://github.com/OpenVoiceOS/skill-ovos-setup
|
||||
MYCROFT_SKILL_OVOS_SETUP_SITE_METHOD = git
|
||||
MYCROFT_SKILL_OVOS_SETUP_DIRLOCATION = home/mycroft/.local/share/mycroft/skills
|
||||
|
|
|
@ -1,280 +0,0 @@
|
|||
From 6b34ebccc767f33d060ed40b5c46ebb4ee34ca2f Mon Sep 17 00:00:00 2001
|
||||
From: Aditya Mehra <aix.m@outlook.com>
|
||||
Date: Fri, 27 May 2022 18:12:21 +0930
|
||||
Subject: [PATCH] Adapt and port to wifi plugin
|
||||
|
||||
---
|
||||
ovos_PHAL_plugin_balena_wifi/__init__.py | 197 +++++++++++------------
|
||||
1 file changed, 91 insertions(+), 106 deletions(-)
|
||||
|
||||
diff --git a/ovos_PHAL_plugin_balena_wifi/__init__.py b/ovos_PHAL_plugin_balena_wifi/__init__.py
|
||||
index 0a0f64d..8f80c0d 100644
|
||||
--- a/ovos_PHAL_plugin_balena_wifi/__init__.py
|
||||
+++ b/ovos_PHAL_plugin_balena_wifi/__init__.py
|
||||
@@ -1,102 +1,98 @@
|
||||
-from os.path import join, dirname
|
||||
+import random
|
||||
+from os.path import dirname, join
|
||||
+from time import sleep
|
||||
|
||||
import pexpect
|
||||
-import random
|
||||
-import subprocess
|
||||
from mycroft_bus_client.message import Message, dig_for_message
|
||||
from ovos_plugin_manager.phal import PHALPlugin
|
||||
-from ovos_utils import create_daemon
|
||||
-from ovos_utils.enclosure.api import EnclosureAPI
|
||||
from ovos_utils.gui import GUIInterface
|
||||
from ovos_utils.log import LOG
|
||||
-from ovos_utils.network_utils import is_connected
|
||||
-from time import sleep
|
||||
|
||||
|
||||
class BalenaWifiSetupPlugin(PHALPlugin):
|
||||
def __init__(self, bus=None, config=None):
|
||||
super().__init__(bus=bus, name="ovos-PHAL-plugin-balena-wifi", config=config)
|
||||
- self.monitoring = False
|
||||
+ self.gui = GUIInterface(bus=self.bus, skill_id=self.name)
|
||||
+ self.client_active = False
|
||||
+ self.client_id = None
|
||||
+ self.registered = False
|
||||
self.in_setup = False
|
||||
- self.connected = False
|
||||
+
|
||||
self.wifi_process = None
|
||||
- self.debug = False # dev setting, VERY VERBOSE DIALOGS
|
||||
+ self.debug = True # dev setting, VERY VERBOSE DIALOGS
|
||||
self.ssid = "OVOS"
|
||||
self.pswd = None
|
||||
- self.grace_period = 45
|
||||
- self.time_between_checks = 30 # seconds
|
||||
- self.mycroft_ready = False
|
||||
self.wifi_command = "sudo /usr/local/sbin/wifi-connect --portal-ssid {ssid}"
|
||||
if self.pswd:
|
||||
self.wifi_command += " --portal-passphrase {pswd}"
|
||||
self.color = "#FF0000"
|
||||
- self.stop_on_internet = False
|
||||
- self.timeout_after_internet = 90
|
||||
-
|
||||
- self.bus.on("mycroft.internet.connected", self.handle_internet_connected)
|
||||
-
|
||||
- self.enclosure = EnclosureAPI(bus=self.bus, skill_id=self.name)
|
||||
- self.gui = GUIInterface(bus=self.bus, skill_id=self.name)
|
||||
- self.start_internet_check()
|
||||
-
|
||||
- # internet watchdog
|
||||
- def start_internet_check(self):
|
||||
- create_daemon(self._watchdog)
|
||||
-
|
||||
- def stop_internet_check(self):
|
||||
- self.monitoring = False
|
||||
-
|
||||
- def _watchdog(self):
|
||||
- try:
|
||||
- self.monitoring = True
|
||||
- LOG.info("Wifi watchdog started")
|
||||
- output = subprocess.check_output("nmcli connection show",
|
||||
- shell=True).decode("utf-8")
|
||||
- if "wifi" in output:
|
||||
- LOG.info("Detected previously configured wifi, starting "
|
||||
- "grace period to allow it to connect")
|
||||
- sleep(self.grace_period)
|
||||
- while self.monitoring:
|
||||
- if self.in_setup:
|
||||
- sleep(1) # let setup do it's thing
|
||||
- continue
|
||||
-
|
||||
- if not is_connected():
|
||||
- LOG.info("NO INTERNET")
|
||||
- if not self.is_connected_to_wifi():
|
||||
- LOG.info("LAUNCH SETUP")
|
||||
- try:
|
||||
- self.launch_wifi_setup() # blocking
|
||||
- except Exception as e:
|
||||
- LOG.exception(e)
|
||||
- else:
|
||||
- LOG.warning("CONNECTED TO WIFI, BUT NO INTERNET!!")
|
||||
-
|
||||
- sleep(self.time_between_checks)
|
||||
- except Exception as e:
|
||||
- LOG.error("Wifi watchdog crashed unexpectedly")
|
||||
- LOG.exception(e)
|
||||
-
|
||||
- # wifi setup
|
||||
- @staticmethod
|
||||
- def get_wifi_ssid():
|
||||
- SSID = None
|
||||
- try:
|
||||
- SSID = subprocess.check_output(["iwgetid", "-r"]).strip()
|
||||
- except subprocess.CalledProcessError:
|
||||
- # If there is no connection subprocess throws a 'CalledProcessError'
|
||||
- pass
|
||||
- return SSID
|
||||
-
|
||||
- @staticmethod
|
||||
- def is_connected_to_wifi():
|
||||
- return BalenaWifiSetupPlugin.get_wifi_ssid() is not None
|
||||
-
|
||||
- def launch_wifi_setup(self):
|
||||
- if not self.in_setup:
|
||||
- self.bus.emit(Message("ovos.wifi.setup.started"))
|
||||
- self.stop_setup()
|
||||
+
|
||||
+ # WIFI Plugin Registeration and Activation Specific Events
|
||||
+ self.bus.on("ovos.phal.wifi.plugin.stop.setup.event", self.handle_stop_setup)
|
||||
+ self.bus.on("ovos.phal.wifi.plugin.client.registered", self.handle_registered)
|
||||
+ self.bus.on("ovos.phal.wifi.plugin.client.deregistered", self.handle_deregistered)
|
||||
+ self.bus.on("ovos.phal.wifi.plugin.client.registration.failure", self.handle_registration_failure)
|
||||
+
|
||||
+ # Try Register the Client with WIFI Plugin on Startup
|
||||
+ self.register_client()
|
||||
+
|
||||
+ # Wifi Plugin Registeration Handling
|
||||
+ def register_client(self):
|
||||
+ self.bus.emit(Message("ovos.phal.wifi.plugin.register.client", {
|
||||
+ "client": self.name,
|
||||
+ "type": "Remote",
|
||||
+ "display_text": "On Mobile Setup",
|
||||
+ "has_gui": True,
|
||||
+ "requires_input": False
|
||||
+ }))
|
||||
+
|
||||
+ def handle_registered(self, message=None):
|
||||
+ get_client = message.data.get("client", "")
|
||||
+ if get_client == self.name:
|
||||
+ get_id = message.data.get("id", "")
|
||||
+ self.client_id = get_id
|
||||
+ self.registered = True
|
||||
+ self.bus.on(f"ovos.phal.wifi.plugin.activate.{self.client_id}", self.handle_activate_client_request)
|
||||
+ self.bus.on(f"ovos.phal.wifi.plugin.deactivate.{self.client_id}", self.handle_deactivate_client_request)
|
||||
+ LOG.info(f"Client Registered with WIFI Plugin: {self.client_id}")
|
||||
+
|
||||
+ def handle_deregistered(self, message=None):
|
||||
+ self.registered = False
|
||||
+ self.bus.remove(f"ovos.phal.wifi.plugin.activate.{self.client_id}", self.handle_active_client_request)
|
||||
+ self.bus.remove(f"ovos.phal.wifi.plugin.deactivate.{self.client_id}", self.handle_deactivate_client_request)
|
||||
+ self.client_id = None
|
||||
+
|
||||
+ def handle_registration_failure(self, message=None):
|
||||
+ if not self.registered:
|
||||
+ error = message.data.get("error", "")
|
||||
+ LOG.info(f"Registration Failure: {error}")
|
||||
+ # Try to Register the Client with WIFI Plugin Again
|
||||
+ self.register_client()
|
||||
+
|
||||
+ def handle_activate_client_request(self, message=None):
|
||||
+ LOG.info("Balena Wifi Plugin Activated")
|
||||
+ self.client_active = True
|
||||
+ self.display_network_setup()
|
||||
+
|
||||
+ def handle_deactivate_client_request(self, message=None):
|
||||
+ LOG.info("Balena Wifi Plugin Deactivated")
|
||||
+ self.cleanup_wifi_process()
|
||||
+ self.client_active = False
|
||||
+ self.gui.release()
|
||||
+
|
||||
+ def request_deactivate(self, message=None):
|
||||
+ self.bus.emit(Message("ovos.phal.wifi.plugin.remove.active.client", {
|
||||
+ "client": "ovos-PHAL-plugin-balena-wifi"}))
|
||||
+ LOG.info("Balena Wifi Plugin Deactivation Requested")
|
||||
+
|
||||
+ def display_network_setup(self):
|
||||
+ LOG.info("Balena Wifi In Network Setup")
|
||||
+ if self.in_setup:
|
||||
+ # Always start with a clean slate
|
||||
+ self.cleanup_wifi_process()
|
||||
+
|
||||
self.in_setup = True
|
||||
+
|
||||
self.wifi_process = pexpect.spawn(
|
||||
self.wifi_command.format(ssid=self.ssid)
|
||||
)
|
||||
@@ -180,24 +176,16 @@ def launch_wifi_setup(self):
|
||||
except Exception as e:
|
||||
LOG.exception(e)
|
||||
break
|
||||
- self.stop_setup()
|
||||
+ self.handle_stop_setup()
|
||||
+
|
||||
if restart:
|
||||
# handle bugs in balena, sometimes it fails to come back up
|
||||
# seems to happen on
|
||||
# Error: Getting access points failed
|
||||
- self.launch_wifi_setup()
|
||||
+ self.display_network_setup()
|
||||
elif self.debug:
|
||||
self.speak_dialog("debug_end_setup")
|
||||
|
||||
- # bus events
|
||||
- def handle_internet_connected(self, message=None):
|
||||
- """System came online later after booting."""
|
||||
- self.enclosure.mouth_reset()
|
||||
- # sync clock as soon as we have internet
|
||||
- self.bus.emit(Message("system.ntp.sync"))
|
||||
- self.stop_setup() # just in case
|
||||
- self.gui.release()
|
||||
-
|
||||
# GUI events
|
||||
def prompt_to_join_ap(self, message=None):
|
||||
"""Provide instructions for setting up wifi."""
|
||||
@@ -215,18 +203,11 @@ def prompt_to_select_network(self, message=None):
|
||||
|
||||
def report_setup_complete(self, message=None):
|
||||
"""Wifi setup complete, network is connected."""
|
||||
- # once first connected to internet increase time between checks
|
||||
- self.connected = True
|
||||
- self.time_between_checks = self.timeout_after_internet
|
||||
- # stop watchdog on internet connection
|
||||
- if self.stop_on_internet:
|
||||
- self.monitoring = False
|
||||
self.manage_setup_display("setup-completed", "status")
|
||||
# allow GUI to linger around for a bit, will block the wifi setup loop
|
||||
sleep(5)
|
||||
- self.bus.emit(Message("ovos.wifi.setup.completed"))
|
||||
- # pairing skill should take over now
|
||||
- self.gui.release()
|
||||
+ self.client_active = False
|
||||
+ self.request_deactivate()
|
||||
|
||||
def report_setup_failed(self, message=None):
|
||||
"""Wifi setup failed"""
|
||||
@@ -234,6 +215,8 @@ def report_setup_failed(self, message=None):
|
||||
self.speak_dialog("debug_wifi_error")
|
||||
# allow GUI to linger around for a bit, will block the wifi setup loop
|
||||
sleep(2)
|
||||
+ self.in_setup = False
|
||||
+ self.display_network_setup()
|
||||
|
||||
def manage_setup_display(self, state, page_type):
|
||||
self.gui.clear()
|
||||
@@ -268,7 +251,8 @@ def manage_setup_display(self, state, page_type):
|
||||
self.gui.show_page(page, override_animations=True)
|
||||
|
||||
# cleanup
|
||||
- def stop_setup(self):
|
||||
+ def cleanup_wifi_process(self):
|
||||
+ self.in_setup = False
|
||||
if self.wifi_process is not None:
|
||||
try:
|
||||
if self.wifi_process.isalive():
|
||||
@@ -289,13 +273,14 @@ def stop_setup(self):
|
||||
LOG.debug('wifi setup exited gracefully.')
|
||||
except Exception as e:
|
||||
LOG.exception(e)
|
||||
- self.wifi_process = None
|
||||
- self.in_setup = False
|
||||
-
|
||||
+ else:
|
||||
+ return
|
||||
+
|
||||
+ def handle_stop_setup(self, message=None):
|
||||
+ self.request_deactivate()
|
||||
+
|
||||
def shutdown(self):
|
||||
- self.monitoring = False
|
||||
- self.bus.remove("mycroft.internet.connected", self.handle_internet_connected)
|
||||
- self.stop_setup()
|
||||
+ self.handle_stop_setup()
|
||||
super().shutdown()
|
||||
|
||||
# speech
|
|
@ -1 +1 @@
|
|||
sha256 ae6eac2706f1dc5d8f6a0305a7e9ec8b2e6ff0b92238510bc89fd82435e04f29 python-ovos-phal-plugin-balena-wifi-f523bb4582bb01c90a7cec273feb49e578551057.tar.gz
|
||||
sha256 aa430274440e92b0a4e71db2b14c7d051f20fdb1d991e57ec1d5b5db8d2026dd python-ovos-phal-plugin-balena-wifi-356a05051e8475b3f75a8df833bf4801cd678412.tar.gz
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#
|
||||
################################################################################
|
||||
|
||||
PYTHON_OVOS_PHAL_PLUGIN_BALENA_WIFI_VERSION = f523bb4582bb01c90a7cec273feb49e578551057
|
||||
PYTHON_OVOS_PHAL_PLUGIN_BALENA_WIFI_VERSION = 356a05051e8475b3f75a8df833bf4801cd678412
|
||||
PYTHON_OVOS_PHAL_PLUGIN_BALENA_WIFI_SITE = $(call github,OpenVoiceOS,ovos-PHAL-plugin-balena-wifi,$(PYTHON_OVOS_PHAL_PLUGIN_BALENA_WIFI_VERSION))
|
||||
PYTHON_OVOS_PHAL_PLUGIN_BALENA_WIFI_SETUP_TYPE = setuptools
|
||||
PYTHON_OVOS_PHAL_PLUGIN_BALENA_WIFI_LICENSE_FILES = LICENSE
|
||||
|
|
|
@ -1 +1 @@
|
|||
sha256 5d14c38351894a5a367031b47b83a04a5d2675f513a252cdb8c1e358fcaa9bca python-ovos-phal-plugin-gui-network-client-c35ca8e510f3f0576db637222b15c34fe9997ba3.tar.gz
|
||||
sha256 9457537c79c3234e6fb2f23407bf353e5bfd67fbac0aecc0c54d6d29636dc1e4 python-ovos-phal-plugin-gui-network-client-3231ab353f7a8d94d9f2b98350ea938de958afa0.tar.gz
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#
|
||||
################################################################################
|
||||
|
||||
PYTHON_OVOS_PHAL_PLUGIN_GUI_NETWORK_CLIENT_VERSION = c35ca8e510f3f0576db637222b15c34fe9997ba3
|
||||
PYTHON_OVOS_PHAL_PLUGIN_GUI_NETWORK_CLIENT_VERSION = 3231ab353f7a8d94d9f2b98350ea938de958afa0
|
||||
PYTHON_OVOS_PHAL_PLUGIN_GUI_NETWORK_CLIENT_SITE = $(call github,OpenVoiceOS,ovos-PHAL-plugin-gui-network-client,$(PYTHON_OVOS_PHAL_PLUGIN_GUI_NETWORK_CLIENT_VERSION))
|
||||
PYTHON_OVOS_PHAL_PLUGIN_GUI_NETWORK_CLIENT_SETUP_TYPE = setuptools
|
||||
PYTHON_OVOS_PHAL_PLUGIN_GUI_NETWORK_CLIENT_LICENSE_FILES = LICENSE
|
||||
|
|
|
@ -1 +1 @@
|
|||
sha256 8c0d7a1633e3f671422c655c97624f71a7e9bbbc7e56827e5c262263a0e8a4d4 python-ovos-phal-plugin-wifi-setup-ffb458dc689a638a1f2fc76928bc4771e33d1a9f.tar.gz
|
||||
sha256 18c1b21c65c135aaa0c2d817767f9412976a79a3f70528e47b0fa9daefcd8453 python-ovos-phal-plugin-wifi-setup-39f957dc050d5a110bd7384cec3c0d87e8bf0740.tar.gz
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#
|
||||
################################################################################
|
||||
|
||||
PYTHON_OVOS_PHAL_PLUGIN_WIFI_SETUP_VERSION = ffb458dc689a638a1f2fc76928bc4771e33d1a9f
|
||||
PYTHON_OVOS_PHAL_PLUGIN_WIFI_SETUP_VERSION = 39f957dc050d5a110bd7384cec3c0d87e8bf0740
|
||||
PYTHON_OVOS_PHAL_PLUGIN_WIFI_SETUP_SITE = $(call github,OpenVoiceOS,ovos-PHAL-plugin-wifi-setup,$(PYTHON_OVOS_PHAL_PLUGIN_WIFI_SETUP_VERSION))
|
||||
PYTHON_OVOS_PHAL_PLUGIN_WIFI_SETUP_SETUP_TYPE = setuptools
|
||||
PYTHON_OVOS_PHAL_PLUGIN_WIFI_SETUP_LICENSE_FILES = LICENSE
|
||||
|
|
|
@ -1 +1 @@
|
|||
sha256 c700f599936b658bc3c0131c1913d19d8d1b7b36578eb07a4f3783c9c14ffc78 python-ovos-utils-c5300d0ed4b66faa64c2c10504baef22b78cf7a4.tar.gz
|
||||
sha256 89f8be304808afd359b48f73d7008da9868c998568b870110a403e2248535d74 python-ovos-utils-670d4580938338e609047447d3ecfee180635070.tar.gz
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#
|
||||
################################################################################
|
||||
|
||||
PYTHON_OVOS_UTILS_VERSION = c5300d0ed4b66faa64c2c10504baef22b78cf7a4
|
||||
PYTHON_OVOS_UTILS_VERSION = 670d4580938338e609047447d3ecfee180635070
|
||||
PYTHON_OVOS_UTILS_SITE = $(call github,OpenVoiceOS,ovos_utils,$(PYTHON_OVOS_UTILS_VERSION))
|
||||
PYTHON_OVOS_UTILS_SETUP_TYPE = setuptools
|
||||
PYTHON_OVOS_UTILS_LICENSE_FILES = LICENSE
|
||||
|
|
Loading…
Reference in New Issue