diff --git a/enviro/__init__.py b/enviro/__init__.py index 82044e9..ae07ecf 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -186,12 +186,9 @@ def reconnect_wifi(ssid, password, country): wlan = network.WLAN(network.STA_IF) - def wlog(message): #replace with enviro logging - print(f"[WLAN] {message}") - def dump_status(): status = wlan.status() - wlog(f"active: {1 if wlan.active() else 0}, status: {status} ({status_names[status]})") + logging.info(f"> active: {1 if wlan.active() else 0}, status: {status} ({status_names[status]})") return status # Return True on expected status, exception on error status (negative) and False on timeout @@ -212,33 +209,33 @@ def wait_status(expected_status, *, timeout=10, tick_sleep=0.5): # Print MAC mac = ubinascii.hexlify(wlan.config('mac'),':').decode() - wlog("MAC: " + mac) + logging.info("> MAC: " + mac) # Disconnect when necessary status = dump_status() if status >= CYW43_LINK_JOIN and status <= CYW43_LINK_UP: - wlog("Disconnecting...") + logging.info("> Disconnecting...") wlan.disconnect() try: wait_status(CYW43_LINK_DOWN) except Exception as x: raise Exception(f"Failed to disconnect: {x}") - wlog("Ready for connection!") + logging.info("> Ready for connection!") # Connect to our AP - wlog(f"Connecting to SSID {ssid} (password: {password})...") + logging.info(f"> Connecting to SSID {ssid} (password: {password})...") wlan.connect(ssid, password) try: wait_status(CYW43_LINK_UP) except Exception as x: raise Exception(f"Failed to connect to SSID {ssid} (password: {password}): {x}") - wlog("Connected successfully!") + logging.info("> Connected successfully!") ip, subnet, gateway, dns = wlan.ifconfig() - wlog(f"IP: {ip}, Subnet: {subnet}, Gateway: {gateway}, DNS: {dns}") + logging.info(f"> IP: {ip}, Subnet: {subnet}, Gateway: {gateway}, DNS: {dns}") elapsed_ms = time.ticks_ms() - start_ms - wlog(f"Elapsed: {elapsed_ms}ms") + logging.info(f"> Elapsed: {elapsed_ms}ms") return elapsed_ms def connect_to_wifi(): @@ -519,7 +516,7 @@ def upload_readings(): finally: # Disconnect wifi import network - print("[WLAN] Disconnecting after upload") + logging.info("> Disconnecting wireless after upload") wlan = network.WLAN(network.STA_IF) wlan.active(True) wlan.disconnect()