Advertisement
RuiViana

ESP_SSIFFS

May 29th, 2017
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include "FS.h"
  2.  
  3. void setup()
  4. {
  5.  // SPIFFS.format();
  6.   Serial.begin(115200);
  7.   bool result = SPIFFS.begin();             // always use this to "mount" the filesystem
  8.   Serial.println("SPIFFS opened: " + result);
  9.   File f = SPIFFS.open("/g.txt", "r");      // this opens the file "f.txt" in read-mode
  10.   if (!f)
  11.   {
  12.     Serial.println("File doesn't exist yet. Creating it");
  13.     File f = SPIFFS.open("/g.txt", "w");          // open the file in write mode
  14.     if (!f)
  15.     {
  16.       Serial.println("file creation failed");
  17.     }
  18.     f.println("ssid=abc");                        // now write two lines in key/value style with  end-of-line characters
  19.     f.println("password=123455secret");
  20.   }
  21.   else
  22.   {
  23.     while (f.available())                         // we could open the file
  24.     {
  25.       String line = f.readStringUntil('\n');      //Lets read line by line from the file
  26.       Serial.println(line);
  27.     }
  28.   }
  29.   f.close();
  30. }
  31. //------------------------------------
  32. void loop() {
  33.   // nothing to do for now, this is just a simple test
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement