Athena: get ipv4 addr

This commit is contained in:
MoreTorque
2024-11-29 03:36:24 -06:00
committed by MoreTore
parent 90954ec9a1
commit e55566291a
3 changed files with 37 additions and 0 deletions
+11
View File
@@ -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
+3
View File
@@ -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
+23
View File
@@ -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()