From e55566291a846f3c07d504f708ceffd2c05ac2be Mon Sep 17 00:00:00 2001 From: MoreTorque <104254025+MoreTore@users.noreply.github.com> Date: Fri, 29 Nov 2024 03:36:24 -0600 Subject: [PATCH] Athena: get ipv4 addr --- system/athena/athenad.py | 11 +++++++++++ system/hardware/base.py | 3 +++ system/hardware/tici/hardware.py | 23 +++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/system/athena/athenad.py b/system/athena/athenad.py index d606ec0a0..26a36f423 100755 --- a/system/athena/athenad.py +++ b/system/athena/athenad.py @@ -533,6 +533,17 @@ def getNetworks(): return HARDWARE.get_networks() +@dispatcher.add_method +def getManagerURL(): + ip_addr = HARDWARE.get_ipv4_address() + if ip_addr: + return { + 'url': f"http://{ip_addr}:8082", + } + else: + raise Exception("Network Error") + + @dispatcher.add_method def takeSnapshot() -> str | dict[str, str] | None: from openpilot.system.camerad.snapshot.snapshot import jpeg_write, snapshot diff --git a/system/hardware/base.py b/system/hardware/base.py index 6cdb4a4d6..0bcd62f14 100644 --- a/system/hardware/base.py +++ b/system/hardware/base.py @@ -144,3 +144,6 @@ class HardwareBase(ABC): def get_modem_data_usage(self): return -1, -1 + + def get_ipv4_address(self, interface="wlan0"): + return None \ No newline at end of file diff --git a/system/hardware/tici/hardware.py b/system/hardware/tici/hardware.py index a5dee88b5..eefb4fae9 100644 --- a/system/hardware/tici/hardware.py +++ b/system/hardware/tici/hardware.py @@ -586,6 +586,29 @@ class Tici(HardwareBase): return False return True + def get_ipv4_address(self, interface="wlan0"): + try: + # Run the `ip` command to get interface details + result = subprocess.run( + ["ip", "addr", "show", interface], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + ) + + # Check if the command succeeded + if result.returncode != 0: + return None + + # Parse the output for the IPv4 address + for line in result.stdout.splitlines(): + line = line.strip() + if line.startswith("inet "): # Find the line with 'inet' + return line.split()[1].split('/')[0] # Extract the IP address + except Exception: + pass + return None + if __name__ == "__main__": t = Tici() t.configure_modem()