File tree Expand file tree Collapse file tree 2 files changed +33
-14
lines changed Expand file tree Collapse file tree 2 files changed +33
-14
lines changed Original file line number Diff line number Diff line change 3
3
Author: Tvde1
4
4
*/
5
5
6
- #include " ConfigTool.h" ;
7
- #include " FS.h" ;
8
- #include " ArduinoJson.h" ;
9
- #include " ESP8266WebServer.h" ;
10
- #include < map> ;
6
+ #include " ConfigTool.h"
7
+ #include < FS.h>
8
+ #include < ArduinoJson.h>
9
+ #include < SPIFFS.h>
10
+
11
+ #ifdef ESP8266
12
+ #include < ESP8266WebServer.h>
13
+ #endif
14
+
15
+ #include < map>
11
16
12
17
void ConfigTool::load () {
13
- SPIFFS.begin ();
18
+ if (!SPIFFS.begin (true )) {
19
+ Serial.println (" SPIFFS Failed" );
20
+ }
14
21
File f = SPIFFS.open (" /config.json" , " r" );
15
22
if (!f) {
16
23
return ;
17
24
}
18
25
19
26
DynamicJsonBuffer jsonBuffer;
20
27
JsonObject& root = jsonBuffer.parseObject (f.readStringUntil (' \n ' ));
21
-
22
28
for (auto item : variables_) {
23
29
item.second ->deserialize (&root);
24
30
}
@@ -37,12 +43,12 @@ void ConfigTool::save() {
37
43
SPIFFS.begin ();
38
44
File f = SPIFFS.open (" /config.json" , " w" );
39
45
40
- String output = " " ;
41
46
root.printTo (f);
42
47
43
48
f.close ();
44
49
}
45
50
51
+ #ifdef ESP8266
46
52
String ConfigTool::createWebPage (bool updated) {
47
53
const String beginHtml = "<html><head><title>Config Tool</title><link rel=\"stylesheet\"href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css\"integrity=\"sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4\"crossorigin=\"anonymous\"><script src=\"https://code.jquery.com/jquery-3.3.1.slim.min.js\"integrity=\"sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo\"crossorigin=\"anonymous\"></script><script src=\"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js\"integrity=\"sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ\"crossorigin=\"anonymous\"></script><script src=\"https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js\"integrity=\"sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm\"crossorigin=\"anonymous\"></script></head><body><div class=\"container\"><div class=\"jumbotron\"style=\"width:100%\"><h1>ConfigTool Web Interface</h1><p>Edit the config variables here and click save.</p></div>";
48
54
const String continueHtml = " <form method=\" POST\" action=\"\" >" ;
@@ -99,9 +105,10 @@ std::function<void()> ConfigTool::getWebHandler(ESP8266WebServer* server) {
99
105
return ;
100
106
};
101
107
}
108
+ #endif
102
109
103
110
void ConfigTool::reset () {
104
- SPIFFS.begin ();
111
+ SPIFFS.begin (true );
105
112
SPIFFS.remove (" /config.json" );
106
113
107
114
for (auto item : variables_) {
Original file line number Diff line number Diff line change 3
3
Author: Tvde1
4
4
*/
5
5
6
- #include < Arduino.h> ;
7
- #include < map> ;
8
- #include " ArduinoJson.h"
9
- #include " ESP8266WebServer.h" ;
10
- #include < string> ;
6
+ #include < Arduino.h>
7
+ #include < map>
8
+ #include < ArduinoJson.h>
9
+
10
+ #ifdef ESP8266
11
+ #include < ESP8266WebServer.h>
12
+ #endif
13
+
14
+ #include < string>
11
15
12
16
#ifndef _ConfigTool_h
13
17
#define _ConfigTool_h
@@ -148,11 +152,19 @@ struct ConfigTool {
148
152
};
149
153
void load ();
150
154
void save ();
155
+
156
+ #ifdef ESP8266
151
157
std::function<void ()> getWebHandler (ESP8266WebServer*);
158
+ #endif
159
+
152
160
void reset ();
153
161
private:
154
162
std::map<String, BaseVar*> variables_;
163
+
164
+ #ifdef ESP8266
155
165
String createWebPage (bool );
166
+ #endif
167
+
156
168
};
157
169
158
170
#endif
You can’t perform that action at this time.
0 commit comments