Problem with credential saving after reboot wemos d1 r1 wifimanager work well with esp12 not wemos d1 r1

#include <WiFiManager.h>
#include <SPI.h>
#include <Wire.h>
#include <FS.h>                   
#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#include <BlynkSimpleEsp8266.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>          
#include <ArduinoJson.h>          
#define BLYNK_PRINT Serial   
#include <Ticker.h>
#include <DHT.h>
#define PIN_LED   D8   // Pin D4 mapped to pin GPIO2/TXD1 of ESP8266, NodeMCU and WeMoS, control on-board LED
#define DHTPIN 5  
BlynkTimer timer;
DHT dht(DHTPIN,  DHT11);

#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

Ticker     led_ticker;
#define AREF_VOLTAGE 3.27
   
//#define BLYNK_DEBUG
char server[15] = "192.168.4.1" ;
char port[6] = "8080";
char auth[34] = "";


bool shouldSaveConfig = false;


void set_led(byte status)
{
  digitalWrite(LED_BUILTIN, status);
}

void heartBeatPrint(void)
{
  static int num = 1;

  if (Blynk.connected())
  {
    set_led(LOW);
    led_ticker.once_ms(111, set_led, (byte) HIGH);
    Serial.print("B");
  }
  else
  {
    Serial.print("F");
    ESP.restart();
  }

  if (num == 80)
  {
    Serial.println();
    num = 1;
  }
  else if (num++ % 10 == 0)
  {
    Serial.print(" ");
  }
}

void check_status()
{
  static unsigned long checkstatus_timeout = 0;

#define STATUS_CHECK_INTERVAL     6000L

  // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change.
  if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
  {
    // report status to Blynk
    heartBeatPrint();

    checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
  }
}

void resetting()
{
  if (digitalRead(13) == LOW) 
    {
          WiFiManager wifiManager;
  wifiManager.resetSettings();
      SPIFFS.format();
    Serial.println("BLYNK resset");
  
  ESP.restart();
ESP.reset();
    ESP.restart();
}


}





  void checkPhysicalButtond0()
{
  if (digitalRead(16) == LOW) //D1 is GPIO5
    {
      Blynk.virtualWrite(V99, LOW);
    }
    else 
   {
    Blynk.virtualWrite(V99, HIGH);
   }
}
 // void checkPhysicalButtond1()
//{
 // if (digitalRead(5) == LOW) //D1 is GPIO5
   // {
    //  Blynk.virtualWrite(V1, LOW);
   // }
  //  else 
  // {
   // Blynk.virtualWrite(V1, HIGH);
  // }
//}
  void checkPhysicalButtond2()
{
  if (digitalRead(4) == LOW) //D1 is GPIO5
    {
      Blynk.virtualWrite(V2, LOW);
   
      Blynk.virtualWrite(V2, LOW);
    }
    else 
   {
    Blynk.virtualWrite(V2, HIGH);

   }
}
  void checkPhysicalButtond3()
  {
  if (digitalRead(0) == LOW) //D1 is GPIO5
    {
      Blynk.virtualWrite(V3, LOW);
    
      Blynk.virtualWrite(V0, LOW);
   }
    else 
   {
    Blynk.virtualWrite(V3, HIGH);
       Blynk.virtualWrite(V0, HIGH);

   }
}
  void checkPhysicalButtond4()
{
  if (digitalRead(2) == LOW) //D1 is GPIO5
    {
      Blynk.virtualWrite(V4, LOW);
    }
    else 
   {
    Blynk.virtualWrite(V4, HIGH);
   }
}
  void checkPhysicalButtond5()
{
  if (digitalRead(14) == LOW) //D1 is GPIO5
    {
      Blynk.virtualWrite(V5, LOW);
    }
    else 
   {
    Blynk.virtualWrite(V5, HIGH);
   }
}
  void checkPhysicalButtond6()
{
  if (digitalRead(12) == LOW) //D1 is GPIO5
    {
      Blynk.virtualWrite(V6, LOW);
    }
    else 
   {
    Blynk.virtualWrite(V6, HIGH);
   }
}
  void checkPhysicalButtond7()
{
  if (digitalRead(13) == LOW) //D1 is GPIO5
    {
      
      WiFiManager wifiManager;
      wifiManager.resetSettings();
      SPIFFS.format();
      Blynk.virtualWrite(V7, LOW);
      Serial.println("ERASING");
    SPIFFS.format();
ESP.reset();  // reset button
ESP.restart();
    }
    else 
   {
    Blynk.virtualWrite(V7, HIGH);

   }
}
  void checkPhysicalButtond8()
{
  if (digitalRead(15) == LOW) //D1 is GPIO5
    {
      Blynk.virtualWrite(V8, LOW);
    }
    else 
   {
    Blynk.virtualWrite(V8, HIGH);
   }
}

void saveConfigCallback () {
  Serial.println("Should save config");
  shouldSaveConfig = true;
}
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(true); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V20, h);
  Blynk.virtualWrite(V21, t);
}
void setup() {{
    dht.begin();

  // Setup a function to be called every second
  timer.setInterval(10000L, sendSensor);
    
  


  
  pinMode(16, INPUT_PULLUP);

  // Setup a function to be called every 100 ms
  timer.setInterval(200L, checkPhysicalButtond0);
  
}
    // {

  
 // pinMode(5, INPUT_PULLUP);

  // Setup a function to be called every 100 ms
//  timer.setInterval(200L, checkPhysicalButtond1);
//}

     {

  
  pinMode(4, INPUT_PULLUP);

  // Setup a function to be called every 100 ms
  timer.setInterval(200L, checkPhysicalButtond2);
  
}

     {

  
  pinMode(0, INPUT_PULLUP);

  // Setup a function to be called every 100 ms
 timer.setInterval(200L, checkPhysicalButtond3);

}
     {

  
  pinMode(2, INPUT_PULLUP);

  // Setup a function to be called every 100 ms
  timer.setInterval(200L, checkPhysicalButtond4);
}
     {

  
  pinMode(14, INPUT_PULLUP);

  // Setup a function to be called every 100 ms
  timer.setInterval(200L, checkPhysicalButtond5);
}
     {

  
  pinMode(12, INPUT_PULLUP);

  // Setup a function to be called every 100 ms
  timer.setInterval(200L, checkPhysicalButtond6);
}
     {

  
  pinMode(13, INPUT_PULLUP);

  // Setup a function to be called every 100 ms
  timer.setInterval(100L, checkPhysicalButtond7);
  timer.setInterval(10L, resetting);
  
}
     {

  
  pinMode(15, INPUT_PULLUP);

  // Setup a function to be called every 100 ms
  timer.setInterval(100L, checkPhysicalButtond8);
}


   Serial.begin(115200);
  Serial.println();
  //***************DON'T TOUTCH WIFI-MANAGER AND BLYNK PART *************************
  //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(server, json["server"]);
          strcpy(port, json["port"]);
          strcpy(auth, json["auth"]);
        } else {
          Serial.println("failed to load json config");
          
        }
      }
    }
  } else {
    Serial.println("failed to mount FS");
    SPIFFS.format();
  }
  //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_server("server", "server", server, 15);
  WiFiManagerParameter custom_port("port", "port", port, 6);
  WiFiManagerParameter custom_auth("blynk", "blynk token", auth, 34);
  //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(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
  //add all your parameters here
  wifiManager.addParameter(&custom_server);
  wifiManager.addParameter(&custom_port);
  wifiManager.addParameter(&custom_auth);
  //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(300);
  //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("NotifySPA", "")) {
    Serial.println("failed to connect and hit timeout");
    //reset and try again, or maybe put it to deep sleep
    ESP.restart();//      ici ESP.reset();
  }
  //if you get here you have connected to the WiFi
  Serial.println("connected...yeey :)");
  //read updated parameters
  strcpy(server, custom_server.getValue());
  strcpy(port, custom_port.getValue());
  strcpy(auth, custom_auth.getValue());
  //save the custom parameters to FS
  if (shouldSaveConfig) {
    Serial.println("saving config");
    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.createObject();
    json["server"] = server;
    json["port"] = port;
    json["auth"] = auth;
    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());
  Blynk.config(auth);
  bool result = Blynk.connect();
 Blynk.run();
if (result != true)
{
  Serial.println("BLYNK Connection Fail");
  //SPIFFS.format();
  Serial.println(auth);
  //wifiManager.resetSettings();
  Serial.println("local ip");
Serial.println(WiFi.localIP());
  Blynk.config(auth);
  bool result = Blynk.connect();
 Blynk.run();
if (result != true)
  ESP.restart();
}
else
{
  Serial.println("BLYNK Connected");
//WiFi.mode(WIFI_STA);

//        ***************END  DON'T TOUTCH WIFI-MANAGER AND BLYNK PART *************************
}}
void notify(){ 
}
void loop() {
  notify();

  check_status();
notify();
timer.run(); // Initiates BlynkTimer
 Blynk.run();
}

And the problem is what exactly ?

Pete.

is with credential auth saving , after reboot they can connect to wifi credential but not to auth blynk . here the output os serial. i try many attemps type of card and i realy don’t understand , this same code well with esp12f but wemos d1 r1 not saving i choose the same parameter for fs memory but dont work?

after reboot dont reconnect because the blynk auth was not succesfull saved before

What Flash Size and Erase Flash settings did you choose when you compiled/uploaded the sketch?

Pete.

i have try all (none= normal dont work) 1m, 2m 3m

I have no idea what your answer means.

Pete.

board wemos d1 r1
i have try all option : 4mb (fs:2mb ota :1019kb)
4mb (fs:1mb ota :1019kb)
4mb (fs:3mb ota :512kb)
4mb (fs:none ota :1019kb)

Well, that answers half of my question.

Selecting fs:none is never going to be a viable option I’d you want to store data in the file system memory.

Pete.

i know it dont work with this option selected i have try anayway in the case it work ,… have you idea what happen?

Have you any intention of answering my question?

Pete.

how to do this? select another option? i have already try all other option what do you mean if it is not this

I don’t know what i will do now ? Can you help me? Please. Tank you

if is stupid mistake or easy to fix , can you give me clue :S please

image

Pete.

ha yes i have already try y too , my probleme is when i have finish to configured credential via portal the blynk auth credential was erased just befor blynk connect for the first time, i have try to add saving credential attemp but , this is not working,… i have exactly the same code (ino)for wemos d1 mini with(nodemcu0.9 board selected) and all succesfully working .
i have change the memory and try the full erase or just sketch or sketch+wifi and no working after all this

and too for more information of my tested already , with the wemos d1 mini when i upload , if i choose skecth only. or erase or sketch+wifi , the code work all correctly too (this have no incidence to it).

i use arduinojson 5 and the scirpt work well on the wemos the mini and - or on nodemcu0.9 .
is just the model wemos d1 r1 the problem as

if you want i can show you the output serial monitor
of each ?

finaly is stupid of my own side , choose incompatible board apparantly