WiFiManager: Problem to Save on FS
Basic Infos
Hardware
WiFimanager Branch/Release:
- Master
- Development
Esp8266/Esp32:
- [x ] ESP8266
- ESP32
Hardware: ESP-12F,
- ESP01
- [x ] ESP12 E/F/S (nodemcu, wemos, feather)
- Other
ESP Core Version: 2.4.0, staging
- 2.3.0
- 2.4.0
- staging (master/dev)
Description
Cannot save anything on ESP12F. It seems that it fails to mount FS.
mounting FS...
failed to mount FS
Settings in IDE
Module: NodeMcu
Additional libraries:
Sketch is the AutoConnectWithFSParametersAndCustomIP where I`ve changed the IP and gateway.
#include <FS.h> //this needs to be first, or it all crashes and burns...
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson
//define your default values here, if there are different values in config.json, they are overwritten.
char mqtt_server[40];
char mqtt_port[6] = "1883";
char blynk_token[34] = "YOUR_BLYNK_TOKEN";
//flag for saving data
bool shouldSaveConfig = false;
//callback notifying us of the need to save config
void saveConfigCallback () {
Serial.println("Should save config");
shouldSaveConfig = true;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println();
//clean FS, for testing
//SPIFFS.format();
//read configuration from FS json
Serial.println("mounting FS...");
if (SPIFFS.begin()) {
Serial.println("mounted file system");
if (SPIFFS.exists("/config.json")) {
//file exists, reading and loading
Serial.println("reading config file");
File configFile = SPIFFS.open("/config.json", "r");
if (configFile) {
Serial.println("opened config file");
size_t size = configFile.size();
// Allocate a buffer to store contents of the file.
std::unique_ptr<char[]> buf(new char[size]);
configFile.readBytes(buf.get(), size);
DynamicJsonBuffer jsonBuffer;
JsonObject& json = jsonBuffer.parseObject(buf.get());
json.printTo(Serial);
if (json.success()) {
Serial.println("\nparsed json");
strcpy(mqtt_server, json["mqtt_server"]);
strcpy(mqtt_port, json["mqtt_port"]);
strcpy(blynk_token, json["blynk_token"]);
} else {
Serial.println("failed to load json config");
}
configFile.close();
}
}
} else {
Serial.println("failed to mount FS");
}
//end read
// 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
// id/name placeholder/prompt default length
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 6);
WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 32);
//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifiManager;
//set config save notify callback
wifiManager.setSaveConfigCallback(saveConfigCallback);
//set static ip
wifiManager.setSTAStaticIPConfig(IPAddress(192,168,8,88), IPAddress(192,168,8,1), IPAddress(255,255,255,0));
//add all your parameters here
wifiManager.addParameter(&custom_mqtt_server);
wifiManager.addParameter(&custom_mqtt_port);
wifiManager.addParameter(&custom_blynk_token);
//reset settings - for testing
//wifiManager.resetSettings();
//set minimu quality of signal so it ignores AP's under that quality
//defaults to 8%
//wifiManager.setMinimumSignalQuality();
//sets timeout until configuration portal gets turned off
//useful to make it all retry or go to sleep
//in seconds
//wifiManager.setTimeout(120);
//fetches ssid and pass and tries to connect
//if it does not connect it starts an access point with the specified name
//here "AutoConnectAP"
//and goes into a blocking loop awaiting configuration
if (!wifiManager.autoConnect("AutoConnectAP", "password")) {
Serial.println("failed to connect and hit timeout");
delay(3000);
//reset and try again, or maybe put it to deep sleep
ESP.reset();
delay(5000);
}
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
//read updated parameters
strcpy(mqtt_server, custom_mqtt_server.getValue());
strcpy(mqtt_port, custom_mqtt_port.getValue());
strcpy(blynk_token, custom_blynk_token.getValue());
//save the custom parameters to FS
if (shouldSaveConfig) {
Serial.println("saving config");
DynamicJsonBuffer jsonBuffer;
JsonObject& json = jsonBuffer.createObject();
json["mqtt_server"] = mqtt_server;
json["mqtt_port"] = mqtt_port;
json["blynk_token"] = blynk_token;
File configFile = SPIFFS.open("/config.json", "w");
if (!configFile) {
Serial.println("failed to open config file for writing");
}
json.printTo(Serial);
json.printTo(configFile);
configFile.close();
//end save
}
Serial.println("local ip");
Serial.println(WiFi.localIP());
}
void loop() {
// put your main code here, to run repeatedly:
}
Debug Messages
mounting FS…
failed to mount FS
*WM: [3] allocating params bytes: 20
*WM: [2] Added Parameter: server
*WM: [2] Added Parameter: port
*WM: [2] Added Parameter: blynk
*WM: [1] AutoConnect
*WM: [2] Connecting as wifi client…
*WM: [1] STA static IP: 192.168.8.88
*WM: [2] Custom static IP/GW/Subnet/DNS
*WM: [2] Custom STA IP/GW/Subnet
*WM: [1] STA IP set: 192.168.8.88
*WM: [3] WIFI station disconnect
*WM: [1] No saved credentials, skipping wifi
*WM: [2] Connection result: WL_NO_SSID_AVAIL
*WM: [3] lastconxresult: WL_NO_SSID_AVAIL
*WM: [1] AutoConnect: FAILED
*WM: [2] AccessPoint set password is VALID
*WM: [1] password
*WM: [3] WIFI station disconnect
*WM: [3] WiFi station enable
*WM: [2] Disabling STA
*WM: [2] Enabling AP
*WM: [1] StartAP with SSID: AutoConnectAP
*WM: [1] AP IP address: 192.168.4.1
*WM: [3] setupConfigPortal
*WM: [1] Starting Web Portal
*WM: [3] dns server started with ip: 192.168.4.1
*WM: [2] HTTP server started
*WM: [2] WiFi Scan ASYNC started
*WM: [2] Config Portal Running, blocking, waiting for clients…
*WM: [2] NUM CLIENTS: 0
*WM: [2] WiFi Scan ASYNC completed in 2203 ms
*WM: [2] WiFi Scan ASYNC found: 2
*WM: [2] <- HTTP Root
*WM: [3] -> 192.168.4.1
*WM: [3] lastconxresult: WL_CONNECTED
*WM: [2] Scan is cached 17023 ms ago
*WM: [3] -> connectivitycheck.gstatic.com
*WM: [2] <- Request redirected to captive portal
*WM: [3] -> clients3.google.com
*WM: [2] <- Request redirected to captive portal
*WM: [3] -> portal.fb.com
*WM: [2] <- Request redirected to captive portal
*WM: [2] <- HTTP Root
*WM: [3] -> 192.168.4.1
*WM: [3] lastconxresult: WL_CONNECTED
*WM: [2] Scan is cached 19344 ms ago
*WM: [3] -> connect.rom.miui.com
*WM: [2] <- Request redirected to captive portal
*WM: [2] <- HTTP Root
*WM: [3] -> 192.168.4.1
*WM: [3] lastconxresult: WL_CONNECTED
*WM: [2] WiFi Scan ASYNC started
*WM: [3] -> 192.168.4.1
*WM: [2] WiFi Scan ASYNC completed in 2205 ms
*WM: [2] WiFi Scan ASYNC found: 4
*WM: [2] <- HTTP Wifi
*WM: [2] Scan is cached 1036 ms ago
*WM: [1] 4 networks found
*WM: [2] DUP AP: OTWLAN
*WM: [2] AP: -66 OTWLAN
*WM: [2] AP: -66 OTpublic
*WM: [2] AP: -95 NET_2G034B04
*WM: [3] _staShowStaticFields
*WM: [3] lastconxresult: WL_CONNECTED
*WM: [3] Sent config page
*WM: [3] -> connect.rom.miui.com
*WM: [2] <- Request redirected to captive portal
*WM: [3] -> connect.rom.miui.com
*WM: [2] <- Request redirected to captive portal
*WM: [3] -> connect.rom.miui.com
*WM: [2] <- Request redirected to captive portal
*WM: [2] NUM CLIENTS: 1
*WM: [3] -> connect.rom.miui.com
*WM: [2] <- Request redirected to captive portal
*WM: [2] <- HTTP WiFi save
*WM: [3] Method: POST
*WM: [2] Parameters
*WM: [2] --------------------
*WM: [2] server: Teste.xxx.com
*WM: [2] port: 1883
*WM: [2] blynk: YOUR_BLYNK_TOKEN
*WM: [2] --------------------
*WM: [3] static ip: 192.168.8.88
*WM: [3] static gateway: 192.168.8.1
*WM: [3] static netmask: 255.255.255.0
*WM: [3] Sent wifi save page
*WM: [2] process connect
*WM: [2] Connecting as wifi client…
*WM: [1] STA static IP: 192.168.8.88
*WM: [2] Custom static IP/GW/Subnet/DNS
*WM: [2] Custom STA IP/GW/Subnet
*WM: [1] STA IP set: 192.168.8.88
*WM: [3] WIFI station disconnect
*WM: [1] Connecting to new AP: $ecreta
*WM: [3] Using Password: $3nh4$3gur4
*WM: [3] WiFi station enable
*WM: [3] enableSTA PERSISTENT ON
*WM: [1] connectTimeout not set, ESP waitForConnectResult…
*WM: [2] Connection result: WL_CONNECTED
*WM: [3] lastconxresult: WL_CONNECTED
*WM: [1] Connect to new AP [SUCCESS]
*WM: [1] Got IP Address:
*WM: [1] 192.168.8.88
Should save config
*WM: [2] disconnect configportal
*WM: [2] restoring usermode STA
*WM: [2] wifi status: WL_CONNECTED
*WM: [2] wifi mode: STA
*WM: [1] config portal exiting
connected…yeey 😃
saving config
failed to open config file for writing
{“mqtt_server”:“Teste.xxx.com”,“mqtt_port”:“1883”,“blynk_token”:“YOUR_BLYNK_TOKEN”}local ip
192.168.8.88
*WM: [3] freeing allocated params!
*WM: [3] unloading
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 1
- Comments: 25
Hi guys! Today I have the same problem as you and I solved it changing configuration in tool -> flash size -> 4M(1M SPIFFS). Someone posted it but I’m doing it again to be easier to find!
Hi. Same problem for me and also solved by downgrading esp8266 core from 2.5.0 to 2.4.0 thanks to @leofuscaldi comment! Thanks a lot @leofuscaldi, made my day! Have been troubleshooting for some time now. 😃