Skip to content

Commit

Permalink
Adjust wlog to logging used elsewhere
Browse files Browse the repository at this point in the history
  • Loading branch information
sjefferson99 authored and Stephen Jefferson committed Jan 16, 2024
1 parent 7a665b8 commit bf21ecd
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions enviro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit bf21ecd

Please sign in to comment.