diff --git a/data/logo.png b/data/logo.png new file mode 100644 index 0000000..5d18f7d Binary files /dev/null and b/data/logo.png differ diff --git a/platformio.ini b/platformio.ini index 7b1ecd1..3b247a9 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,12 +8,37 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html +[env] + [env:esp32-s3-devkitc-1] platform = espressif32 board = esp32-s3-devkitc-1 framework = arduino monitor_speed = 115200 +board_build.filesystem = littlefs lib_deps = tzapu/WiFiManager@^2.0.17 bblanchon/ArduinoJson@^7.0.0 knolleary/PubSubClient@^2.8 + +[env:esp32dev] +board = esp32dev +framework = arduino +platform = espressif32 +monitor_speed = 115200 +board_build.filesystem = littlefs +lib_deps = + tzapu/WiFiManager@^2.0.17 + bblanchon/ArduinoJson@^7.4.3 + knolleary/PubSubClient@^2.8 + +[env:esp32-C3-devkitm-1] +board = esp32-c3-devkitm-1 +framework = arduino +platform = espressif32 +monitor_speed = 115200 +board_build.filesystem = littlefs +lib_deps = + tzapu/WiFiManager@^2.0.17 + bblanchon/ArduinoJson@^7.4.3 + knolleary/PubSubClient@^2.8 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index b1f17bd..33232d1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -41,12 +41,12 @@ struct AuthConfig { char pass[32] = ""; }; -static char hostname[32] = HOSTNAME_DEFAULT; +static char hostname[64] = HOSTNAME_DEFAULT; static int meterCount = 0; static MeterConfig meters[MAX_METERS] = {}; static MqttConfig mqttCfg; static AuthConfig authCfg; -static WiFiManagerParameter hostnameParam("hostname", "Device hostname", hostname, 32); +static WiFiManagerParameter hostnameParam("hostname", "Device hostname", hostname, 63); static WebServer server(80); static WiFiClient wifiClient; static PubSubClient mqttClient(wifiClient); @@ -413,6 +413,21 @@ static bool requireAuth() { // Web handlers // --------------------------------------------------------------------------- +static void handleLogo() { + File f = LittleFS.open("/logo.png", "r"); + if (!f) { server.send(404, "text/plain", "Not found"); return; } + server.streamFile(f, "image/png"); + f.close(); +} + +static void handleReset() { + if (!requireAuth()) { Serial.println("[HTTP] POST /reset -> 401"); return; } + Serial.println("[HTTP] POST /reset -> restarting"); + server.send(200, "text/plain", "Restarting..."); + delay(200); + ESP.restart(); +} + static void handleRoot() { if (!requireAuth()) { Serial.println("[HTTP] GET / -> 401"); return; } Serial.println("[HTTP] GET /"); @@ -515,7 +530,7 @@ static void handleRoot() { html += ".count-row{display:flex;gap:12px;align-items:flex-end;margin-bottom:20px}.count-row > div{flex:1}"; html += ".count-row label{margin-bottom:4px}"; html += ".btn{width:100%;margin-top:8px;padding:12px;background:#4361ee;color:#fff;border:none;border-radius:8px;font-size:15px;font-weight:600;cursor:pointer;transition:background .2s}"; - html += ".btn:hover{background:#3651d4}.mac{font-size:12px;color:#999;text-align:center;margin-top:20px}"; + html += ".btn:hover{background:#3651d4}.btn-danger{background:#dc2626}.btn-danger:hover{background:#b91c1c}.mac{font-size:12px;color:#999;text-align:center;margin-top:20px}"; html += ".tgl-lbl{margin-bottom:0!important;line-height:18px}.switch{position:relative;display:inline-block;width:32px;height:18px;margin-left:auto;flex-shrink:0}fieldset .row label.switch{width:32px}"; html += ".switch input{opacity:0;width:0;height:0}.slid{position:absolute;cursor:pointer;top:0;left:0;right:0;bottom:0;background:#ccc;border-radius:18px;transition:.3s}"; html += ".slid::before{content:\"\";position:absolute;height:14px;width:14px;left:2px;top:2px;background:#fff;border-radius:50%;transition:.3s;box-shadow:0 1px 3px rgba(0,0,0,.2)}"; @@ -532,6 +547,8 @@ html += ".switch input:checked+.slid{background:#4361ee}.switch input:checked+.s html += authSection; html += mqttSection; html += ""; + html += "
"; html += "