diff --git a/CO2-Ampel_Plus/CO2-Ampel_Plus.ino b/CO2-Ampel_Plus/CO2-Ampel_Plus.ino index d095313..0afe8fa 100644 --- a/CO2-Ampel_Plus/CO2-Ampel_Plus.ino +++ b/CO2-Ampel_Plus/CO2-Ampel_Plus.ino @@ -40,8 +40,11 @@ Button modeButton(BUTTON_PIN); int wifi_reconnect_attemps = WIFI_RECONNECT_ATTEMPTS; void setup() { + + + #if DEBUG_LOG > 0 - while (!Serial) { + while (!Serial) { ; // wait for serial port to connect. } #endif @@ -77,7 +80,9 @@ void setup() { * Factory Reset when button is pressed while reset */ if (!config_is_initialized() || modeButton.isPressed()) { +#if DEBUG_LOG > 0 Serial.println("Loading factory defaults"); +#endif led_off(); led_set_color(LED_RED); led_update(); @@ -85,8 +90,10 @@ void setup() { config_set_factory_defaults(); led_off(); } +#if DEBUG_LOG > 0 Serial.println("Setup complete!"); Serial.println("------------------------"); +#endif } void loop() { @@ -100,18 +107,25 @@ void loop() { switch (wifi_state) { case WIFI_MODE_AP_INIT: // Create an Access Point +#if DEBUG_LOG > 0 Serial.println("Creating Access Point"); +#endif wifi_ap_create(); wifi_state = WIFI_MODE_AP_LISTEN; +#if DEBUG_LOG > 0 Serial.println("------------------------"); +#endif break; case WIFI_MODE_WPA_CONNECT: // Connect to WiFi device_config_t cfg = config_get_values(); + +#if DEBUG_LOG > 0 Serial.print("Connecting to SSID "); Serial.print(cfg.wifi_ssid); Serial.println(" Wifi"); +#endif if (strlen(cfg.wifi_ssid) != 0) { if (wifi_wpa_connect() == WL_CONNECTED) { wifi_state = WIFI_MODE_WPA_LISTEN; @@ -122,21 +136,22 @@ void loop() { Serial.println("No WiFi SSID Configured."); wifi_state = WIFI_MODE_NOT_CONECTED; } +#if DEBUG_LOG > 0 Serial.println("------------------------"); Serial.println("Start measurement"); Serial.println(""); +#endif break; } - - if (!wifi_is_connected()) { wifi_state = WIFI_MODE_WPA_CONNECT; } + mqtt_loop(); - - wifi_handle_client(); sensor_handler(); sensor_handle_brightness(); + wifi_handle_client(); + } diff --git a/CO2-Ampel_Plus/Config.h b/CO2-Ampel_Plus/Config.h index b9cd2ce..7caf11f 100644 --- a/CO2-Ampel_Plus/Config.h +++ b/CO2-Ampel_Plus/Config.h @@ -1,7 +1,7 @@ #ifndef CONFIG_H #define CONFIG_H -#define VERSION "v3.0.0" +#define VERSION "v3.0.1" #define DEBUG_LOG 0 // 1 = Enable debug log @@ -103,15 +103,13 @@ #define WIFI_MODE_NOT_CONECTED 87 #define WIFI_RECONNECT_ATTEMPTS 10 -// Required for WiFiWebServer lib -#define USE_WIFI_NINA false -#define USE_WIFI101 true -#define DEBUG_WIFI_WEBSERVER_PORT Serial // WIFI_LOGLEVEL below 4 causes EMPTY HTTP RESPONSE // see: https://github.com/khoih-prog/WiFiWebServer/issues/3 + +#define DEBUG_WIFI_WEBSERVER_PORT Serial #define _WIFI_LOGLEVEL_ 4 -#define _WIFININA_LOGLEVEL_ 3 +#define _WIFININA_LOGLEVEL_ 0 #define USE_WIFI_NINA false #define USE_WIFI101 true diff --git a/CO2-Ampel_Plus/HTMLStatic.h b/CO2-Ampel_Plus/HTMLStatic.h index 5e3f577..503bcb0 100644 --- a/CO2-Ampel_Plus/HTMLStatic.h +++ b/CO2-Ampel_Plus/HTMLStatic.h @@ -26,13 +26,20 @@ const char settings_header_html[] PROGMEM = R"=====(