-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwemosspiffs.txt
70 lines (61 loc) · 1.29 KB
/
wemosspiffs.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <FS.h>
const char* filename = "/testfile.txt";
void setup()
{
//init serial
Serial.begin(115200);
Serial.println();
//Initialize File System
if(SPIFFS.begin())
{
Serial.println("SPIFFS Initialize....ok");
}
else
{
Serial.println("SPIFFS Initialization...failed");
}
//Format File System
if(SPIFFS.format())
{
Serial.println("File System Formated");
}
else
{
Serial.println("File System Formatting Error");
}
//Create New File And Write Data to It
File f = SPIFFS.open(filename, "w");
if (!f)
{
Serial.println("file open failed");
}
else
{
//Write data to file
Serial.println("Writing Data to File");
f.print("This is sample data which is written to sample file");
f.close(); //Close file
}
}
void loop()
{
int i;
//Read File data
File f = SPIFFS.open(filename, "r");
if (!f)
{
Serial.println("file open failed");
}
else
{
Serial.println("Reading Data from File:");
//Data from file
for(i=0;i<f.size();i++) //Read upto complete file size
{
Serial.print((char)f.read());
}
f.close(); //Close file
Serial.println("File Closed");
}
delay(5000);
}