diff --git a/ampel-firmware/web_server.cpp b/ampel-firmware/web_server.cpp index 2c632da9693852479fb2ab5c842999ebd79d2087..7a9ef8e93dbf5d39ca7ee831fc5bb92e158269a9 100644 --- a/ampel-firmware/web_server.cpp +++ b/ampel-firmware/web_server.cpp @@ -169,9 +169,13 @@ namespace web_server { web_config::http.on("/delete_csv", HTTP_POST, handleDeleteCSV); } - // Allow access if http_user or http_password are empty, or if provided credentials match + /* + * Allow access if Ampel is in access point mode, + * if http_user or http_password are empty, + * or if provided credentials match + */ bool shouldBeAllowed() { - return strcmp(config::http_user, "") == 0 || strcmp(config::ap_password(), "") == 0 + return wifi::isAccessPoint() || strcmp(config::http_user, "") == 0 || strcmp(config::ap_password(), "") == 0 || web_config::http.authenticate(config::http_user, config::ap_password()); } @@ -196,8 +200,8 @@ namespace web_server { snprintf_P(content, sizeof(content), header_template, sensor::co2, config::ampel_name(), wifi::local_ip, csv_writer::filename); - Serial.print(F("INFO - Header size : ")); - Serial.print(strlen(content)); + Serial.print(F("INFO - Header size : ")); + Serial.print(strlen(content)); web_config::http.setContentLength(CONTENT_LENGTH_UNKNOWN); web_config::http.send_P(200, PSTR("text/html"), content); @@ -210,19 +214,20 @@ namespace web_server { lorawan::connected ? "Yes" : "No", config::lorawan_frequency_plan, lorawan::last_transmission, config::lorawan_sending_interval, #endif - config::temperature_offset, config::auto_calibrate_sensor ? "Yes" : "No", config::ampel_name(), config::ampel_name(), - wifi::local_ip, wifi::local_ip, ampel.macAddress, ESP.getFreeHeap(), esp_get_max_free_block_size(), - esp_get_heap_fragmentation(), ampel.max_loop_duration, ampel.board, ampel.sensorId, ampel.version, dd, hh, mm, ss); + config::temperature_offset, config::auto_calibrate_sensor ? "Yes" : "No", config::ampel_name(), + config::ampel_name(), wifi::local_ip, wifi::local_ip, ampel.macAddress, ESP.getFreeHeap(), + esp_get_max_free_block_size(), esp_get_heap_fragmentation(), ampel.max_loop_duration, ampel.board, + ampel.sensorId, ampel.version, dd, hh, mm, ss); - Serial.print(F(" - Body size : ")); - Serial.print(strlen(content)); + Serial.print(F(" - Body size : ")); + Serial.print(strlen(content)); web_config::http.sendContent(content); // Script snprintf_P(content, sizeof(content), script_template, csv_writer::filename, config::ampel_name()); - Serial.print(F(" - Script size : ")); - Serial.println(strlen(content)); + Serial.print(F(" - Script size : ")); + Serial.println(strlen(content)); web_config::http.sendContent(content); } diff --git a/ampel-firmware/wifi_util.cpp b/ampel-firmware/wifi_util.cpp index 2252e6ff951f978be983031e5a3c06b8df29ea03..da4ca65c64e16412e63c84348f530fb0cd72596f 100644 --- a/ampel-firmware/wifi_util.cpp +++ b/ampel-firmware/wifi_util.cpp @@ -19,6 +19,10 @@ namespace wifi { return WiFi.status() == WL_CONNECTED; } + bool isAccessPoint() { + return WiFi.getMode() == WIFI_AP; + } + /* * Connection attempt, called in blocking mode by setup(). This way, LED effects can be shown * without needing callbacks, but only during wifi_timeout seconds. @@ -31,7 +35,7 @@ namespace wifi { void tryConnection() { for (int i = 0; i <= config::wifi_timeout + 5; i++) { web_config::update(); - if (WiFi.getMode() == WIFI_AP){ + if (isAccessPoint()) { led_effects::alert(0x1cff68); } else if (connected()) { break; diff --git a/ampel-firmware/wifi_util.h b/ampel-firmware/wifi_util.h index 5b9f719f3af618f0091c08c19fc828e748ffd9ff..67323687b7a25926800eb85edade77fa841b470c 100644 --- a/ampel-firmware/wifi_util.h +++ b/ampel-firmware/wifi_util.h @@ -5,6 +5,7 @@ namespace wifi { extern char local_ip[16]; void defineCommands(); bool connected(); + bool isAccessPoint(); void tryConnection(); }