|
@@ -14,6 +14,12 @@ bool setConfig(char* param, char* value) {
|
|
|
strlcpy(deviceName, value, 31);
|
|
|
// deviceName[30] = '\0';
|
|
|
}
|
|
|
+ else if ( strcmp(param, "httpUser") == 0 ) {
|
|
|
+ strlcpy(http_user, value, 31);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "httpPass") == 0 ) {
|
|
|
+ strlcpy(http_pass, value, 31);
|
|
|
+ }
|
|
|
else if ( strcmp(param, "usedRelais") == 0 ) {
|
|
|
usedRelaisCount = atoi(value);
|
|
|
}
|
|
@@ -173,47 +179,67 @@ bool loadConfig() { // loadConfig 1
|
|
|
Serial.print("file size: ");
|
|
|
Serial.println(size);
|
|
|
|
|
|
- if (size > 800) {
|
|
|
+// Serial.println("file content:");
|
|
|
+//
|
|
|
+// while (configFile.available()) {
|
|
|
+// //Lets read line by line from the file
|
|
|
+// String line = configFile.readStringUntil('\n');
|
|
|
+// Serial.println(line);
|
|
|
+// }
|
|
|
+// Serial.println();
|
|
|
+
|
|
|
+ if (size > 900) {
|
|
|
Serial.println("Config file size is too large");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ Serial.println("allocate buffer");
|
|
|
// Allocate a buffer to store contents of the file.
|
|
|
std::unique_ptr<char[]> buf(new char[size]);
|
|
|
|
|
|
+ Serial.println("read file bytes to buffer");
|
|
|
// We don't use String here because ArduinoJson library requires the input
|
|
|
// buffer to be mutable. If you don't use ArduinoJson, you may as well
|
|
|
// use configFile.readString instead.
|
|
|
configFile.readBytes(buf.get(), size);
|
|
|
|
|
|
- StaticJsonBuffer<810> jsonBuffer;
|
|
|
+ Serial.println("create json buffer");
|
|
|
+
|
|
|
+ StaticJsonBuffer<800> jsonBuffer;
|
|
|
+
|
|
|
+ Serial.println("parse json data");
|
|
|
+
|
|
|
JsonObject& json = jsonBuffer.parseObject(buf.get());
|
|
|
|
|
|
+ Serial.println("do her kumm ma a no");
|
|
|
+
|
|
|
if (!json.success()) {
|
|
|
Serial.println("Failed to parse config file");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- strlcpy(deviceName, json["devName"], 31);
|
|
|
- strlcpy(http_user, json["httpUser"], 31);
|
|
|
- strlcpy(http_pass, json["httpPass"], 31);
|
|
|
- strlcpy(mqtt_server, json["mqttHost"], 41);
|
|
|
- mqtt_port = atoi(json["mqttPort"]);
|
|
|
- strlcpy(mqtt_user, json["mqttUser"], 31);
|
|
|
- strlcpy(mqtt_pass, json["mqttPass"], 31);
|
|
|
- strlcpy(mqtt_topic_in, json["inTop"], 51);
|
|
|
- strlcpy(mqtt_topic_out, json["outTop"], 51);
|
|
|
- strlcpy(mqtt_willTopic, json["willTop"], 51);
|
|
|
- mqtt_willQos = atoi(json["willQos"]);
|
|
|
- if (atoi(json["willRet"]) == 1) mqtt_willRetain = true;
|
|
|
+ Serial.println("und da ?");
|
|
|
+ strlcpy(deviceName, json["devName"] | "", 31);
|
|
|
+ strlcpy(http_user, json["httpUser"] | "", 31);
|
|
|
+ strlcpy(http_pass, json["httpPass"] | "", 31);
|
|
|
+ strlcpy(mqtt_server, json["mqttHost"] | "", 41);
|
|
|
+ mqtt_port = atoi(json["mqttPort"] | "");
|
|
|
+ strlcpy(mqtt_user, json["mqttUser"] | "", 31);
|
|
|
+ strlcpy(mqtt_pass, json["mqttPass"] | "", 31);
|
|
|
+ strlcpy(mqtt_topic_in, json["inTop"] | "", 51);
|
|
|
+ strlcpy(mqtt_topic_out, json["outTop"] | "", 51);
|
|
|
+ strlcpy(mqtt_willTopic, json["willTop"] | "", 51);
|
|
|
+ mqtt_willQos = atoi(json["willQos"] | "0");
|
|
|
+ if (atoi(json["willRet"] | "") == 1) mqtt_willRetain = true;
|
|
|
else mqtt_willRetain = false;
|
|
|
- strlcpy(mqtt_willMsg, json["willMsg"], 31);
|
|
|
- strlcpy(domoticz_out_topic, json["domoOutTop"], 51);
|
|
|
+ strlcpy(mqtt_willMsg, json["willMsg"] | "", 31);
|
|
|
+ strlcpy(domoticz_out_topic, json["domoOutTop"] | "", 51);
|
|
|
|
|
|
Serial.println("Loaded config values:");
|
|
|
printConfig();
|
|
|
return true;
|
|
|
}
|
|
|
+ configFile.close();
|
|
|
}
|
|
|
else {
|
|
|
Serial.println("file /config.json file does not exist");
|
|
@@ -235,14 +261,19 @@ bool loadConfig2() {
|
|
|
size_t size = configFile.size();
|
|
|
Serial.print("file size: ");
|
|
|
Serial.println(size);
|
|
|
- if (size > 1195) {
|
|
|
+ if (size > 800) {
|
|
|
Serial.println("Config file size is too large");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// Allocate a buffer to store contents of the file.
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
std::unique_ptr<char[]> buf(new char[size]);
|
|
|
|
|
|
+
|
|
|
+
|
|
|
// We don't use String here because ArduinoJson library requires the input
|
|
|
// buffer to be mutable. If you don't use ArduinoJson, you may as well
|
|
|
// use configFile.readString instead.
|
|
@@ -256,20 +287,20 @@ bool loadConfig2() {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- usedRelaisCount = atoi(json["usedRelais"]);
|
|
|
- usedButtonsCount = atoi(json["usedButtons"]);
|
|
|
- strlcpy(mqtt_topic_out_hold_1, json["outTop_hold1"], 51);
|
|
|
- strlcpy(mqtt_topic_out_hold_2, json["outTop_hold2"], 51);
|
|
|
- strlcpy(mqtt_topic_out_hold_3, json["outTop_hold3"], 51);
|
|
|
- strlcpy(mqtt_payload_out_hold_1, json["outPld_hold1"], 31);
|
|
|
- strlcpy(mqtt_payload_out_hold_2, json["outPld_hold2"], 31);
|
|
|
- strlcpy(mqtt_payload_out_hold_3, json["outPld_hold3"], 31);
|
|
|
- domoticzIdx[0] = atoi(json["domoIdx1"]);
|
|
|
- domoticzIdx[1] = atoi(json["domoIdx2"]);
|
|
|
- domoticzIdx[2] = atoi(json["domoIdx3"]);
|
|
|
- relais_impulse[0] = atoi(json["impuls1"]);
|
|
|
- relais_impulse[1] = atoi(json["impuls2"]);
|
|
|
- relais_impulse[2] = atoi(json["impuls3"]);
|
|
|
+ usedRelaisCount = atoi(json["usedRelais"] | "");
|
|
|
+ usedButtonsCount = atoi(json["usedButtons"] | "");
|
|
|
+ strlcpy(mqtt_topic_out_hold_1, json["outTop_hold1"] | "", 51);
|
|
|
+ strlcpy(mqtt_topic_out_hold_2, json["outTop_hold2"] | "", 51);
|
|
|
+ strlcpy(mqtt_topic_out_hold_3, json["outTop_hold3"] | "", 51);
|
|
|
+ strlcpy(mqtt_payload_out_hold_1, json["outPld_hold1"] | "", 31);
|
|
|
+ strlcpy(mqtt_payload_out_hold_2, json["outPld_hold2"] | "", 31);
|
|
|
+ strlcpy(mqtt_payload_out_hold_3, json["outPld_hold3"] | "", 31);
|
|
|
+ domoticzIdx[0] = atoi(json["domoIdx1"] | "");
|
|
|
+ domoticzIdx[1] = atoi(json["domoIdx2"] | "");
|
|
|
+ domoticzIdx[2] = atoi(json["domoIdx3"] | "");
|
|
|
+ relais_impulse[0] = atoi(json["impuls1"] | "");
|
|
|
+ relais_impulse[1] = atoi(json["impuls2"] | "");
|
|
|
+ relais_impulse[2] = atoi(json["impuls3"] | "");
|
|
|
|
|
|
Serial.println("Loaded config values:");
|
|
|
printConfig();
|
|
@@ -300,6 +331,7 @@ bool saveConfig() { // safeConfig
|
|
|
json["willMsg"] = mqtt_willMsg;
|
|
|
json["inTop"] = mqtt_topic_in;
|
|
|
json["outTop"] = mqtt_topic_out;
|
|
|
+ json["domoOutTop"] = domoticz_out_topic;
|
|
|
|
|
|
File configFile = SPIFFS.open("/config.json", "w");
|
|
|
if (!configFile) {
|
|
@@ -327,7 +359,6 @@ bool saveConfig2() { // safeConfig2
|
|
|
json["domoIdx1"] = domoticzIdx[0];
|
|
|
json["domoIdx2"] = domoticzIdx[1];
|
|
|
json["domoIdx3"] = domoticzIdx[2];
|
|
|
- json["domoOutTop"] = domoticz_out_topic;
|
|
|
json["impuls1"] = relais_impulse[0];
|
|
|
json["impuls2"] = relais_impulse[1];
|
|
|
json["impuls3"] = relais_impulse[2];
|