Commit aeacb867 authored by Eric Duminil's avatar Eric Duminil
Browse files

No need to ask for password twice

parent 80e074fa
Pipeline #5816 passed with stage
in 2 minutes and 41 seconds
......@@ -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);
}
......
......@@ -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;
......
......@@ -5,6 +5,7 @@ namespace wifi {
extern char local_ip[16];
void defineCommands();
bool connected();
bool isAccessPoint();
void tryConnection();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment