Skip to main content
Manage WiFi network connections on Lager Boxes.

Import

from lager.wifi import (
    scan_wifi,
    connect_to_wifi,
    get_wifi_status,
    Wifi,
    toggle_internet_access,
    set_internet_access
)

Functions

FunctionDescription
scan_wifi()Scan for available networks
connect_to_wifi()Connect to a WiFi network
get_wifi_status()Get connection status
toggle_internet_access()Toggle internet access for a device
set_internet_access()Set internet access state for a device

Classes

ClassDescription
WifiRouter management (Asus router parental control)

Function Reference

scan_wifi(interface='wlan0')

Scan for available WiFi networks.
from lager.wifi import scan_wifi

result = scan_wifi()
networks = result.get('access_points', [])
for net in networks:
    print(f"{net['ssid']}: {net['strength']}%")
Parameters:
ParameterTypeDescription
interfacestrWireless interface (default: ‘wlan0’)
Returns: dict with keys:
  • access_points - List of network dicts, each containing:
    • ssid - Network name
    • address - Access point MAC address
    • strength - Signal strength as percentage (0-100)
    • security - Security type (‘Open’ or ‘Secured’)
  • error - Error message (only present if scan failed)

connect_to_wifi(ssid, password, interface='wlan0')

Connect to a WiFi network.
from lager.wifi import connect_to_wifi

result = connect_to_wifi(ssid='MyNetwork', password='secret123')
if result['success']:
    print(f"Connected: {result['message']}")
else:
    print(f"Failed: {result['error']}")
Parameters:
ParameterTypeDescription
ssidstrNetwork name
passwordstrNetwork password (empty string for open networks)
interfacestrWireless interface (default: ‘wlan0’)
Returns: dict with keys:
  • success - Boolean indicating connection success
  • message - Success message (when success is True)
  • error - Error message (when success is False)
  • method - Connection method used (‘nmcli’ or ‘wpa_supplicant’)
  • interface - Interface used for connection
  • dhcp_status - DHCP status (‘requested’ or ‘failed’, optional)

get_wifi_status()

Get current WiFi connection status for all interfaces.
from lager.wifi import get_wifi_status

status = get_wifi_status()
for interface_name, info in status.items():
    print(f"{interface_name}: {info['state']} - {info['ssid']}")
Returns: dict keyed by interface name, each value containing:
  • interface - Interface name (e.g., ‘wlan0’)
  • ssid - Connected network name or ‘Not Connected’
  • state - Connection state (‘Connected’, ‘Disconnected’, or ‘Available’)

toggle_internet_access()

Toggle internet access for a device via router parental controls.
from lager.wifi import toggle_internet_access

toggle_internet_access()

set_internet_access(enabled)

Set internet access state for a device.
from lager.wifi import set_internet_access

set_internet_access(True)   # Enable internet
set_internet_access(False)  # Disable internet
Parameters:
ParameterTypeDescription
enabledboolTrue to enable, False to disable

Wifi Class (Router Management)

The Wifi class provides router management for Asus routers with parental control features.
from lager.wifi import Wifi

router = Wifi()
# Router management operations

Examples

Scan and Connect

from lager.wifi import scan_wifi, connect_to_wifi, get_wifi_status
import time

# Scan for networks
result = scan_wifi()
networks = result.get('access_points', [])

# Find target network
for net in networks:
    if net['ssid'] == 'TestNetwork':
        print(f"Found: {net['strength']}% signal")
        break

# Connect
connect_result = connect_to_wifi(ssid='TestNetwork', password='password123')

if connect_result['success']:
    print(f"Connection successful: {connect_result['message']}")
else:
    print(f"Connection failed: {connect_result['error']}")

# Wait for connection to stabilize
time.sleep(5)

# Verify status
status = get_wifi_status()
for iface, info in status.items():
    if info['state'] == 'Connected':
        print(f"Connected on {iface} to {info['ssid']}")

Network Verification Test

from lager.wifi import scan_wifi

def verify_network_visible(expected_ssid):
    result = scan_wifi()
    networks = result.get('access_points', [])
    ssids = [n['ssid'] for n in networks]

    if expected_ssid in ssids:
        print(f"PASS: {expected_ssid} is visible")
        return True
    else:
        print(f"FAIL: {expected_ssid} not found")
        return False

Signal Strength Test

from lager.wifi import scan_wifi

def check_signal_strength(ssid, min_strength=50):
    """Check if signal strength meets minimum threshold (0-100%)"""
    result = scan_wifi()
    networks = result.get('access_points', [])

    for net in networks:
        if net['ssid'] == ssid:
            strength = net['strength']
            if strength >= min_strength:
                print(f"PASS: {ssid} signal {strength}%")
                return True
            else:
                print(f"FAIL: {ssid} signal {strength}% below {min_strength}%")
                return False

    print(f"FAIL: {ssid} not found")
    return False

Connection Test

from lager.wifi import connect_to_wifi, get_wifi_status
import time

def test_wifi_connection(ssid, password):
    result = connect_to_wifi(ssid=ssid, password=password)

    if not result['success']:
        print(f"FAIL: Connection error - {result['error']}")
        return False

    time.sleep(5)

    status = get_wifi_status()
    for iface, info in status.items():
        if info['state'] == 'Connected' and info['ssid'] == ssid:
            print(f"PASS: Connected to {ssid} on {iface}")
            return True

    print(f"FAIL: Not connected to {ssid}")
    return False

Hardware Requirements

RequirementDescription
WiFi HardwareUSB adapter or built-in
PermissionsRoot/sudo access required
Supported SecurityWPA2, WPA3, Open

Notes

  • Lager Box must have WiFi hardware
  • Root/sudo access required for most operations
  • WPA2/WPA3 networks supported
  • Open networks require empty password string ('')
  • Interface defaults to ‘wlan0’
  • get_wifi_status() takes no parameters and returns all interfaces
  • Router management requires Asus router with parental control