diff --git a/ampel-firmware/ampel-firmware.ino b/ampel-firmware/ampel-firmware.ino index 6ad91545f9fcb52695c396c73a50b5a779db4ef6..da1f42b8c78d6fb50d58f998f0fbfafb86fd2dba 100644 --- a/ampel-firmware/ampel-firmware.ino +++ b/ampel-firmware/ampel-firmware.ino @@ -181,6 +181,7 @@ void wifiConnected() { } void wifiFailed() { + // Ampel will go back to Access Point mode for AP_TIMEOUT seconds, and try connection again after Serial.print(F("WiFi - Could not connect to ")); Serial.println(config::selected_ssid()); led_effects::showKITTWheel(color::red); diff --git a/ampel-firmware/config.public.h b/ampel-firmware/config.public.h index 8839e26c706b4d6687e25fa66ac70c384797e3bc..6285ba6ddf93ed4128ce5548b71647d75bb80e27 100644 --- a/ampel-firmware/config.public.h +++ b/ampel-firmware/config.public.h @@ -44,7 +44,12 @@ // SSID and PASSWORD need to be defined, but can be empty. # define WIFI_SSID "" # define WIFI_PASSWORD "" +// How long should the Ampel try to connect to WIFI_SSID? # define WIFI_TIMEOUT 30 // [s] +// If the Ampel cannot connect to WIFI_SSID, it will start an Access Point for ACCESS_POINT_TIMEOUT seconds. +// If someone connects to this Access Point, the Ampel will stay in this mode until everybody logs out. +// If nobody connects to the Access Point before ACCESS_POINT_TIMEOUT seconds, the Ampel will try to connect WIFI_SSID again. +# define ACCESS_POINT_TIMEOUT 30 // [s] /** * Sensor diff --git a/ampel-firmware/web_config.cpp b/ampel-firmware/web_config.cpp index f1443550efb924359e15ea8ea2ed9bc9851b05ef..f8aac2db84a997e62c7b4b562500ef146b1d92fc 100644 --- a/ampel-firmware/web_config.cpp +++ b/ampel-firmware/web_config.cpp @@ -2,6 +2,9 @@ #define STRING_LEN 33 // Should be enough for ip, addresses, passwords... +#define STRING(x) #x +#define STRINGIFY(x) STRING(x) // Allows to call STRINGIFY(SOME_MACRO) and convert the value of SOME_MACRO to string + #include "config.h" #ifndef AMPEL_PASSWORD # error Missing config.h file. Please copy config.public.h to config.h. @@ -158,7 +161,6 @@ namespace web_config { void setWifiFailCallback(void (*fail_function)()) { std::function<WifiAuthInfo* ()> fail_and_return_null = [fail_function]() { fail_function(); - iotWebConf->forceApMode(true); // Will stay in AP. return nullptr; }; iotWebConf->setWifiConnectionFailedHandler(fail_and_return_null); @@ -172,10 +174,13 @@ namespace web_config { iotWebConf->getThingNameParameter()->label = "Ampel name"; iotWebConf->getApPasswordParameter()->label = "Ampel password (user : 'admin')"; + iotWebConf->getApTimeoutParameter()->label = "Access Point timeout"; + iotWebConf->getApTimeoutParameter()->visible = true; iotWebConf->getApPasswordParameter()->defaultValue = AMPEL_PASSWORD; iotWebConf->getWifiSsidParameter()->defaultValue = WIFI_SSID; iotWebConf->getWifiPasswordParameter()->defaultValue = WIFI_PASSWORD; + iotWebConf->getApTimeoutParameter()->defaultValue = STRINGIFY(ACCESS_POINT_TIMEOUT); // Defined as number in config.h but stored as string in webconf. co2Params.addItem(×tepParam); co2Params.addItem(&temperatureOffsetParam);