implement feature to disable wifi / wifi config portal fallback
This commit is contained in:
2
Config.h
2
Config.h
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define NUKI_HUB_VERSION "8.30"
|
#define NUKI_HUB_VERSION "8.31-pre-1"
|
||||||
|
|
||||||
#define MQTT_QOS_LEVEL 1
|
#define MQTT_QOS_LEVEL 1
|
||||||
#define MQTT_CLEAN_SESSIONS false
|
#define MQTT_CLEAN_SESSIONS false
|
||||||
|
|||||||
@@ -65,6 +65,14 @@ void Network::setupDevice()
|
|||||||
|
|
||||||
if(strcmp(WiFi_fallbackDetect, "wifi_fallback") == 0)
|
if(strcmp(WiFi_fallbackDetect, "wifi_fallback") == 0)
|
||||||
{
|
{
|
||||||
|
if(_preferences->getBool(preference_network_wifi_fallback_disabled))
|
||||||
|
{
|
||||||
|
Log->println(F("Failed to connect to network. Wifi fallback is disable, rebooting."));
|
||||||
|
memset(WiFi_fallbackDetect, 0, sizeof(WiFi_fallbackDetect));
|
||||||
|
sleep(5);
|
||||||
|
restartEsp(RestartReason::NetworkDeviceCriticalFailureNoWifiFallback);
|
||||||
|
}
|
||||||
|
|
||||||
Log->println(F("Switching to WiFi device as fallback."));
|
Log->println(F("Switching to WiFi device as fallback."));
|
||||||
_networkDeviceType = NetworkDeviceType::WiFi;
|
_networkDeviceType = NetworkDeviceType::WiFi;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#define preference_ip_dns_server "dnssrv"
|
#define preference_ip_dns_server "dnssrv"
|
||||||
#define preference_network_hardware "nwhw"
|
#define preference_network_hardware "nwhw"
|
||||||
#define preference_network_hardware_gpio "nwhwdt" // obsolete
|
#define preference_network_hardware_gpio "nwhwdt" // obsolete
|
||||||
|
#define preference_network_wifi_fallback_disabled "nwwififb"
|
||||||
#define preference_rssi_publish_interval "rssipb"
|
#define preference_rssi_publish_interval "rssipb"
|
||||||
#define preference_hostname "hostname"
|
#define preference_hostname "hostname"
|
||||||
#define preference_network_timeout "nettmout"
|
#define preference_network_timeout "nettmout"
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ enum class RestartReason
|
|||||||
ReconfigureWifi,
|
ReconfigureWifi,
|
||||||
ReconfigureLAN8720,
|
ReconfigureLAN8720,
|
||||||
NetworkDeviceCriticalFailure,
|
NetworkDeviceCriticalFailure,
|
||||||
|
NetworkDeviceCriticalFailureNoWifiFallback,
|
||||||
ConfigurationUpdated,
|
ConfigurationUpdated,
|
||||||
GpioConfigurationUpdated,
|
GpioConfigurationUpdated,
|
||||||
RestartTimer,
|
RestartTimer,
|
||||||
@@ -81,6 +82,8 @@ inline static String getRestartReason()
|
|||||||
return "ReconfigureLAN8720";
|
return "ReconfigureLAN8720";
|
||||||
case RestartReason::NetworkDeviceCriticalFailure:
|
case RestartReason::NetworkDeviceCriticalFailure:
|
||||||
return "NetworkDeviceCriticalFailure";
|
return "NetworkDeviceCriticalFailure";
|
||||||
|
case RestartReason::NetworkDeviceCriticalFailureNoWifiFallback:
|
||||||
|
return "NetworkDeviceCriticalFailureNoWifiFallback";
|
||||||
case RestartReason::ConfigurationUpdated:
|
case RestartReason::ConfigurationUpdated:
|
||||||
return "ConfigurationUpdated";
|
return "ConfigurationUpdated";
|
||||||
case RestartReason::GpioConfigurationUpdated:
|
case RestartReason::GpioConfigurationUpdated:
|
||||||
|
|||||||
@@ -325,6 +325,11 @@ bool WebCfgServer::processArgs(String& message)
|
|||||||
_preferences->putInt(preference_network_hardware, value.toInt());
|
_preferences->putInt(preference_network_hardware, value.toInt());
|
||||||
configChanged = true;
|
configChanged = true;
|
||||||
}
|
}
|
||||||
|
else if(key == "NWHWWIFIFB")
|
||||||
|
{
|
||||||
|
_preferences->putBool(preference_network_wifi_fallback_disabled, (value == "1"));
|
||||||
|
configChanged = true;
|
||||||
|
}
|
||||||
else if(key == "RSSI")
|
else if(key == "RSSI")
|
||||||
{
|
{
|
||||||
_preferences->putInt(preference_rssi_publish_interval, value.toInt());
|
_preferences->putInt(preference_rssi_publish_interval, value.toInt());
|
||||||
@@ -763,6 +768,7 @@ void WebCfgServer::buildMqttConfigHtml(String &response)
|
|||||||
printTextarea(response, "MQTTCRT", "MQTT SSL Client Certificate (*, optional)", _preferences->getString(preference_mqtt_crt).c_str(), TLS_CERT_MAX_SIZE, _network->encryptionSupported(), true);
|
printTextarea(response, "MQTTCRT", "MQTT SSL Client Certificate (*, optional)", _preferences->getString(preference_mqtt_crt).c_str(), TLS_CERT_MAX_SIZE, _network->encryptionSupported(), true);
|
||||||
printTextarea(response, "MQTTKEY", "MQTT SSL Client Key (*, optional)", _preferences->getString(preference_mqtt_key).c_str(), TLS_KEY_MAX_SIZE, _network->encryptionSupported(), true);
|
printTextarea(response, "MQTTKEY", "MQTT SSL Client Key (*, optional)", _preferences->getString(preference_mqtt_key).c_str(), TLS_KEY_MAX_SIZE, _network->encryptionSupported(), true);
|
||||||
printDropDown(response, "NWHW", "Network hardware", String(_preferences->getInt(preference_network_hardware)), getNetworkDetectionOptions());
|
printDropDown(response, "NWHW", "Network hardware", String(_preferences->getInt(preference_network_hardware)), getNetworkDetectionOptions());
|
||||||
|
printCheckBox(response, "NWHWWIFIFB", "Disable fallback to Wifi / WiFi config portal", _preferences->getBool(preference_network_wifi_fallback_disabled));
|
||||||
printInputField(response, "RSSI", "RSSI Publish interval (seconds; -1 to disable)", _preferences->getInt(preference_rssi_publish_interval), 6);
|
printInputField(response, "RSSI", "RSSI Publish interval (seconds; -1 to disable)", _preferences->getInt(preference_rssi_publish_interval), 6);
|
||||||
printInputField(response, "NETTIMEOUT", "Network Timeout until restart (seconds; -1 to disable)", _preferences->getInt(preference_network_timeout), 5);
|
printInputField(response, "NETTIMEOUT", "Network Timeout until restart (seconds; -1 to disable)", _preferences->getInt(preference_network_timeout), 5);
|
||||||
printCheckBox(response, "RSTDISC", "Restart on disconnect", _preferences->getBool(preference_restart_on_disconnect));
|
printCheckBox(response, "RSTDISC", "Restart on disconnect", _preferences->getBool(preference_restart_on_disconnect));
|
||||||
|
|||||||
2
main.cpp
2
main.cpp
@@ -138,6 +138,8 @@ bool initPreferences()
|
|||||||
preferences = new Preferences();
|
preferences = new Preferences();
|
||||||
preferences->begin("nukihub", false);
|
preferences->begin("nukihub", false);
|
||||||
|
|
||||||
|
// preferences->putBool(preference_network_wifi_fallback_disabled, false);
|
||||||
|
|
||||||
bool firstStart = !preferences->getBool(preference_started_before);
|
bool firstStart = !preferences->getBool(preference_started_before);
|
||||||
|
|
||||||
if(firstStart)
|
if(firstStart)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ RTC_NOINIT_ATTR char WiFiDevice_reconfdetect[17];
|
|||||||
|
|
||||||
WifiDevice::WifiDevice(const String& hostname, Preferences* preferences, const IPConfiguration* ipConfiguration)
|
WifiDevice::WifiDevice(const String& hostname, Preferences* preferences, const IPConfiguration* ipConfiguration)
|
||||||
: NetworkDevice(hostname, ipConfiguration),
|
: NetworkDevice(hostname, ipConfiguration),
|
||||||
|
_preferences(preferences),
|
||||||
_wm(preferences->getString(preference_cred_user).c_str(), preferences->getString(preference_cred_password).c_str())
|
_wm(preferences->getString(preference_cred_user).c_str(), preferences->getString(preference_cred_password).c_str())
|
||||||
{
|
{
|
||||||
_startAp = strcmp(WiFiDevice_reconfdetect, "reconfigure_wifi") == 0;
|
_startAp = strcmp(WiFiDevice_reconfdetect, "reconfigure_wifi") == 0;
|
||||||
@@ -64,6 +65,7 @@ void WifiDevice::initialize()
|
|||||||
std::vector<const char *> wm_menu;
|
std::vector<const char *> wm_menu;
|
||||||
wm_menu.push_back("wifi");
|
wm_menu.push_back("wifi");
|
||||||
wm_menu.push_back("exit");
|
wm_menu.push_back("exit");
|
||||||
|
_wm.setEnableConfigPortal(_startAp || !_preferences->getBool(preference_network_wifi_fallback_disabled));
|
||||||
// reduced tieout if ESP is set to restart on disconnect
|
// reduced tieout if ESP is set to restart on disconnect
|
||||||
_wm.setConfigPortalTimeout(_restartOnDisconnect ? 60 * 3 : 60 * 30);
|
_wm.setConfigPortalTimeout(_restartOnDisconnect ? 60 * 3 : 60 * 30);
|
||||||
_wm.setShowInfoUpdate(false);
|
_wm.setShowInfoUpdate(false);
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ private:
|
|||||||
WiFiManager _wm;
|
WiFiManager _wm;
|
||||||
espMqttClient* _mqttClient = nullptr;
|
espMqttClient* _mqttClient = nullptr;
|
||||||
espMqttClientSecure* _mqttClientSecure = nullptr;
|
espMqttClientSecure* _mqttClientSecure = nullptr;
|
||||||
|
Preferences* _preferences = nullptr;
|
||||||
|
|
||||||
bool _restartOnDisconnect = false;
|
bool _restartOnDisconnect = false;
|
||||||
bool _startAp = false;
|
bool _startAp = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user