diff --git a/src/controllers/settings.py b/src/controllers/settings.py index 0b327ca..43de919 100644 --- a/src/controllers/settings.py +++ b/src/controllers/settings.py @@ -13,51 +13,6 @@ async def get_settings(request): # trigger MicroPython's "dict update sequence has wrong length" quirk. return json.dumps(settings), 200, {'Content-Type': 'application/json'} -@controller.get('/wifi/station') -async def get_station_status(request): - """Get WiFi station connection status.""" - status = wifi.get_sta_status() - if status: - return json.dumps(status), 200, {'Content-Type': 'application/json'} - return json.dumps({"error": "Failed to get station status"}), 500 - -@controller.post('/wifi/station') -async def connect_station(request): - """Connect to WiFi station with credentials.""" - try: - data = request.json - ssid = data.get('ssid') - password = data.get('password', '') - ip = data.get('ip') - gateway = data.get('gateway') - - if not ssid: - return json.dumps({"error": "SSID is required"}), 400 - - # Save credentials to settings - settings['wifi_station_ssid'] = ssid - settings['wifi_station_password'] = password - if ip: - settings['wifi_station_ip'] = ip - if gateway: - settings['wifi_station_gateway'] = gateway - settings.save() - - # Attempt connection - result = wifi.connect(ssid, password, ip, gateway) - if result: - return json.dumps({ - "message": "Connected successfully", - "ip": result[0], - "netmask": result[1], - "gateway": result[2], - "dns": result[3] if len(result) > 3 else None - }), 200, {'Content-Type': 'application/json'} - else: - return json.dumps({"error": "Failed to connect"}), 400 - except Exception as e: - return json.dumps({"error": str(e)}), 500 - @controller.get('/wifi/ap') async def get_ap_config(request): """Get Access Point configuration.""" @@ -106,15 +61,6 @@ async def configure_ap(request): except Exception as e: return json.dumps({"error": str(e)}), 500 -@controller.get('/wifi/station/credentials') -async def get_station_credentials(request): - """Get saved WiFi station credentials (without password).""" - return json.dumps({ - "ssid": settings.get('wifi_station_ssid', ''), - "ip": settings.get('wifi_station_ip', ''), - "gateway": settings.get('wifi_station_gateway', '') - }), 200, {'Content-Type': 'application/json'} - @controller.put('/settings') async def update_settings(request): """Update general settings.""" diff --git a/src/main.py b/src/main.py index 39409ff..0eca195 100644 --- a/src/main.py +++ b/src/main.py @@ -9,7 +9,6 @@ from microdot.session import Session from settings import Settings import aioespnow -import network import controllers.preset as preset import controllers.profile as profile import controllers.group as group @@ -27,9 +26,6 @@ async def main(port=80): print(settings) print("Starting") - sta = network.WLAN(network.STA_IF) - sta.active(True) - # Initialize ESPNow singleton (config + peers) esp = ESPNow() diff --git a/src/static/help.js b/src/static/help.js index 9656ed3..ce3e1ad 100644 --- a/src/static/help.js +++ b/src/static/help.js @@ -80,44 +80,6 @@ document.addEventListener('DOMContentLoaded', () => { } } - async function loadStationStatus() { - try { - const response = await fetch('/settings/wifi/station'); - const status = await response.json(); - const statusEl = document.getElementById('station-status'); - if (!statusEl) return; - if (status.connected) { - statusEl.innerHTML = ` -
SSID: ${status.ssid || 'N/A'}
-IP Address: ${status.ip || 'N/A'}
-Gateway: ${status.gateway || 'N/A'}
-Netmask: ${status.netmask || 'N/A'}
-DNS: ${status.dns || 'N/A'}
- `; - } else { - statusEl.innerHTML = ` -Not connected to any WiFi network
- `; - } - } catch (error) { - console.error('Error loading station status:', error); - } - } - - async function loadStationCredentials() { - try { - const response = await fetch('/settings/wifi/station/credentials'); - const creds = await response.json(); - if (creds.ssid) document.getElementById('station-ssid').value = creds.ssid; - if (creds.ip) document.getElementById('station-ip').value = creds.ip; - if (creds.gateway) document.getElementById('station-gateway').value = creds.gateway; - } catch (error) { - console.error('Error loading station credentials:', error); - } - } - async function loadAPStatus() { try { const response = await fetch('/settings/wifi/ap'); @@ -149,8 +111,6 @@ document.addEventListener('DOMContentLoaded', () => { settingsModal.classList.add('active'); // Load current WiFi status/config when opening loadDeviceSettings(); - loadStationStatus(); - loadStationCredentials(); loadAPStatus(); }); } @@ -169,45 +129,6 @@ document.addEventListener('DOMContentLoaded', () => { }); } - const stationForm = document.getElementById('station-form'); - if (stationForm) { - stationForm.addEventListener('submit', async (e) => { - e.preventDefault(); - const ssid = (document.getElementById('station-ssid').value || '').trim(); - if (!ssid) { - showSettingsMessage('SSID is required', 'error'); - return; - } - const formData = { - ssid, - password: document.getElementById('station-password').value || '', - ip: (document.getElementById('station-ip').value || '').trim() || null, - gateway: (document.getElementById('station-gateway').value || '').trim() || null, - }; - try { - const response = await fetch('/settings/wifi/station', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(formData), - }); - let result = {}; - try { - result = await response.json(); - } catch (_) { - result = { error: response.status === 400 ? 'Bad request (check SSID and connection)' : 'Request failed' }; - } - if (response.ok) { - showSettingsMessage('WiFi station connected successfully!', 'success'); - setTimeout(loadStationStatus, 1000); - } else { - showSettingsMessage(`Error: ${result.error || 'Failed to connect'}`, 'error'); - } - } catch (error) { - showSettingsMessage(`Error: ${error.message}`, 'error'); - } - }); - } - const deviceForm = document.getElementById('device-form'); if (deviceForm) { deviceForm.addEventListener('submit', async (e) => { diff --git a/src/templates/index.html b/src/templates/index.html index faf0248..8bafe34 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -250,7 +250,7 @@Loading...
-Configure WiFi and device settings
+Configure WiFi Access Point settings
Loading...
-SSID: ${status.ssid || 'N/A'}
-IP Address: ${status.ip || 'N/A'}
-Gateway: ${status.gateway || 'N/A'}
-Netmask: ${status.netmask || 'N/A'}
-DNS: ${status.dns || 'N/A'}
- `; - } else { - statusEl.innerHTML = ` -Not connected to any WiFi network
- `; - } - } catch (error) { - console.error('Error loading station status:', error); - } - } - - // Load saved station credentials - async function loadStationCredentials() { - try { - const response = await fetch('/settings/wifi/station/credentials'); - const creds = await response.json(); - - if (creds.ssid) document.getElementById('station-ssid').value = creds.ssid; - if (creds.ip) document.getElementById('station-ip').value = creds.ip; - if (creds.gateway) document.getElementById('station-gateway').value = creds.gateway; - } catch (error) { - console.error('Error loading station credentials:', error); - } - } - // Load AP status and config async function loadAPStatus() { try { @@ -334,39 +251,6 @@ } } - // Station form submission - document.getElementById('station-form').addEventListener('submit', async (e) => { - e.preventDefault(); - - const formData = { - ssid: document.getElementById('station-ssid').value, - password: document.getElementById('station-password').value, - ip: document.getElementById('station-ip').value || null, - gateway: document.getElementById('station-gateway').value || null - }; - - try { - const response = await fetch('/settings/wifi/station', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify(formData) - }); - - const result = await response.json(); - - if (response.ok) { - showMessage('WiFi station connected successfully!', 'success'); - setTimeout(loadStationStatus, 1000); - } else { - showMessage(`Error: ${result.error || 'Failed to connect'}`, 'error'); - } - } catch (error) { - showMessage(`Error: ${error.message}`, 'error'); - } - }); - // AP form submission document.getElementById('ap-form').addEventListener('submit', async (e) => { e.preventDefault(); @@ -415,15 +299,10 @@ }); // Load all data on page load - loadStationStatus(); - loadStationCredentials(); loadAPStatus(); // Refresh status every 10 seconds - setInterval(() => { - loadStationStatus(); - loadAPStatus(); - }, 10000); + setInterval(loadAPStatus, 10000);