Chat freely about anything...

User avatar
By ghanashyam
#50151 I'm trying to write a few lines of data onto my Olimex MOD WiFi ESP8266 Dev Rev B,and then read it, using the method given in https://github.com/tzapu/WiFiManager/blob/master/examples/AutoConnectWithFSParametersAndCustomIP/AutoConnectWithFSParametersAndCustomIP.ino ,but I do not get uniform results, ie, sometimes when I read the data , I get the desired output, but sometimes it prints junk characters. I don't know why it is happening so. Here is the code
Code: Select allif (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(email, json["E-Mail"]);
        }
        else
          Serial.println("Failed to Load json config");
      }
    }
  }
  else
    Serial.println("Failed to Mount FS");
  SPIFFS.end();
  String str(email);
  Serial.println("\n" + str + "\n");


I am not getting any compilation errors. It just prints junk characters sometimes. Also is it better to write data onto the EEPROM or the Flash, given I need to read the data again?

Thanks in Advance