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
+33
-29
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
|
||||||
|
|||||||
+30
-28
@@ -462,7 +462,7 @@ void setup()
|
|||||||
{
|
{
|
||||||
//Launch serial for debugging purposes
|
//Launch serial for debugging purposes
|
||||||
Serial.begin(SERIAL_BAUD);
|
Serial.begin(SERIAL_BAUD);
|
||||||
|
|
||||||
#if defined(ESP8266) || defined(ESP32)
|
#if defined(ESP8266) || defined(ESP32)
|
||||||
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
@@ -662,35 +662,35 @@ void setup_wifimanager(bool reset_settings){
|
|||||||
|
|
||||||
if (SPIFFS.begin()) {
|
if (SPIFFS.begin()) {
|
||||||
trc(F("mounted file system"));
|
trc(F("mounted file system"));
|
||||||
if (SPIFFS.exists("/config.json")) {
|
}else{
|
||||||
//file exists, reading and loading
|
trc(F("failed to mount FS -> formating"));
|
||||||
trc(F("reading config file"));
|
SPIFFS.format();
|
||||||
File configFile = SPIFFS.open("/config.json", "r");
|
if(SPIFFS.begin())
|
||||||
if (configFile) {
|
trc(F("mounted file system after formating"));
|
||||||
trc(F("opened config file"));
|
}
|
||||||
size_t size = configFile.size();
|
if (SPIFFS.exists("/config.json")) {
|
||||||
// Allocate a buffer to store contents of the file.
|
//file exists, reading and loading
|
||||||
std::unique_ptr<char[]> buf(new char[size]);
|
trc(F("reading config file"));
|
||||||
|
File configFile = SPIFFS.open("/config.json", "r");
|
||||||
configFile.readBytes(buf.get(), size);
|
if (configFile) {
|
||||||
DynamicJsonBuffer jsonBuffer;
|
trc(F("opened config file"));
|
||||||
JsonObject& json = jsonBuffer.parseObject(buf.get());
|
size_t size = configFile.size();
|
||||||
json.printTo(Serial);
|
// Allocate a buffer to store contents of the file.
|
||||||
if (json.success()) {
|
std::unique_ptr<char[]> buf(new char[size]);
|
||||||
trc(F("\nparsed json"));
|
configFile.readBytes(buf.get(), size);
|
||||||
|
DynamicJsonBuffer jsonBuffer;
|
||||||
strcpy(mqtt_server, json["mqtt_server"]);
|
JsonObject& json = jsonBuffer.parseObject(buf.get());
|
||||||
strcpy(mqtt_port, json["mqtt_port"]);
|
json.printTo(Serial);
|
||||||
strcpy(mqtt_user, json["mqtt_user"]);
|
if (json.success()) {
|
||||||
strcpy(mqtt_pass, json["mqtt_pass"]);
|
trc(F("\nparsed json"));
|
||||||
|
strcpy(mqtt_server, json["mqtt_server"]);
|
||||||
} else {
|
strcpy(mqtt_port, json["mqtt_port"]);
|
||||||
trc(F("failed to load json config"));
|
strcpy(mqtt_user, json["mqtt_user"]);
|
||||||
}
|
strcpy(mqtt_pass, json["mqtt_pass"]);
|
||||||
|
} else {
|
||||||
|
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)
|
||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -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
|
||||||
@@ -254,4 +255,4 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
|||||||
#define TimeBetweenReadingSYS 120000 // time between system readings (like memory)
|
#define TimeBetweenReadingSYS 120000 // time between system readings (like memory)
|
||||||
#define subjectSYStoMQTT Base_Topic Gateway_Name "/SYStoMQTT"
|
#define subjectSYStoMQTT Base_Topic Gateway_Name "/SYStoMQTT"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in new issue
Block a user