Update main application and dependencies
- Update main.py and run_web.py for local development - Update microdot session handling - Update wifi utility
This commit is contained in:
@@ -2,9 +2,11 @@ import network
|
||||
from time import sleep
|
||||
|
||||
def connect(ssid, password, ip, gateway):
|
||||
if ssid is None or password is None:
|
||||
print("Missing ssid or password")
|
||||
if ssid is None:
|
||||
print("Missing ssid")
|
||||
return None
|
||||
if password is None:
|
||||
password = ''
|
||||
try:
|
||||
sta_if = network.WLAN(network.STA_IF)
|
||||
if ip is not None and gateway is not None:
|
||||
@@ -23,12 +25,15 @@ def connect(ssid, password, ip, gateway):
|
||||
return None
|
||||
|
||||
|
||||
def ap(ssid, password):
|
||||
def ap(ssid, password, channel=None):
|
||||
ap_if = network.WLAN(network.AP_IF)
|
||||
ap_mac = ap_if.config('mac')
|
||||
print(ssid)
|
||||
ap_if.active(True)
|
||||
ap_if.config(essid=ssid, password=password)
|
||||
if channel is not None:
|
||||
ap_if.config(essid=ssid, password=password, channel=channel)
|
||||
else:
|
||||
ap_if.config(essid=ssid, password=password)
|
||||
ap_if.active(False)
|
||||
ap_if.active(True)
|
||||
print(ap_if.ifconfig())
|
||||
@@ -36,3 +41,60 @@ def ap(ssid, password):
|
||||
def get_mac():
|
||||
ap_if = network.WLAN(network.AP_IF)
|
||||
return ap_if.config('mac')
|
||||
|
||||
def get_ap_config():
|
||||
"""Get current AP configuration."""
|
||||
try:
|
||||
ap_if = network.WLAN(network.AP_IF)
|
||||
if ap_if.active():
|
||||
config = ap_if.ifconfig()
|
||||
return {
|
||||
'ssid': ap_if.config('essid'),
|
||||
'channel': ap_if.config('channel'),
|
||||
'ip': config[0] if config else None,
|
||||
'active': True
|
||||
}
|
||||
return {
|
||||
'ssid': None,
|
||||
'channel': None,
|
||||
'ip': None,
|
||||
'active': False
|
||||
}
|
||||
except Exception as e:
|
||||
print(f"Error getting AP config: {e}")
|
||||
return None
|
||||
|
||||
def get_sta_status():
|
||||
"""Get current station connection status."""
|
||||
try:
|
||||
sta_if = network.WLAN(network.STA_IF)
|
||||
if sta_if.active():
|
||||
if sta_if.isconnected():
|
||||
config = sta_if.ifconfig()
|
||||
return {
|
||||
'connected': True,
|
||||
'ssid': sta_if.config('essid'),
|
||||
'ip': config[0] if config else None,
|
||||
'gateway': config[2] if len(config) > 2 else None,
|
||||
'netmask': config[1] if len(config) > 1 else None,
|
||||
'dns': config[3] if len(config) > 3 else None
|
||||
}
|
||||
return {
|
||||
'connected': False,
|
||||
'ssid': None,
|
||||
'ip': None,
|
||||
'gateway': None,
|
||||
'netmask': None,
|
||||
'dns': None
|
||||
}
|
||||
return {
|
||||
'connected': False,
|
||||
'ssid': None,
|
||||
'ip': None,
|
||||
'gateway': None,
|
||||
'netmask': None,
|
||||
'dns': None
|
||||
}
|
||||
except Exception as e:
|
||||
print(f"Error getting STA status: {e}")
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user