MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / get_current_ssid

Method get_current_ssid

wifi_manager.py:1433–1468  ·  view source on GitHub ↗

Get the current connected SSID

(self)

Source from the content-addressed store, hash-verified

1431 self.shared_data.lan_ip = ethernet_iface.get('ip_address') if ethernet_iface else None
1432 self.shared_data.network_connected = True
1433 self.shared_data.wifi_connected = False
1434 return True
1435
1436 # No LAN; fall back to Wi-Fi detection
1437 self.shared_data.lan_connected = False
1438 self.shared_data.lan_interface = None
1439 self.shared_data.lan_ip = None
1440
1441 wifi_connected = self.check_wifi_connection()
1442 self.last_connection_type = 'wifi' if wifi_connected else None
1443 self.shared_data.network_connected = wifi_connected
1444 self.shared_data.wifi_connected = wifi_connected
1445 return wifi_connected
1446 except Exception as exc:
1447 self.logger.error(f"Error checking network connectivity: {exc}")
1448 self.shared_data.network_connected = False
1449 return False
1450
1451 def check_wifi_connection(self):
1452 """Check if Wi-Fi is connected using multiple methods"""
1453 try:
1454 self._ensure_wifi_interfaces_up()
1455 # Method 1: Check using nmcli for active wireless connections
1456 result = subprocess.run(['nmcli', '-t', '-f', 'ACTIVE,TYPE', 'con', 'show'],
1457 capture_output=True, text=True, timeout=30)
1458 if result.returncode == 0:
1459 for line in result.stdout.strip().split('\n'):
1460 if line and 'yes:802-11-wireless' in line:
1461 # Double-check with device status
1462 dev_result = subprocess.run(['nmcli', '-t', '-f', 'DEVICE,STATE', 'dev', 'status'],
1463 capture_output=True, text=True, timeout=5)
1464 if dev_result.returncode == 0 and 'connected' in dev_result.stdout:
1465 return True
1466
1467 # Methods 2 and 3 name an interface, so they must name the one
1468 # actually carrying the connection. With a dongle that is wlan1,
1469 # while the built-in is busy hosting the AP — checking the built-in
1470 # would report "not connected" for a perfectly good uplink.
1471 client_iface = self._client_wifi_interface()

Callers 9

stopMethod · 0.95
disconnect_wifiMethod · 0.95
get_statusMethod · 0.95
get_current_wifi_ssidFunction · 0.80

Calls 2

errorMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected