| ... | ... |
@@ -6,6 +6,8 @@ |
| 6 | 6 |
#include <ESP8266WebServer.h> |
| 7 | 7 |
#include <DNSServer.h> |
| 8 | 8 |
|
| 9 |
+#define DEBUG 0 //0=off 1=on |
|
| 10 |
+ |
|
| 9 | 11 |
// Variables |
| 10 | 12 |
const char* set_mqtt_user="exwrgq"; |
| 11 | 13 |
const char* set_mqtt_devid="2638"; |
| ... | ... |
@@ -22,17 +24,21 @@ bool writeConfigFile(); |
| 22 | 22 |
void setup() {
|
| 23 | 23 |
// Put your setup code here, to run once |
| 24 | 24 |
Serial.begin(115200); |
| 25 |
+ #if DEBUG |
|
| 25 | 26 |
Serial.println("\n Starting");
|
| 27 |
+ #endif |
|
| 26 | 28 |
|
| 27 | 29 |
// Mount the filesystem |
| 28 | 30 |
bool result = SPIFFS.begin(); |
| 29 | 31 |
//Serial.println("SPIFFS opened: " + result);
|
| 30 | 32 |
|
| 31 | 33 |
if (readConfigFile()) {
|
| 34 |
+ #if DEBUG |
|
| 32 | 35 |
Serial.print("User:");
|
| 33 | 36 |
Serial.println(mqtt_user); |
| 34 | 37 |
Serial.print("devid:");
|
| 35 | 38 |
Serial.println(mqtt_devid); |
| 39 |
+ #endif |
|
| 36 | 40 |
} |
| 37 | 41 |
//WiFi.printDiag(Serial); //Remove this line if you do not want to see WiFi password printed |
| 38 | 42 |
|
| ... | ... |
@@ -51,7 +57,9 @@ bool readConfigFile() {
|
| 51 | 51 |
File f = SPIFFS.open("/config.json", "r");
|
| 52 | 52 |
|
| 53 | 53 |
if (!f) {
|
| 54 |
+ #if DEBUG |
|
| 54 | 55 |
Serial.println("Configuration file not found");
|
| 56 |
+ #endif |
|
| 55 | 57 |
return false; |
| 56 | 58 |
} else {
|
| 57 | 59 |
// we could open the file |
| ... | ... |
@@ -70,10 +78,14 @@ bool readConfigFile() {
|
| 70 | 70 |
JsonObject& json = jsonBuffer.parseObject(buf.get()); |
| 71 | 71 |
// Test if parsing succeeds. |
| 72 | 72 |
if (!json.success()) {
|
| 73 |
+ #if DEBUG |
|
| 73 | 74 |
Serial.println("JSON parseObject() failed");
|
| 75 |
+ #endif |
|
| 74 | 76 |
return false; |
| 75 | 77 |
} |
| 78 |
+ #if DEBUG |
|
| 76 | 79 |
json.printTo(Serial); |
| 80 |
+ #endif |
|
| 77 | 81 |
strcpy(mqtt_user, json["mqtt_user"]); |
| 78 | 82 |
strcpy(mqtt_devid, json["mqtt_devid"]); |
| 79 | 83 |
} |
| ... | ... |
@@ -81,7 +93,9 @@ bool readConfigFile() {
|
| 81 | 81 |
} |
| 82 | 82 |
|
| 83 | 83 |
bool writeConfigFile() {
|
| 84 |
+ #if DEBUG |
|
| 84 | 85 |
Serial.println("Saving config file");
|
| 86 |
+ #endif |
|
| 85 | 87 |
DynamicJsonBuffer jsonBuffer; |
| 86 | 88 |
JsonObject& json = jsonBuffer.createObject(); |
| 87 | 89 |
|
| ... | ... |
@@ -92,7 +106,7 @@ bool writeConfigFile() {
|
| 92 | 92 |
// Open file for writing |
| 93 | 93 |
File f = SPIFFS.open("/config.json", "w");
|
| 94 | 94 |
if (!f) {
|
| 95 |
- Serial.println("Failed to open config file for writing");
|
|
| 95 |
+ Serial.println("Instalation failed! Write error!");
|
|
| 96 | 96 |
return false; |
| 97 | 97 |
} |
| 98 | 98 |
|
| ... | ... |
@@ -101,7 +115,7 @@ bool writeConfigFile() {
|
| 101 | 101 |
json.printTo(f); |
| 102 | 102 |
f.close(); |
| 103 | 103 |
|
| 104 |
- Serial.println("\nConfig file was successfully saved");
|
|
| 104 |
+ Serial.println("\nDevice updated!");
|
|
| 105 | 105 |
return true; |
| 106 | 106 |
} |
| 107 | 107 |
|