Skip to content

Commit 1f8f84c

Browse files
author
burnsed
committed
Get ConfigTool working for ESP32
1 parent 4165f11 commit 1f8f84c

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

src/ConfigTool.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,28 @@
33
Author: Tvde1
44
*/
55

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>
1116

1217
void ConfigTool::load() {
13-
SPIFFS.begin();
18+
if (!SPIFFS.begin(true)) {
19+
Serial.println("SPIFFS Failed");
20+
}
1421
File f = SPIFFS.open("/config.json", "r");
1522
if (!f) {
1623
return;
1724
}
1825

1926
DynamicJsonBuffer jsonBuffer;
2027
JsonObject& root = jsonBuffer.parseObject(f.readStringUntil('\n'));
21-
2228
for (auto item : variables_) {
2329
item.second->deserialize(&root);
2430
}
@@ -37,12 +43,12 @@ void ConfigTool::save() {
3743
SPIFFS.begin();
3844
File f = SPIFFS.open("/config.json", "w");
3945

40-
String output = "";
4146
root.printTo(f);
4247

4348
f.close();
4449
}
4550

51+
#ifdef ESP8266
4652
String ConfigTool::createWebPage(bool updated) {
4753
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>";
4854
const String continueHtml = "<form method=\"POST\" action=\"\">";
@@ -99,9 +105,10 @@ std::function<void()> ConfigTool::getWebHandler(ESP8266WebServer* server) {
99105
return;
100106
};
101107
}
108+
#endif
102109

103110
void ConfigTool::reset() {
104-
SPIFFS.begin();
111+
SPIFFS.begin(true);
105112
SPIFFS.remove("/config.json");
106113

107114
for (auto item : variables_) {

src/ConfigTool.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
Author: Tvde1
44
*/
55

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>
1115

1216
#ifndef _ConfigTool_h
1317
#define _ConfigTool_h
@@ -148,11 +152,19 @@ struct ConfigTool {
148152
};
149153
void load();
150154
void save();
155+
156+
#ifdef ESP8266
151157
std::function<void()> getWebHandler(ESP8266WebServer*);
158+
#endif
159+
152160
void reset();
153161
private:
154162
std::map<String, BaseVar*> variables_;
163+
164+
#ifdef ESP8266
155165
String createWebPage(bool);
166+
#endif
167+
156168
};
157169

158170
#endif

0 commit comments

Comments
 (0)