-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspiffs.h
More file actions
43 lines (39 loc) · 1.05 KB
/
spiffs.h
File metadata and controls
43 lines (39 loc) · 1.05 KB
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
#ifndef __SPIFFS_H_
#define __SPIFFS_H_
#ifdef ESP8266
#include <FS.h> // Include the SPIFFS library
void SPIFFS_begin(){
if(!SPIFFS.begin()){
Serial.println("An Error has occurred while mounting SPIFFS");
}
}
void writeSPIFFS(float value, char const *path){
File f = SPIFFS.open(path, "w");
if (!f) {
Serial.println("file open failed");
}
//Serial.print("set ");Serial.print(value);Serial.print(" to ");Serial.println(path);
f.println(value);
f.close();
}
float readSPIFFS(char const *path){
float ret;
File f = SPIFFS.open(path, "r");
if (!f) {
Serial.println("file open failed");
ret = -200;
}
String str = f.readStringUntil('\n');
f.close();
ret = str.toFloat();
//Serial.print("get ");Serial.print(ret);Serial.print(" from ");Serial.println(path);
return ret;
}
void writeReboot(float value){
writeSPIFFS(value, "/reboot.txt");
}
int readReboot(){
return readSPIFFS("/reboot.txt");
}
#endif //ESP8266
#endif // __SPIFFS_H_