Add flair

This commit is contained in:
Tomislav Kopić 2024-11-05 13:05:31 +01:00
parent 56ed7e4b19
commit 20a6714bef
No known key found for this signature in database
GPG Key ID: 77B232765688AEA7

View File

@ -7,7 +7,7 @@
#include <map> #include <map>
// Constants for the HTML pages and config file // 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 endHtml = "</tbody></table></body></html>";
static const String configFile = "/netman"; 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
// Attempt to connect to a specific SSID with timeout and dot animation
bool netman::tryConnectToSsid(const char* ssid, const char* pass) { bool netman::tryConnectToSsid(const char* ssid, const char* pass) {
WiFi.begin(ssid, pass); WiFi.begin(ssid, pass);
unsigned long start = millis(); 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) { while (millis() - start < connectionTimeout) {
delay(500); delay(500);
// Check WiFi connection status
if (WiFi.status() == WL_CONNECTED) { if (WiFi.status() == WL_CONNECTED) {
// Success message
display.clearDisplay();
display.setCursor(0, 0);
display.println("Connected!"); display.println("Connected!");
display.display();
return true; 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.println("Connection failed.");
display.display();
WiFi.disconnect(); WiFi.disconnect();
return false; return false;
} }