feature/netman #1
33
src/netman.h
33
src/netman.h
@ -7,7 +7,7 @@
|
||||
#include <map>
|
||||
|
||||
// Constants for the HTML pages and config file
|
||||
static const String beginHtml = "<!DOCTYPE html><html lang=\"en\"><head><title>AP Configure</title><style></style></head><body><table><tbody><tr><td><label for=\"ssid\">SSID</label></td><td><input id=\"ssid\"/></td></tr><tr><td><label for=\"pass\" >Password</label></td><td><input id=\"pass\" type=\"password\"/></td></tr><tr><td><button onclick=\"location.href = '/add?ssid=' + escape(document.getElementById('ssid').value) + '&pass=' + escape(document.getElementById('pass').value);\">Add</button></td></tr></tbody></table><br/><table><tbody>";
|
||||
static const String beginHtml = "<!DOCTYPE html><html lang='en'><head><title>SmartCube Configure</title><style>body{font-family:Arial,sans-serif;background-color:#f4f4f9;color:#333;display:flex;align-items:center;justify-content:center;height:100vh;margin:0}.container{width:300px;padding:20px;background:#fff;border-radius:10px;box-shadow:0 4px 8px rgba(0,0,0,0.2)}h2{margin-top:0;text-align:center;color:#0073e6}label{display:block;margin-bottom:5px;font-weight:bold}input[type='text'],input[type='password']{width:100%;padding:8px;margin-bottom:15px;border:1px solid #ccc;border-radius:4px}button{width:100%;padding:10px;background-color:#0073e6;color:white;border:none;border-radius:4px;cursor:pointer;font-size:16px}button:hover{background-color:#005bb5}table{width:100%;margin-top:20px}td{padding:5px;text-align:left}</style></head><body><div class='container'><h2>Configure AP</h2><table><tbody><tr><td><label for='ssid'>SSID</label></td><td><input id='ssid' type='text' placeholder='Enter SSID'/></td></tr><tr><td><label for='pass'>Password</label></td><td><input id='pass' type='password' placeholder='Enter Password'/></td></tr><tr><td colspan='2'><button onclick=\"location.href = '/add?ssid=' + encodeURIComponent(document.getElementById('ssid').value) + '&pass=' + encodeURIComponent(document.getElementById('pass').value);\">Add Network</button></td></tr></tbody></table><br/><table><tbody>";
|
||||
static const String endHtml = "</tbody></table></body></html>";
|
||||
static const String configFile = "/netman";
|
||||
|
||||
@ -104,19 +104,48 @@ bool netman::tryConnect() {
|
||||
}
|
||||
|
||||
// Attempt to connect to a specific SSID with timeout
|
||||
// Attempt to connect to a specific SSID with timeout and dot animation
|
||||
bool netman::tryConnectToSsid(const char* ssid, const char* pass) {
|
||||
WiFi.begin(ssid, pass);
|
||||
unsigned long start = millis();
|
||||
|
||||
display.println("Connecting to " + String(ssid) + "...");
|
||||
// Clear display and set initial message
|
||||
display.clearDisplay();
|
||||
display.setCursor(0, 0);
|
||||
display.println("Connecting to SSID:");
|
||||
display.println(String(ssid));
|
||||
display.display();
|
||||
|
||||
int dotCount = 0;
|
||||
while (millis() - start < connectionTimeout) {
|
||||
delay(500);
|
||||
|
||||
// Check WiFi connection status
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
// Success message
|
||||
display.clearDisplay();
|
||||
display.setCursor(0, 0);
|
||||
display.println("Connected!");
|
||||
display.display();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Animate by adding dots up to three, then reset
|
||||
display.setCursor(0, 20);
|
||||
display.print("Connecting");
|
||||
for (int i = 0; i < dotCount; i++) {
|
||||
display.print(".");
|
||||
}
|
||||
display.display();
|
||||
|
||||
dotCount = (dotCount + 1) % 4; // Cycle dot count from 0 to 3
|
||||
}
|
||||
|
||||
// Connection failed
|
||||
display.clearDisplay();
|
||||
display.setCursor(0, 0);
|
||||
display.println("Connection failed.");
|
||||
display.display();
|
||||
WiFi.disconnect();
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user