// ============================================================================= // test_web_server.cpp – Phase 7: WebServer Verifikation // Projekt: MQTT-Display LaserCutter // // Testet: // GET / – Statusseite im Browser // GET /config – Konfigurationsformular laden + Werte aendern // POST /config – Werte in NVS speichern, nach Neustart pruefen // POST /reset – Gesamtzeit zuruecksetzen per Browser-Button // GET /update – ElegantOTA erreichbar (Firmware-Upload) // // Hardware: // - Taste GPIO 4 (als Laser-Signal-Simulator) // - BOOT-Taste GPIO 0 (3 s = Gesamtzeit loeschen) // // Verwendung: // 1. Flashen: pio run -e test-web --target upload // 2. Monitor: pio device monitor -e test-web // 3. IP-Adresse aus Serial Monitor ablesen // 4. Browser: http:/// // -> Statusseite mit Session, Gesamtzeit, MQTT-Status // 5. Browser: http:///config // -> Formular: Broker, Port, User, PW, Gratiszeit, Polaritaet aendern // -> Nach Speichern: NVS pruefen (Neustart + Serial) // 6. "Gesamtzeit loeschen"-Button auf Statusseite testen // 7. Browser: http:///update -> ElegantOTA-Seite erreichbar // ============================================================================= #include #include "config.h" #include "settings.h" #include "wifi_connector.h" #include "display_manager.h" #include "laser_tracker.h" #include "mqtt_client.h" #include "web_server.h" // BOOT-Taste static const int BOOT_BTN = 0; static uint32_t bootPressMs = 0; // Status-Druck alle 10 Sekunden static uint32_t lastStatusMs = 0; void setup() { Serial.begin(SERIAL_BAUD_RATE); delay(500); settings.begin(); LOG_I("TEST-WEB", "=== Phase 7 WebServer Test gestartet ==="); settings.printToSerial(); display.begin(); display.showWifiError(false); display.showMqttError(false); display.showLaserTime(0.0f); display.showIdle(); laserTracker.begin(); wifiConnector.begin(); wifiConnector.printToSerial(); mqttClient.begin(); webServer.begin(); pinMode(BOOT_BTN, INPUT); LOG_I("TEST-WEB", "Setup abgeschlossen"); LOG_I("TEST-WEB", "Browser: http://%s/", WiFi.localIP().toString().c_str()); } void loop() { laserTracker.loop(); wifiConnector.loop(); mqttClient.loop(); // MQTT: Session-Publish nur wenn Netto-Zeit vorhanden (kein GRATIS-only) if (laserTracker.consumeSessionEnd()) { int lastSession = laserTracker.getLastSessionSeconds(); if (lastSession > 0) { mqttClient.publishSession(lastSession, settings.get().gratisSeconds); } } // Display display.showLaserTime((float)laserTracker.getAllSessionsSumMinutes()); int countdown = laserTracker.getCountdownRemaining(); if (countdown > 0) { display.showCountdown(countdown); // GRATIS } else if (laserTracker.isActive()) { display.showSessionRing(laserTracker.getRunningSessionSeconds() % 60); // NET_COUNTING } else { display.showIdle(); // INACTIVE } display.update(); // BOOT-Taste (GPIO 0): 3 s halten -> Gesamtzeit loeschen if (digitalRead(BOOT_BTN) == LOW) { if (bootPressMs == 0) bootPressMs = millis(); if (millis() - bootPressMs >= 3000) { LOG_I("TEST-WEB", "BOOT 3s: resetTotal()"); laserTracker.resetTotal(); bootPressMs = 0; } } else { bootPressMs = 0; } // Periodischer Status-Druck if (millis() - lastStatusMs >= 10000) { lastStatusMs = millis(); LOG_I("TEST-WEB", "--- Status (10s-Tick) ---"); LOG_I("TEST-WEB", "Session: %d min | Total: %.2f min | MQTT: %s", laserTracker.getAllSessionsSumMinutes(), laserTracker.getTotalMinutes(), mqttClient.isConnected() ? "verbunden" : "getrennt"); LOG_I("TEST-WEB", "URL: http://%s/", WiFi.localIP().toString().c_str()); } delay(50); }