#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Standalone WiFi/GPIO isolation test. This script intentionally does not import any project module. It only tests MaixPy WiFi startup with optional A23/A26 GPIO initialization. """ import time from maix import gpio, network, pinmap GREEN_PIN = "A26" GREEN_GPIO = "GPIOA26" RED_PIN = "A23" RED_GPIO = "GPIOA23" # Run this file directly from the official MaixPy tool. # Change only TEST_MODE between runs: none -> a26 -> a23 -> both. TEST_MODE = "none" WIFI_SSID = "sheling4b02-5G" WIFI_PASSWORD = "Aa12345678" WIFI_TIMEOUT_S = 20 def init_gpio(mode): outputs = [] if mode in ("a26", "both"): pinmap.set_pin_function(GREEN_PIN, GREEN_GPIO) green = gpio.GPIO(GREEN_GPIO, gpio.Mode.OUT) green.value(1) outputs.append((GREEN_GPIO, green)) print("GPIOA26 initialized HIGH") if mode in ("a23", "both"): pinmap.set_pin_function(RED_PIN, RED_GPIO) red = gpio.GPIO(RED_GPIO, gpio.Mode.OUT) red.value(1) outputs.append((RED_GPIO, red)) print("GPIOA23 initialized HIGH") return outputs def connect_wifi(ssid, password, timeout_s): print("Starting MaixPy WiFi connection...") wifi = network.wifi.Wifi() result = wifi.connect(ssid, password, wait=True, timeout=timeout_s) print("WiFi connect result:", result) try: print("WiFi connected:", wifi.is_connected()) print("WiFi IP:", wifi.get_ip()) except Exception as exc: print("WiFi status query failed:", exc) return result def main(): mode = TEST_MODE.lower() if mode not in ("none", "a26", "a23", "both"): print("TEST_MODE must be none, a26, a23, or both") return 1 ssid = WIFI_SSID password = WIFI_PASSWORD timeout_s = WIFI_TIMEOUT_S print("=== Standalone WiFi/GPIO isolation ===") print("mode:", mode) print("ssid:", ssid) outputs = [] try: outputs = init_gpio(mode) time.sleep(1) connect_wifi(ssid, password, timeout_s) return 0 except Exception as exc: print("TEST FAILED:", repr(exc)) return 1 finally: for gpio_name, output in outputs: try: output.value(0) print(gpio_name, "LOW") except Exception as exc: print(gpio_name, "cleanup failed:", exc) if __name__ == "__main__": raise SystemExit(main())