format FS if begin() fail, to avoid setting lost when FS is not mounted
add of timeout parameter
This commit is contained in:
1 parent
6795475e03
commit
e20339857e
3 files changed
+10
-6
No files matched your search
@@ -62,6 +62,7 @@
|
|||||||
#define WifiManager_password "your_password" //this is going to be the WPA2-PSK password for the initial setup access point
|
#define WifiManager_password "your_password" //this is going to be the WPA2-PSK password for the initial setup access point
|
||||||
#define WifiManager_ssid "OpenMQTTGateway" //this is the network name of the initial setup access point
|
#define WifiManager_ssid "OpenMQTTGateway" //this is the network name of the initial setup access point
|
||||||
#define WifiManager_ConfigPortalTimeOut 120
|
#define WifiManager_ConfigPortalTimeOut 120
|
||||||
|
#define WifiManager_TimeOut 5
|
||||||
|
|
||||||
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
|
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
|
||||||
//MQTT Parameters definition
|
//MQTT Parameters definition
|
||||||
|
|||||||
+8
-6
@@ -662,6 +662,12 @@ void setup_wifimanager(bool reset_settings){
|
|||||||
|
|
||||||
if (SPIFFS.begin()) {
|
if (SPIFFS.begin()) {
|
||||||
trc(F("mounted file system"));
|
trc(F("mounted file system"));
|
||||||
|
}else{
|
||||||
|
trc(F("failed to mount FS -> formating"));
|
||||||
|
SPIFFS.format();
|
||||||
|
if(SPIFFS.begin())
|
||||||
|
trc(F("mounted file system after formating"));
|
||||||
|
}
|
||||||
if (SPIFFS.exists("/config.json")) {
|
if (SPIFFS.exists("/config.json")) {
|
||||||
//file exists, reading and loading
|
//file exists, reading and loading
|
||||||
trc(F("reading config file"));
|
trc(F("reading config file"));
|
||||||
@@ -671,27 +677,21 @@ void setup_wifimanager(bool reset_settings){
|
|||||||
size_t size = configFile.size();
|
size_t size = configFile.size();
|
||||||
// Allocate a buffer to store contents of the file.
|
// Allocate a buffer to store contents of the file.
|
||||||
std::unique_ptr<char[]> buf(new char[size]);
|
std::unique_ptr<char[]> buf(new char[size]);
|
||||||
|
|
||||||
configFile.readBytes(buf.get(), size);
|
configFile.readBytes(buf.get(), size);
|
||||||
DynamicJsonBuffer jsonBuffer;
|
DynamicJsonBuffer jsonBuffer;
|
||||||
JsonObject& json = jsonBuffer.parseObject(buf.get());
|
JsonObject& json = jsonBuffer.parseObject(buf.get());
|
||||||
json.printTo(Serial);
|
json.printTo(Serial);
|
||||||
if (json.success()) {
|
if (json.success()) {
|
||||||
trc(F("\nparsed json"));
|
trc(F("\nparsed json"));
|
||||||
|
|
||||||
strcpy(mqtt_server, json["mqtt_server"]);
|
strcpy(mqtt_server, json["mqtt_server"]);
|
||||||
strcpy(mqtt_port, json["mqtt_port"]);
|
strcpy(mqtt_port, json["mqtt_port"]);
|
||||||
strcpy(mqtt_user, json["mqtt_user"]);
|
strcpy(mqtt_user, json["mqtt_user"]);
|
||||||
strcpy(mqtt_pass, json["mqtt_pass"]);
|
strcpy(mqtt_pass, json["mqtt_pass"]);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
trc(F("failed to load json config"));
|
trc(F("failed to load json config"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
trc(F("failed to mount FS"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// The extra parameters to be configured (can be either global or just in the setup)
|
// The extra parameters to be configured (can be either global or just in the setup)
|
||||||
// After connecting, parameter.getValue() will get you the configured value
|
// After connecting, parameter.getValue() will get you the configured value
|
||||||
@@ -704,6 +704,8 @@ void setup_wifimanager(bool reset_settings){
|
|||||||
//WiFiManager
|
//WiFiManager
|
||||||
//Local intialization. Once its business is done, there is no need to keep it around
|
//Local intialization. Once its business is done, there is no need to keep it around
|
||||||
WiFiManager wifiManager;
|
WiFiManager wifiManager;
|
||||||
|
|
||||||
|
wifiManager.setConnectTimeout(WifiManager_TimeOut);
|
||||||
//Set timeout before going to portal
|
//Set timeout before going to portal
|
||||||
wifiManager.setConfigPortalTimeout(WifiManager_ConfigPortalTimeOut);
|
wifiManager.setConfigPortalTimeout(WifiManager_ConfigPortalTimeOut);
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,7 @@
|
|||||||
#define WifiManager_password "your_password" //this is going to be the WPA2-PSK password for the initial setup access point
|
#define WifiManager_password "your_password" //this is going to be the WPA2-PSK password for the initial setup access point
|
||||||
#define WifiManager_ssid "OpenMQTTGateway" //this is the network name of the initial setup access point
|
#define WifiManager_ssid "OpenMQTTGateway" //this is the network name of the initial setup access point
|
||||||
#define WifiManager_ConfigPortalTimeOut 120
|
#define WifiManager_ConfigPortalTimeOut 120
|
||||||
|
#define WifiManager_TimeOut 5
|
||||||
|
|
||||||
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
|
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
|
||||||
//MQTT Parameters definition
|
//MQTT Parameters definition
|
||||||
|
|||||||
Reference in new issue
Block a user