|
@@ -1,902 +1,977 @@
|
|
|
-
|
|
|
-bool setConfig(char* param, char* value) {
|
|
|
- // sets the corresponding config variable for 'param' to new value
|
|
|
- // does not trigger saving to flash
|
|
|
- // does not distinguish between config and config2 as this is only split on flash and web-interface
|
|
|
-
|
|
|
- if (debug) {
|
|
|
- Serial.print("setConfig - '");
|
|
|
- Serial.print(param);
|
|
|
- Serial.print("' to '");
|
|
|
- Serial.print(value);
|
|
|
- Serial.println("'");
|
|
|
- }
|
|
|
-
|
|
|
- // values
|
|
|
- if ( strcmp(param, "temp") == 0 ) {
|
|
|
- float valueFloat = round(atof(value) * 2.0) / 2.0;
|
|
|
-#ifdef DEBUG_VERBOSE
|
|
|
- Serial.print(valueFloat);
|
|
|
-#endif
|
|
|
- setTempTo(valueFloat);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "tempLow") == 0 ) {
|
|
|
- float valueFloat = round(atof(value) * 2.0) / 2.0;
|
|
|
-#ifdef DEBUG_VERBOSE
|
|
|
- Serial.print(valueFloat);
|
|
|
-#endif
|
|
|
- setTempLowTo(valueFloat);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "tempLow2") == 0 ) {
|
|
|
- float valueFloat = round(atof(value) * 2.0) / 2.0;
|
|
|
-#ifdef DEBUG_VERBOSE
|
|
|
- Serial.print(valueFloat);
|
|
|
-#endif
|
|
|
- setTempLow2To(valueFloat);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "mode") == 0 ) {
|
|
|
- int val = atoi(value);
|
|
|
- if (val >= 0 && val <= 3) {
|
|
|
- setHeatingmodeTo(val);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //confdata
|
|
|
- else if ( strcmp(param, "devName") == 0 ) {
|
|
|
- strlcpy(deviceName, value, 31);
|
|
|
- }
|
|
|
- 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, "httpToken") == 0 ) {
|
|
|
- strlcpy(http_token, value, 31);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "mqttHost") == 0 ) {
|
|
|
- strlcpy(mqtt_server, value, 41);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "mqttPort") == 0 ) {
|
|
|
- mqtt_port = atoi(value);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "mqttUser") == 0 ) {
|
|
|
- strlcpy(mqtt_user, value, 31);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "mqttPass") == 0 ) {
|
|
|
- strlcpy(mqtt_pass, value, 31);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "inTop") == 0 ) {
|
|
|
- strlcpy(mqtt_topic_in, value, 51);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "outTop") == 0 ) {
|
|
|
- strlcpy(mqtt_topic_out, value, 51);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "outRet") == 0 ) {
|
|
|
- if (atoi(value) == 1) mqtt_outRetain = true;
|
|
|
- else mqtt_outRetain = false;
|
|
|
- }
|
|
|
- else if ( strcmp(param, "willTop") == 0 ) {
|
|
|
- strlcpy(mqtt_willTopic, value, 51);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "willQos") == 0 ) {
|
|
|
- int tmpval = atoi(value);
|
|
|
- if (tmpval >= 0 && tmpval <= 2) mqtt_willQos = tmpval;
|
|
|
- }
|
|
|
- else if ( strcmp(param, "willRet") == 0 ) {
|
|
|
- if (atoi(value) == 1) mqtt_willRetain = true;
|
|
|
- else mqtt_willRetain = false;
|
|
|
- }
|
|
|
- else if ( strcmp(param, "willMsg") == 0 ) {
|
|
|
- strlcpy(mqtt_willMsg, value, 31);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "connMsg") == 0 ) {
|
|
|
- strlcpy(mqtt_connMsg, value, 31);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "domOutTop") == 0 ) {
|
|
|
- strlcpy(domoticz_out_topic, value, 51);
|
|
|
- }
|
|
|
-
|
|
|
- //confdata2
|
|
|
- else if ( strcmp(param, "domIdxTherm") == 0 ) {
|
|
|
- domoticzIdx_Thermostat = atoi(value);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "domIdxMode") == 0 ) {
|
|
|
- domoticzIdx_ThermostatMode = atoi(value);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "domIdxTempHum") == 0 ) {
|
|
|
- domoticzIdx_TempHumSensor = atoi(value);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "domIdxHeating") == 0 ) {
|
|
|
- domoticzIdx_Heating = atoi(value);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "domIdxPIR") == 0 ) {
|
|
|
- domoticzIdx_PIR = atoi(value);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "outTempTop") == 0 ) {
|
|
|
- strlcpy(outTemp_topic_in, value, 51);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "outHumTop") == 0 ) {
|
|
|
- strlcpy(outHum_topic_in, value, 51);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "PIRTop") == 0 ) {
|
|
|
- strlcpy(mqtt_topic_pir, value, 51);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "autoSaveTemp") == 0 ) {
|
|
|
- if (atoi(value) == 1) autoSaveSetTemp = true;
|
|
|
- else autoSaveSetTemp = false;
|
|
|
- }
|
|
|
- else if ( strcmp(param, "autoSaveMode") == 0 ) {
|
|
|
- if (atoi(value) == 1) autoSaveHeatingMode = true;
|
|
|
- else autoSaveHeatingMode = false;
|
|
|
- }
|
|
|
- else if ( strcmp(param, "minOffTime") == 0 ) {
|
|
|
- heatingMinOffTime = atoi(value);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "tempMin") == 0 ) {
|
|
|
- float valueFloat = round(atof(value) * 2.0) / 2.0;
|
|
|
-#ifdef DEBUG_VERBOSE
|
|
|
- Serial.print(valueFloat);
|
|
|
-#endif
|
|
|
- if (valueFloat >= 10 && valueFloat <= 16) {
|
|
|
- setTempMin = valueFloat;
|
|
|
- }
|
|
|
- }
|
|
|
- else if ( strcmp(param, "tempMax") == 0 ) {
|
|
|
- float valueFloat = round(atof(value) * 2.0) / 2.0;
|
|
|
-#ifdef DEBUG_VERBOSE
|
|
|
- Serial.print(valueFloat);
|
|
|
-#endif
|
|
|
- if (valueFloat >= 18 && valueFloat <= 30) {
|
|
|
- setTempMax = valueFloat;
|
|
|
- }
|
|
|
- }
|
|
|
- else if ( strcmp(param, "tempDec") == 0 ) {
|
|
|
- float valueFloat = atof(value);
|
|
|
-#ifdef DEBUG_VERBOSE
|
|
|
- Serial.print(valueFloat);
|
|
|
-#endif
|
|
|
- if (valueFloat >= 0.0 && valueFloat <= 1.5) {
|
|
|
- setTempDecreaseVal = valueFloat;
|
|
|
- }
|
|
|
- }
|
|
|
- else if ( strcmp(param, "hyst") == 0 ) {
|
|
|
- float valueFloat = atof(value);
|
|
|
-#ifdef DEBUG_VERBOSE
|
|
|
- Serial.print(valueFloat);
|
|
|
-#endif
|
|
|
- if (valueFloat >= 0.1 && valueFloat <= 4.0) {
|
|
|
- hysteresis = valueFloat;
|
|
|
- }
|
|
|
- }
|
|
|
- else if ( strcmp(param, "tempCorr") == 0 ) {
|
|
|
- float valueFloat = atof(value);
|
|
|
- if (valueFloat >= -5.0 && valueFloat <= 5.0) {
|
|
|
- tempCorrVal = valueFloat;
|
|
|
- }
|
|
|
- }
|
|
|
- else if ( strcmp(param, "humCorr") == 0 ) {
|
|
|
- int valueInt = atoi(value);
|
|
|
- if (valueInt >= -40 && valueInt <= 40) {
|
|
|
- humCorrVal = valueInt;
|
|
|
- }
|
|
|
- }
|
|
|
- else if ( strcmp(param, "measInt") == 0 ) {
|
|
|
- int valueInt = atoi(value);
|
|
|
- if (valueInt >= 5 && valueInt <= 120) {
|
|
|
- measureInterval = valueInt;
|
|
|
- }
|
|
|
- }
|
|
|
- else if ( strcmp(param, "dispInt") == 0 ) {
|
|
|
- int valueInt = atoi(value);
|
|
|
- if (valueInt >= 2 && valueInt <= 120) {
|
|
|
- displayInterval = valueInt;
|
|
|
- }
|
|
|
- }
|
|
|
- else if ( strcmp(param, "dispTout") == 0 ) {
|
|
|
- int valueInt = atoi(value);
|
|
|
- if (valueInt >= 2 && valueInt <= 1200) {
|
|
|
- displayTimeout = valueInt;
|
|
|
- }
|
|
|
- }
|
|
|
- else if ( strcmp(param, "modename0") == 0 ) {
|
|
|
- strlcpy(modename0, value, 14);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "modename1") == 0 ) {
|
|
|
- strlcpy(modename1, value, 14);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "modename2") == 0 ) {
|
|
|
- strlcpy(modename2, value, 14);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "modename3") == 0 ) {
|
|
|
- strlcpy(modename3, value, 14);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "PIRenDisp") == 0 ) {
|
|
|
- int valueInt = atoi(value);
|
|
|
- if (valueInt == 1) PIR_enablesDisplay = true;
|
|
|
- else PIR_enablesDisplay = false;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void getConfig(char* param) {
|
|
|
- // gets and prints the corresponding config variable for 'param'
|
|
|
-
|
|
|
- if (debug) {
|
|
|
- Serial.print("getConfig - '");
|
|
|
- Serial.print(param);
|
|
|
- Serial.println("'");
|
|
|
- }
|
|
|
-
|
|
|
- char buf[101];
|
|
|
-
|
|
|
- // values
|
|
|
- if ( strcmp(param, "temp") == 0 ) {
|
|
|
- char buf2[11];
|
|
|
- dtostrf(setTemp, 2, 1, buf2);
|
|
|
- sprintf(buf, "setTemp: '%s'", buf2);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "tempLow") == 0 ) {
|
|
|
- char buf2[11];
|
|
|
- dtostrf(setTempLow, 2, 1, buf2);
|
|
|
- sprintf(buf, "setTempLow: '%s'", buf2);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "tempLow2") == 0 ) {
|
|
|
- char buf2[11];
|
|
|
- dtostrf(setTempLow2, 2, 1, buf2);
|
|
|
- sprintf(buf, "setTempLow2: '%s'", buf2);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "mode") == 0 ) {
|
|
|
- sprintf(buf, "heatingMode: '%d'", heatingMode);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
-
|
|
|
- //confdata
|
|
|
- else if ( strcmp(param, "devName") == 0 ) {
|
|
|
- sprintf(buf, "devName: '%s'", deviceName);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "httpUser") == 0 ) {
|
|
|
- sprintf(buf, "httpUser: '%s'", http_user);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "httpPass") == 0 ) {
|
|
|
- sprintf(buf, "httpPass: '%s'", http_pass);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "httpToken") == 0 ) {
|
|
|
- sprintf(buf, "httpToken: '%s'", http_token);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "mqttHost") == 0 ) {
|
|
|
- sprintf(buf, "mqttHost: '%s'", mqtt_server);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "mqttPort") == 0 ) {
|
|
|
- sprintf(buf, "mqttPort: '%s'", mqtt_port);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "mqttUser") == 0 ) {
|
|
|
- sprintf(buf, "mqttUser: '%s'", mqtt_user);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "mqttPass") == 0 ) {
|
|
|
- sprintf(buf, "mqttPass: '%s'", mqtt_pass);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "inTop") == 0 ) {
|
|
|
- sprintf(buf, "inTop: '%s'", mqtt_topic_in);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "outTop") == 0 ) {
|
|
|
- sprintf(buf, "outTop: '%s'", mqtt_topic_out);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "outRet") == 0 ) {
|
|
|
- char buf2[11];
|
|
|
- if (mqtt_outRetain) strcpy(buf2, "1");
|
|
|
- else strcpy(buf2, "0");
|
|
|
- sprintf(buf, "outRet: '%s'", buf2);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "willTop") == 0 ) {
|
|
|
- sprintf(buf, "willTop: '%s'", mqtt_willTopic);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "willQos") == 0 ) {
|
|
|
- sprintf(buf, "willQos: '%d'", mqtt_willQos);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "willRet") == 0 ) {
|
|
|
- char buf2[11];
|
|
|
- if (mqtt_willRetain) strcpy(buf2, "1");
|
|
|
- else strcpy(buf2, "0");
|
|
|
- sprintf(buf, "willRet: '%s'", buf2);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "willMsg") == 0 ) {
|
|
|
- sprintf(buf, "willMsg: '%s'", mqtt_willMsg);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "connMsg") == 0 ) {
|
|
|
- sprintf(buf, "connMsg: '%s'", mqtt_connMsg);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "domOutTop") == 0 ) {
|
|
|
- sprintf(buf, "domOutTop: '%s'", domoticz_out_topic);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
-
|
|
|
- //confdata2
|
|
|
- else if ( strcmp(param, "domIdxTherm") == 0 ) {
|
|
|
- sprintf(buf, "domIdxTherm: '%d'", domoticzIdx_Thermostat);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "domIdxMode") == 0 ) {
|
|
|
- sprintf(buf, "domIdxMode: '%d'", domoticzIdx_ThermostatMode);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "domIdxTempHum") == 0 ) {
|
|
|
- sprintf(buf, "domIdxTempHum: '%d'", domoticzIdx_TempHumSensor);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "domIdxHeating") == 0 ) {
|
|
|
- sprintf(buf, "domIdxHeating: '%d'", domoticzIdx_Heating);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "domIdxPIR") == 0 ) {
|
|
|
- sprintf(buf, "domIdxPIR: '%d'", domoticzIdx_PIR);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "outTempTop") == 0 ) {
|
|
|
- sprintf(buf, "outTempTop: '%s'", outTemp_topic_in);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "outHumTop") == 0 ) {
|
|
|
- sprintf(buf, "outHumTop: '%s'", outHum_topic_in);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "PIRTop") == 0 ) {
|
|
|
- sprintf(buf, "PIRTop: '%s'", mqtt_topic_pir);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "autoSaveTemp") == 0 ) {
|
|
|
- char buf2[11];
|
|
|
- if (autoSaveSetTemp) strcpy(buf2, "1");
|
|
|
- else strcpy(buf2, "0");
|
|
|
- sprintf(buf, "autoSaveTemp: '%s'", buf2);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "autoSaveMode") == 0 ) {
|
|
|
- char buf2[11];
|
|
|
- if (autoSaveHeatingMode) strcpy(buf2, "1");
|
|
|
- else strcpy(buf2, "0");
|
|
|
- sprintf(buf, "autoSaveMode: '%s'", buf2);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "minOffTime") == 0 ) {
|
|
|
- sprintf(buf, "minOffTime: '%d'", heatingMinOffTime);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "tempMin") == 0 ) {
|
|
|
- char buf2[11];
|
|
|
- dtostrf(setTempMin, 2, 1, buf2);
|
|
|
- sprintf(buf, "tempMin: '%s'", buf2);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "tempMax") == 0 ) {
|
|
|
- char buf2[11];
|
|
|
- dtostrf(setTempMax, 2, 1, buf2);
|
|
|
- sprintf(buf, "tempMax: '%s'", buf2);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "tempDec") == 0 ) {
|
|
|
- char buf2[11];
|
|
|
- dtostrf(setTempDecreaseVal, 2, 1, buf2);
|
|
|
- sprintf(buf, "tempDec: '%s'", buf2);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "hyst") == 0 ) {
|
|
|
- char buf2[11];
|
|
|
- dtostrf(hysteresis, 2, 1, buf2);
|
|
|
- sprintf(buf, "hyst: '%s'", buf2);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "tempCorr") == 0 ) {
|
|
|
- char buf2[11];
|
|
|
- dtostrf(tempCorrVal, 2, 1, buf2);
|
|
|
- sprintf(buf, "tempCorr: '%s'", buf2);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "humCorr") == 0 ) {
|
|
|
- sprintf(buf, "humCorr: '%d'", humCorrVal);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "measInt") == 0 ) {
|
|
|
- sprintf(buf, "measInt: '%d'", measureInterval);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "dispInt") == 0 ) {
|
|
|
- sprintf(buf, "dispInt: '%d'", displayInterval);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "dispTout") == 0 ) {
|
|
|
- sprintf(buf, "dispTout: '%d'", displayTimeout);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "modename0") == 0 ) {
|
|
|
- sprintf(buf, "modename0: '%s'", modename0);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "modename1") == 0 ) {
|
|
|
- sprintf(buf, "modename1: '%s'", modename1);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "modename2") == 0 ) {
|
|
|
- sprintf(buf, "modename2: '%s'", modename2);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "modename3") == 0 ) {
|
|
|
- sprintf(buf, "modename3: '%s'", modename3);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
- else if ( strcmp(param, "PIRenDisp") == 0 ) {
|
|
|
- char buf2[11];
|
|
|
- if (PIR_enablesDisplay) strcpy(buf2, "1");
|
|
|
- else strcpy(buf2, "0");
|
|
|
- sprintf(buf, "pirEnDisp: '%d'", PIR_enablesDisplay);
|
|
|
- sendStatus(buf);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void printConfig() {
|
|
|
- // prints current config vars to serial
|
|
|
- Serial.println("\nconfdata:");
|
|
|
- Serial.print("devName: ");
|
|
|
- Serial.println(deviceName);
|
|
|
- Serial.print("httpUser: ");
|
|
|
- Serial.println(http_user);
|
|
|
- Serial.print("httpPass: ");
|
|
|
- Serial.println(http_pass);
|
|
|
- Serial.print("httpToken: ");
|
|
|
- Serial.println(http_token);
|
|
|
- Serial.print("mqttHost: ");
|
|
|
- Serial.println(mqtt_server);
|
|
|
- Serial.print("mqttPort: ");
|
|
|
- Serial.println(mqtt_port);
|
|
|
- Serial.print("mqttUser: ");
|
|
|
- Serial.println(mqtt_user);
|
|
|
- Serial.print("mqttPass: ");
|
|
|
- Serial.println(mqtt_pass);
|
|
|
- Serial.print("inTop: ");
|
|
|
- Serial.println(mqtt_topic_in);
|
|
|
- Serial.print("outTop: ");
|
|
|
- Serial.println(mqtt_topic_out);
|
|
|
- Serial.print("outRet: ");
|
|
|
- Serial.println(mqtt_outRetain);
|
|
|
- Serial.print("willTop: ");
|
|
|
- Serial.println(mqtt_willTopic);
|
|
|
- Serial.print("willQos: ");
|
|
|
- Serial.println(mqtt_willQos);
|
|
|
- Serial.print("willRet: ");
|
|
|
- Serial.println(mqtt_willRetain);
|
|
|
- Serial.print("willMsg: ");
|
|
|
- Serial.println(mqtt_willMsg);
|
|
|
- Serial.print("connMsg: ");
|
|
|
- Serial.println(mqtt_connMsg);
|
|
|
- Serial.print("domOutTop: ");
|
|
|
- Serial.println(domoticz_out_topic);
|
|
|
- Serial.println();
|
|
|
-}
|
|
|
-void printConfig2() {
|
|
|
- Serial.println("\nconfdata2:");
|
|
|
- Serial.print("domIdxTherm: ");
|
|
|
- Serial.println(domoticzIdx_Thermostat);
|
|
|
- Serial.print("domIdxMode: ");
|
|
|
- Serial.println(domoticzIdx_ThermostatMode);
|
|
|
- Serial.print("domIdxTempHum: ");
|
|
|
- Serial.println(domoticzIdx_TempHumSensor);
|
|
|
- Serial.print("domIdxHeating: ");
|
|
|
- Serial.println(domoticzIdx_Heating);
|
|
|
- Serial.print("domIdxPIR: ");
|
|
|
- Serial.println(domoticzIdx_PIR);
|
|
|
- Serial.print("outTempTop: ");
|
|
|
- Serial.println(outTemp_topic_in);
|
|
|
- Serial.print("outHumTop: ");
|
|
|
- Serial.println(outHum_topic_in);
|
|
|
- Serial.print("PIRTop: ");
|
|
|
- Serial.println(mqtt_topic_pir);
|
|
|
- Serial.print("autoSaveTemp: ");
|
|
|
- Serial.println(autoSaveSetTemp);
|
|
|
- Serial.print("autoSaveMode: ");
|
|
|
- Serial.println(autoSaveHeatingMode);
|
|
|
- Serial.print("minOffTime: ");
|
|
|
- Serial.println(heatingMinOffTime);
|
|
|
- Serial.print("tempMin: ");
|
|
|
- Serial.println(setTempMin);
|
|
|
- Serial.print("tempMax: ");
|
|
|
- Serial.println(setTempMax);
|
|
|
- Serial.print("tempLow: ");
|
|
|
- Serial.print(setTempLow);
|
|
|
- Serial.print("tempLow2: ");
|
|
|
- Serial.print(setTempLow2);
|
|
|
- Serial.print("tempDec: ");
|
|
|
- Serial.println(setTempDecreaseVal);
|
|
|
- Serial.print("hyst: ");
|
|
|
- Serial.println(hysteresis);
|
|
|
- Serial.print("tempCorr: ");
|
|
|
- Serial.println(tempCorrVal);
|
|
|
- Serial.print("humCorr: ");
|
|
|
- Serial.println(humCorrVal);
|
|
|
- Serial.print("measInt: ");
|
|
|
- Serial.println(measureInterval);
|
|
|
- Serial.print("dispInt: ");
|
|
|
- Serial.println(displayInterval);
|
|
|
- Serial.print("dispTout: ");
|
|
|
- Serial.println(displayTimeout);
|
|
|
- Serial.print("modename0: ");
|
|
|
- Serial.println(modename0);
|
|
|
- Serial.print("modename1: ");
|
|
|
- Serial.println(modename1);
|
|
|
- Serial.print("modename2: ");
|
|
|
- Serial.println(modename2);
|
|
|
- Serial.print("modename3: ");
|
|
|
- Serial.println(modename3);
|
|
|
- Serial.print("PIRenDisp: ");
|
|
|
- Serial.println(PIR_enablesDisplay);
|
|
|
- Serial.println();
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-bool loadConfig() { // loadConfig 1
|
|
|
- if (SPIFFS.exists("/conf.json")) {
|
|
|
- File configFile = SPIFFS.open("/conf.json", "r");
|
|
|
- if (!configFile) {
|
|
|
- Serial.println("ERR: Failed to open file /conf.json");
|
|
|
- return false;
|
|
|
- }
|
|
|
- else {
|
|
|
- Serial.println("file /conf.json opened");
|
|
|
- size_t size = configFile.size();
|
|
|
-
|
|
|
- Serial.print("file size: ");
|
|
|
- Serial.println(size);
|
|
|
-
|
|
|
- // 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 > 1000) {
|
|
|
- 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<1050> jsonBuffer;
|
|
|
- JsonObject& json = jsonBuffer.parseObject(buf.get());
|
|
|
-
|
|
|
- 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(http_token, json["httpToken"] | "", 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);
|
|
|
-
|
|
|
- if (atoi(json["outRet"] | "") == 1) mqtt_outRetain = true;
|
|
|
- else mqtt_outRetain = false;
|
|
|
-
|
|
|
- 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(mqtt_connMsg, json["connMsg"] | "", 31);
|
|
|
- strlcpy(domoticz_out_topic, json["domOutTop"] | "", 51);
|
|
|
-
|
|
|
- Serial.println("Loaded config values:");
|
|
|
- printConfig();
|
|
|
- return true;
|
|
|
- }
|
|
|
- configFile.close();
|
|
|
- }
|
|
|
- else {
|
|
|
- Serial.println("file /config.json file does not exist");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-} // loadConfig 1
|
|
|
-
|
|
|
-bool loadConfig2() {
|
|
|
- if (SPIFFS.exists("/conf2.json")) {
|
|
|
- File configFile = SPIFFS.open("/conf2.json", "r");
|
|
|
- if (!configFile) {
|
|
|
- Serial.println("ERR: Failed to open file /conf2.json");
|
|
|
- return false;
|
|
|
- }
|
|
|
- else {
|
|
|
- Serial.println("file /conf2.json opened");
|
|
|
- size_t size = configFile.size();
|
|
|
- Serial.print("file size: ");
|
|
|
- Serial.println(size);
|
|
|
- if (size > 1000) {
|
|
|
- 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.
|
|
|
- configFile.readBytes(buf.get(), size);
|
|
|
-
|
|
|
- StaticJsonBuffer<1050> jsonBuffer;
|
|
|
- JsonObject& json = jsonBuffer.parseObject(buf.get());
|
|
|
-
|
|
|
- if (!json.success()) {
|
|
|
- Serial.println("Failed to parse config file");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- domoticzIdx_Thermostat = atoi(json["domIdxTherm"] | "");
|
|
|
- domoticzIdx_ThermostatMode = atoi(json["domIdxMode"] | "");
|
|
|
- domoticzIdx_TempHumSensor = atoi(json["domIdxTempHum"] | "");
|
|
|
- domoticzIdx_Heating = atoi(json["domIdxHeating"] | "");
|
|
|
-
|
|
|
- domoticzIdx_PIR = atoi(json["domIdxPIR"] | "");
|
|
|
- strlcpy(outTemp_topic_in, json["outTempTop"] | "", 51);
|
|
|
- strlcpy(outHum_topic_in, json["outHumTop"] | "", 51);
|
|
|
- strlcpy(mqtt_topic_pir, json["PIRTop"] | "", 51);
|
|
|
-
|
|
|
- if (atoi(json["autoSaveTemp"] | "") == 1) autoSaveSetTemp = true;
|
|
|
- else autoSaveSetTemp = false;
|
|
|
-
|
|
|
- if (atoi(json["autoSaveMode"] | "") == 1) autoSaveHeatingMode = true;
|
|
|
- else autoSaveHeatingMode = false;
|
|
|
-
|
|
|
- heatingMinOffTime = atoi(json["minOffTime"] | "");
|
|
|
- setTempMin = atof(json["tempMin"] | "");
|
|
|
- setTempMax = atof(json["tempMax"] | "");
|
|
|
- setTempLow = atof(json["tempLow"] | "");
|
|
|
- setTempLow2 = atof(json["tempLow2"] | "");
|
|
|
- setTempDecreaseVal = atof(json["tempDec"] | "");
|
|
|
- hysteresis = atof(json["hyst"] | "");
|
|
|
- tempCorrVal = atof(json["tempCorr"] | "");
|
|
|
- humCorrVal = atoi(json["humCorr"] | "");
|
|
|
- measureInterval = atoi(json["measInt"] | "");
|
|
|
- displayInterval = atoi(json["dispInt"] | "");
|
|
|
- displayTimeout = atoi(json["dispTout"] | "");
|
|
|
- strlcpy(modename0, json["modename0"] | "", 14);
|
|
|
- strlcpy(modename1, json["modename1"] | "", 14);
|
|
|
- strlcpy(modename2, json["modename2"] | "", 14);
|
|
|
- strlcpy(modename3, json["modename3"] | "", 14);
|
|
|
-
|
|
|
- if (atoi(json["PIRenDisp"] | "") == 1) PIR_enablesDisplay = true;
|
|
|
- else PIR_enablesDisplay = false;
|
|
|
-
|
|
|
- Serial.println("Loaded config values:");
|
|
|
- printConfig2();
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- Serial.println("file /conf2.json file does not exist");
|
|
|
- return false;
|
|
|
- }
|
|
|
-} //loadConfig2
|
|
|
-
|
|
|
-
|
|
|
-bool loadSetTemp() { // loadSetTemp
|
|
|
- File configFile = SPIFFS.open("/setTemp", "r");
|
|
|
- if (!configFile) {
|
|
|
- Serial.println("ERR: Failed to open file /setTemp");
|
|
|
- return false;
|
|
|
- }
|
|
|
- String s = configFile.readStringUntil('\n');
|
|
|
- configFile.close();
|
|
|
- float tmpSetTemp = s.toFloat();
|
|
|
- if ( tmpSetTemp >= setTempMin && tmpSetTemp <= setTempMax ) {
|
|
|
- setTemp = tmpSetTemp;
|
|
|
- return true;
|
|
|
- }
|
|
|
- else return false;
|
|
|
-} // loadSetTemp
|
|
|
-
|
|
|
-
|
|
|
-bool loadHeatingMode() { // loadHeatingMode
|
|
|
- File configFile = SPIFFS.open("/heatingMode", "r");
|
|
|
- if (!configFile) {
|
|
|
- Serial.println("ERR: Failed to open file /heatingMode");
|
|
|
- return false;
|
|
|
- }
|
|
|
- String s = configFile.readStringUntil('\n');
|
|
|
- configFile.close();
|
|
|
- int tmpHeatingMode = s.toInt();
|
|
|
- if ( tmpHeatingMode >= 0 && tmpHeatingMode <= 2 ) {
|
|
|
- heatingMode = tmpHeatingMode;
|
|
|
- return true;
|
|
|
- }
|
|
|
- else return false;
|
|
|
-} // loadHeatingMode
|
|
|
-
|
|
|
-
|
|
|
-bool saveConfig() { // safeConfig
|
|
|
- StaticJsonBuffer<1050> jsonBuffer;
|
|
|
- JsonObject& json = jsonBuffer.createObject();
|
|
|
-
|
|
|
- json["devName"] = deviceName;
|
|
|
- json["httpUser"] = http_user;
|
|
|
- json["httpPass"] = http_pass;
|
|
|
- json["httpToken"] = http_token;
|
|
|
- json["mqttHost"] = mqtt_server;
|
|
|
- json["mqttPort"] = mqtt_port;
|
|
|
- json["mqttUser"] = mqtt_user;
|
|
|
- json["mqttPass"] = mqtt_pass;
|
|
|
- json["inTop"] = mqtt_topic_in;
|
|
|
- json["outTop"] = mqtt_topic_out;
|
|
|
-
|
|
|
- if (mqtt_outRetain) json["outRet"] = 1;
|
|
|
- else json["outRet"] = 0;
|
|
|
-
|
|
|
- json["willTop"] = mqtt_willTopic;
|
|
|
- json["willQos"] = mqtt_willQos;
|
|
|
-
|
|
|
- if (mqtt_willRetain) json["willRet"] = 1;
|
|
|
- else json["willRet"] = 0;
|
|
|
-
|
|
|
- json["willMsg"] = mqtt_willMsg;
|
|
|
- json["connMsg"] = mqtt_connMsg;
|
|
|
- json["domOutTop"] = domoticz_out_topic;
|
|
|
-
|
|
|
- yield();
|
|
|
-
|
|
|
- File configFile = SPIFFS.open("/conf.json", "w");
|
|
|
- if (!configFile) {
|
|
|
- Serial.println("Failed to open conf file for writing");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- json.printTo(configFile);
|
|
|
- configFile.close();
|
|
|
- return true;
|
|
|
-} // safeConfig
|
|
|
-
|
|
|
-
|
|
|
-bool saveConfig2() { // safeConfig2
|
|
|
- StaticJsonBuffer<1050> jsonBuffer;
|
|
|
- JsonObject& json = jsonBuffer.createObject();
|
|
|
-
|
|
|
- json["domIdxTherm"] = domoticzIdx_Thermostat;
|
|
|
- json["domIdxMode"] = domoticzIdx_ThermostatMode;
|
|
|
- json["domIdxTempHum"] = domoticzIdx_TempHumSensor;
|
|
|
- json["domIdxHeating"] = domoticzIdx_Heating;
|
|
|
- json["domIdxPIR"] = domoticzIdx_PIR;
|
|
|
- json["outTempTop"] = outTemp_topic_in;
|
|
|
- json["outHumTop"] = outHum_topic_in;
|
|
|
- json["PIRTop"] = mqtt_topic_pir;
|
|
|
-
|
|
|
- if (autoSaveSetTemp) json["autoSaveTemp"] = 1;
|
|
|
- else json["autoSaveTemp"] = 0;
|
|
|
-
|
|
|
- if (autoSaveHeatingMode) json["autoSaveMode"] = 1;
|
|
|
- else json["autoSaveMode"] = 0;
|
|
|
-
|
|
|
- json["minOffTime"] = heatingMinOffTime;
|
|
|
- json["tempMin"] = setTempMin;
|
|
|
- json["tempMax"] = setTempMax;
|
|
|
- json["tempLow"] = setTempLow;
|
|
|
- json["tempLow2"] = setTempLow2;
|
|
|
- json["tempDec"] = setTempDecreaseVal;
|
|
|
- json["hyst"] = hysteresis;
|
|
|
- json["tempCorr"] = tempCorrVal;
|
|
|
- json["humCorr"] = humCorrVal;
|
|
|
- json["measInt"] = measureInterval;
|
|
|
- json["dispInt"] = displayInterval;
|
|
|
- json["dispTout"] = displayTimeout;
|
|
|
-
|
|
|
- json["modename0"] = modename0;
|
|
|
- json["modename1"] = modename1;
|
|
|
- json["modename2"] = modename2;
|
|
|
- json["modename3"] = modename3;
|
|
|
-
|
|
|
- if (PIR_enablesDisplay) json["PIRenDisp"] = 1;
|
|
|
- else json["PIRenDisp"] = 0;
|
|
|
-
|
|
|
- yield();
|
|
|
-
|
|
|
- File configFile = SPIFFS.open("/conf2.json", "w");
|
|
|
- if (!configFile) {
|
|
|
- Serial.println("Failed to open conf2 file for writing");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- json.printTo(configFile);
|
|
|
- configFile.close();
|
|
|
- return true;
|
|
|
-} // safeConfig2
|
|
|
-
|
|
|
-
|
|
|
-bool saveSetTemp() { // saveSetTemp
|
|
|
- File configFile = SPIFFS.open("/setTemp", "w");
|
|
|
- if (!configFile) {
|
|
|
- Serial.println("Failed to open setTemp file for writing");
|
|
|
- return false;
|
|
|
- }
|
|
|
- configFile.println(setTemp);
|
|
|
- configFile.close();
|
|
|
- setTempSaved = setTemp;
|
|
|
- return true;
|
|
|
-} // saveSetTemp
|
|
|
-
|
|
|
-bool saveHeatingMode() { // saveHeatingMode
|
|
|
- File configFile = SPIFFS.open("/heatingMode", "w");
|
|
|
- if (!configFile) {
|
|
|
- Serial.println("Failed to open heatingMode file for writing");
|
|
|
- return false;
|
|
|
- }
|
|
|
- configFile.println(heatingMode);
|
|
|
- configFile.close();
|
|
|
- heatingModeSaved = heatingMode;
|
|
|
- return true;
|
|
|
-} // saveHeatingMode
|
|
|
-
|
|
|
-
|
|
|
-void checkSaveConfigTriggered() {
|
|
|
- if (saveConfigToFlash) {
|
|
|
- saveConfigToFlash = false;
|
|
|
- saveConfig();
|
|
|
- }
|
|
|
- if (saveConfig2ToFlash) {
|
|
|
- saveConfig2ToFlash = false;
|
|
|
- saveConfig2();
|
|
|
- }
|
|
|
- // if (saveSetTempToFlash) {
|
|
|
- // saveSetTempToFlash = false;
|
|
|
- // saveSetTemp();
|
|
|
- // }
|
|
|
- // if (saveHeatingModeToFlash) {
|
|
|
- // saveHeatingModeToFlash = false;
|
|
|
- // saveHeatingMode();
|
|
|
- // }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-void deleteConfig() {
|
|
|
- Serial.println("deleting configuration");
|
|
|
- if (SPIFFS.remove("/formatComplete.txt")) {
|
|
|
- Serial.println("config will be deleted after reboot");
|
|
|
- delay(100);
|
|
|
- ESP.restart();
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
+boolean setConfig(char* param, char* value) {
|
|
|
+ // sets the corresponding config variable for 'param' to new value
|
|
|
+ // does not trigger saving to flash
|
|
|
+ // does not distinguish between config and config2 as this is only split on flash and web-interface
|
|
|
+
|
|
|
+ if (debug) {
|
|
|
+ Serial.print("setConfig - '");
|
|
|
+ Serial.print(param);
|
|
|
+ Serial.print("' to '");
|
|
|
+ Serial.print(value);
|
|
|
+ Serial.println("'");
|
|
|
+ }
|
|
|
+
|
|
|
+ // values
|
|
|
+ if ( strcmp(param, "temp") == 0 ) {
|
|
|
+ float valueFloat = round(atof(value) * 2.0) / 2.0;
|
|
|
+#ifdef DEBUG_VERBOSE
|
|
|
+ Serial.print(valueFloat);
|
|
|
+#endif
|
|
|
+ setTempTo(valueFloat);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "tempLow") == 0 ) {
|
|
|
+ float valueFloat = round(atof(value) * 2.0) / 2.0;
|
|
|
+#ifdef DEBUG_VERBOSE
|
|
|
+ Serial.print(valueFloat);
|
|
|
+#endif
|
|
|
+ setTempLowTo(valueFloat);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "tempLow2") == 0 ) {
|
|
|
+ float valueFloat = round(atof(value) * 2.0) / 2.0;
|
|
|
+#ifdef DEBUG_VERBOSE
|
|
|
+ Serial.print(valueFloat);
|
|
|
+#endif
|
|
|
+ setTempLow2To(valueFloat);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "mode") == 0 ) {
|
|
|
+ int val = atoi(value);
|
|
|
+ if (val >= 0 && val <= 3) {
|
|
|
+ setHeatingmodeTo(val);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //confdata
|
|
|
+ else if ( strcmp(param, "devName") == 0 ) {
|
|
|
+ strlcpy(deviceName, value, 31);
|
|
|
+ }
|
|
|
+ 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, "httpToken") == 0 ) {
|
|
|
+ strlcpy(http_token, value, 31);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "mqttHost") == 0 ) {
|
|
|
+ strlcpy(mqtt_server, value, 41);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "mqttPort") == 0 ) {
|
|
|
+ mqtt_port = atoi(value);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "mqttUser") == 0 ) {
|
|
|
+ strlcpy(mqtt_user, value, 31);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "mqttPass") == 0 ) {
|
|
|
+ strlcpy(mqtt_pass, value, 31);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "inTop") == 0 ) {
|
|
|
+ strlcpy(mqtt_topic_in, value, 51);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "outTop") == 0 ) {
|
|
|
+ strlcpy(mqtt_topic_out, value, 51);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "outRet") == 0 ) {
|
|
|
+ if (atoi(value) == 1) mqtt_outRetain = true;
|
|
|
+ else mqtt_outRetain = false;
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "willTop") == 0 ) {
|
|
|
+ strlcpy(mqtt_willTopic, value, 51);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "willQos") == 0 ) {
|
|
|
+ int tmpval = atoi(value);
|
|
|
+ if (tmpval >= 0 && tmpval <= 2) mqtt_willQos = tmpval;
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "willRet") == 0 ) {
|
|
|
+ if (atoi(value) == 1) mqtt_willRetain = true;
|
|
|
+ else mqtt_willRetain = false;
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "willMsg") == 0 ) {
|
|
|
+ strlcpy(mqtt_willMsg, value, 31);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "connMsg") == 0 ) {
|
|
|
+ strlcpy(mqtt_connMsg, value, 31);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "domOutTop") == 0 ) {
|
|
|
+ strlcpy(domoticz_out_topic, value, 51);
|
|
|
+ }
|
|
|
+
|
|
|
+ //confdata2
|
|
|
+ else if ( strcmp(param, "domIdxTherm") == 0 ) {
|
|
|
+ domoticzIdx_Thermostat = atoi(value);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "domIdxMode") == 0 ) {
|
|
|
+ domoticzIdx_ThermostatMode = atoi(value);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "domIdxTempHum") == 0 ) {
|
|
|
+ domoticzIdx_TempHumSensor = atoi(value);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "domIdxHeating") == 0 ) {
|
|
|
+ domoticzIdx_Heating = atoi(value);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "domIdxPIR") == 0 ) {
|
|
|
+ domoticzIdx_PIR = atoi(value);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "outTempTop") == 0 ) {
|
|
|
+ strlcpy(outTemp_topic_in, value, 51);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "outHumTop") == 0 ) {
|
|
|
+ strlcpy(outHum_topic_in, value, 51);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "PIRTop") == 0 ) {
|
|
|
+ strlcpy(mqtt_topic_pir, value, 51);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "autoSaveTemp") == 0 ) {
|
|
|
+ if (atoi(value) == 1) autoSaveSetTemp = true;
|
|
|
+ else autoSaveSetTemp = false;
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "autoSaveMode") == 0 ) {
|
|
|
+ if (atoi(value) == 1) autoSaveHeatingMode = true;
|
|
|
+ else autoSaveHeatingMode = false;
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "minOffTime") == 0 ) {
|
|
|
+ heatingMinOffTime = atoi(value);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "tempMin") == 0 ) {
|
|
|
+ float valueFloat = round(atof(value) * 2.0) / 2.0;
|
|
|
+#ifdef DEBUG_VERBOSE
|
|
|
+ Serial.print(valueFloat);
|
|
|
+#endif
|
|
|
+ if (valueFloat >= 10 && valueFloat <= 16) {
|
|
|
+ setTempMin = valueFloat;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "tempMax") == 0 ) {
|
|
|
+ float valueFloat = round(atof(value) * 2.0) / 2.0;
|
|
|
+#ifdef DEBUG_VERBOSE
|
|
|
+ Serial.print(valueFloat);
|
|
|
+#endif
|
|
|
+ if (valueFloat >= 18 && valueFloat <= 30) {
|
|
|
+ setTempMax = valueFloat;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "tempDec") == 0 ) {
|
|
|
+ float valueFloat = atof(value);
|
|
|
+#ifdef DEBUG_VERBOSE
|
|
|
+ Serial.print(valueFloat);
|
|
|
+#endif
|
|
|
+ if (valueFloat >= 0.0 && valueFloat <= 1.5) {
|
|
|
+ setTempDecreaseVal = valueFloat;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "hyst") == 0 ) {
|
|
|
+ float valueFloat = atof(value);
|
|
|
+#ifdef DEBUG_VERBOSE
|
|
|
+ Serial.print(valueFloat);
|
|
|
+#endif
|
|
|
+ if (valueFloat >= 0.1 && valueFloat <= 4.0) {
|
|
|
+ hysteresis = valueFloat;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "tempCorr") == 0 ) {
|
|
|
+ float valueFloat = atof(value);
|
|
|
+ if (valueFloat >= -5.0 && valueFloat <= 5.0) {
|
|
|
+ tempCorrVal = valueFloat;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "humCorr") == 0 ) {
|
|
|
+ int valueInt = atoi(value);
|
|
|
+ if (valueInt >= -40 && valueInt <= 40) {
|
|
|
+ humCorrVal = valueInt;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "measInt") == 0 ) {
|
|
|
+ int valueInt = atoi(value);
|
|
|
+ if (valueInt >= 5 && valueInt <= 120) {
|
|
|
+ measureInterval = valueInt;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "dispInt") == 0 ) {
|
|
|
+ int valueInt = atoi(value);
|
|
|
+ if (valueInt >= 2 && valueInt <= 120) {
|
|
|
+ displayInterval = valueInt;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "dispTout") == 0 ) {
|
|
|
+ int valueInt = atoi(value);
|
|
|
+ if (valueInt >= 2 && valueInt <= 1200) {
|
|
|
+ displayTimeout = valueInt;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "offMsg") == 0 ) {
|
|
|
+ strlcpy(offMessage, value, 14);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "modename0") == 0 ) {
|
|
|
+ strlcpy(modename0, value, 14);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "modename1") == 0 ) {
|
|
|
+ strlcpy(modename1, value, 14);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "psetname0") == 0 ) {
|
|
|
+ strlcpy(psetname0, value, 14);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "psetname1") == 0 ) {
|
|
|
+ strlcpy(psetname1, value, 14);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "psetname2") == 0 ) {
|
|
|
+ strlcpy(psetname2, value, 14);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "PIRenDisp") == 0 ) {
|
|
|
+ int valueInt = atoi(value);
|
|
|
+ if (valueInt == 1) PIR_enablesDisplay = true;
|
|
|
+ else PIR_enablesDisplay = false;
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "togTHdisp") == 0 ) {
|
|
|
+ int valueInt = atoi(value);
|
|
|
+ if (valueInt == 1) togglingTempHumAIDisplay = true;
|
|
|
+ else togglingTempHumAIDisplay = false;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void getConfig(char* param) {
|
|
|
+ // gets and prints the corresponding config variable for 'param'
|
|
|
+
|
|
|
+ if (debug) {
|
|
|
+ Serial.print("getConfig - '");
|
|
|
+ Serial.print(param);
|
|
|
+ Serial.println("'");
|
|
|
+ }
|
|
|
+
|
|
|
+ char buf[101];
|
|
|
+
|
|
|
+ // values
|
|
|
+ if ( strcmp(param, "temp") == 0 ) {
|
|
|
+ char buf2[11];
|
|
|
+ dtostrf(setTemp, 2, 1, buf2);
|
|
|
+ sprintf(buf, "setTemp: '%s'", buf2);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "tempLow") == 0 ) {
|
|
|
+ char buf2[11];
|
|
|
+ dtostrf(setTempLow, 2, 1, buf2);
|
|
|
+ sprintf(buf, "setTempLow: '%s'", buf2);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "tempLow2") == 0 ) {
|
|
|
+ char buf2[11];
|
|
|
+ dtostrf(setTempLow2, 2, 1, buf2);
|
|
|
+ sprintf(buf, "setTempLow2: '%s'", buf2);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "mode") == 0 ) {
|
|
|
+ sprintf(buf, "heatingMode: '%d'", heatingMode);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "preset") == 0 ) {
|
|
|
+ sprintf(buf, "preset: '%d'", preset);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+
|
|
|
+ //confdata
|
|
|
+ else if ( strcmp(param, "devName") == 0 ) {
|
|
|
+ sprintf(buf, "devName: '%s'", deviceName);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "httpUser") == 0 ) {
|
|
|
+ sprintf(buf, "httpUser: '%s'", http_user);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "httpPass") == 0 ) {
|
|
|
+ sprintf(buf, "httpPass: '%s'", http_pass);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "httpToken") == 0 ) {
|
|
|
+ sprintf(buf, "httpToken: '%s'", http_token);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "mqttHost") == 0 ) {
|
|
|
+ sprintf(buf, "mqttHost: '%s'", mqtt_server);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "mqttPort") == 0 ) {
|
|
|
+ sprintf(buf, "mqttPort: '%s'", mqtt_port);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "mqttUser") == 0 ) {
|
|
|
+ sprintf(buf, "mqttUser: '%s'", mqtt_user);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "mqttPass") == 0 ) {
|
|
|
+ sprintf(buf, "mqttPass: '%s'", mqtt_pass);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "inTop") == 0 ) {
|
|
|
+ sprintf(buf, "inTop: '%s'", mqtt_topic_in);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "outTop") == 0 ) {
|
|
|
+ sprintf(buf, "outTop: '%s'", mqtt_topic_out);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "outRet") == 0 ) {
|
|
|
+ char buf2[11];
|
|
|
+ if (mqtt_outRetain) strcpy(buf2, "1");
|
|
|
+ else strcpy(buf2, "0");
|
|
|
+ sprintf(buf, "outRet: '%s'", buf2);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "willTop") == 0 ) {
|
|
|
+ sprintf(buf, "willTop: '%s'", mqtt_willTopic);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "willQos") == 0 ) {
|
|
|
+ sprintf(buf, "willQos: '%d'", mqtt_willQos);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "willRet") == 0 ) {
|
|
|
+ char buf2[11];
|
|
|
+ if (mqtt_willRetain) strcpy(buf2, "1");
|
|
|
+ else strcpy(buf2, "0");
|
|
|
+ sprintf(buf, "willRet: '%s'", buf2);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "willMsg") == 0 ) {
|
|
|
+ sprintf(buf, "willMsg: '%s'", mqtt_willMsg);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "connMsg") == 0 ) {
|
|
|
+ sprintf(buf, "connMsg: '%s'", mqtt_connMsg);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "domOutTop") == 0 ) {
|
|
|
+ sprintf(buf, "domOutTop: '%s'", domoticz_out_topic);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+
|
|
|
+ //confdata2
|
|
|
+ else if ( strcmp(param, "domIdxTherm") == 0 ) {
|
|
|
+ sprintf(buf, "domIdxTherm: '%d'", domoticzIdx_Thermostat);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "domIdxMode") == 0 ) {
|
|
|
+ sprintf(buf, "domIdxMode: '%d'", domoticzIdx_ThermostatMode);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "domIdxTempHum") == 0 ) {
|
|
|
+ sprintf(buf, "domIdxTempHum: '%d'", domoticzIdx_TempHumSensor);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "domIdxHeating") == 0 ) {
|
|
|
+ sprintf(buf, "domIdxHeating: '%d'", domoticzIdx_Heating);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "domIdxPIR") == 0 ) {
|
|
|
+ sprintf(buf, "domIdxPIR: '%d'", domoticzIdx_PIR);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "outTempTop") == 0 ) {
|
|
|
+ sprintf(buf, "outTempTop: '%s'", outTemp_topic_in);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "outHumTop") == 0 ) {
|
|
|
+ sprintf(buf, "outHumTop: '%s'", outHum_topic_in);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "PIRTop") == 0 ) {
|
|
|
+ sprintf(buf, "PIRTop: '%s'", mqtt_topic_pir);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "autoSaveTemp") == 0 ) {
|
|
|
+ char buf2[11];
|
|
|
+ if (autoSaveSetTemp) strcpy(buf2, "1");
|
|
|
+ else strcpy(buf2, "0");
|
|
|
+ sprintf(buf, "autoSaveTemp: '%s'", buf2);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "autoSaveMode") == 0 ) {
|
|
|
+ char buf2[11];
|
|
|
+ if (autoSaveHeatingMode) strcpy(buf2, "1");
|
|
|
+ else strcpy(buf2, "0");
|
|
|
+ sprintf(buf, "autoSaveMode: '%s'", buf2);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "minOffTime") == 0 ) {
|
|
|
+ sprintf(buf, "minOffTime: '%d'", heatingMinOffTime);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "tempMin") == 0 ) {
|
|
|
+ char buf2[11];
|
|
|
+ dtostrf(setTempMin, 2, 1, buf2);
|
|
|
+ sprintf(buf, "tempMin: '%s'", buf2);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "tempMax") == 0 ) {
|
|
|
+ char buf2[11];
|
|
|
+ dtostrf(setTempMax, 2, 1, buf2);
|
|
|
+ sprintf(buf, "tempMax: '%s'", buf2);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "tempDec") == 0 ) {
|
|
|
+ char buf2[11];
|
|
|
+ dtostrf(setTempDecreaseVal, 2, 1, buf2);
|
|
|
+ sprintf(buf, "tempDec: '%s'", buf2);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "hyst") == 0 ) {
|
|
|
+ char buf2[11];
|
|
|
+ dtostrf(hysteresis, 2, 1, buf2);
|
|
|
+ sprintf(buf, "hyst: '%s'", buf2);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "tempCorr") == 0 ) {
|
|
|
+ char buf2[11];
|
|
|
+ dtostrf(tempCorrVal, 2, 1, buf2);
|
|
|
+ sprintf(buf, "tempCorr: '%s'", buf2);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "humCorr") == 0 ) {
|
|
|
+ sprintf(buf, "humCorr: '%d'", humCorrVal);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "measInt") == 0 ) {
|
|
|
+ sprintf(buf, "measInt: '%d'", measureInterval);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "dispInt") == 0 ) {
|
|
|
+ sprintf(buf, "dispInt: '%d'", displayInterval);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "dispTout") == 0 ) {
|
|
|
+ sprintf(buf, "dispTout: '%d'", displayTimeout);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "offMsg") == 0 ) {
|
|
|
+ sprintf(buf, "offMsg: '%s'", offMessage);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "modename0") == 0 ) {
|
|
|
+ sprintf(buf, "modename0: '%s'", modename0);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "modename1") == 0 ) {
|
|
|
+ sprintf(buf, "modename1: '%s'", modename1);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "psetname0") == 0 ) {
|
|
|
+ sprintf(buf, "psetname0: '%s'", psetname0);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "psetname1") == 0 ) {
|
|
|
+ sprintf(buf, "psetname1: '%s'", psetname1);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "psetname2") == 0 ) {
|
|
|
+ sprintf(buf, "psetname2: '%s'", psetname2);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "PIRenDisp") == 0 ) {
|
|
|
+ char buf2[11];
|
|
|
+ if (PIR_enablesDisplay) strcpy(buf2, "1");
|
|
|
+ else strcpy(buf2, "0");
|
|
|
+ sprintf(buf, "pirEnDisp: '%d'", PIR_enablesDisplay);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+ else if ( strcmp(param, "togTHdisp") == 0 ) {
|
|
|
+ char buf2[11];
|
|
|
+ if (togglingTempHumAIDisplay) strcpy(buf2, "1");
|
|
|
+ else strcpy(buf2, "0");
|
|
|
+ sprintf(buf, "togTHdisp: '%d'", togglingTempHumAIDisplay);
|
|
|
+ sendStatus(buf);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void printConfig() {
|
|
|
+ // prints current config vars to serial
|
|
|
+ Serial.println("\nconfdata:");
|
|
|
+ Serial.print("devName: ");
|
|
|
+ Serial.println(deviceName);
|
|
|
+ Serial.print("httpUser: ");
|
|
|
+ Serial.println(http_user);
|
|
|
+ Serial.print("httpPass: ");
|
|
|
+ Serial.println(http_pass);
|
|
|
+ Serial.print("httpToken: ");
|
|
|
+ Serial.println(http_token);
|
|
|
+ Serial.print("mqttHost: ");
|
|
|
+ Serial.println(mqtt_server);
|
|
|
+ Serial.print("mqttPort: ");
|
|
|
+ Serial.println(mqtt_port);
|
|
|
+ Serial.print("mqttUser: ");
|
|
|
+ Serial.println(mqtt_user);
|
|
|
+ Serial.print("mqttPass: ");
|
|
|
+ Serial.println(mqtt_pass);
|
|
|
+ Serial.print("inTop: ");
|
|
|
+ Serial.println(mqtt_topic_in);
|
|
|
+ Serial.print("outTop: ");
|
|
|
+ Serial.println(mqtt_topic_out);
|
|
|
+ Serial.print("outRet: ");
|
|
|
+ Serial.println(mqtt_outRetain);
|
|
|
+ Serial.print("willTop: ");
|
|
|
+ Serial.println(mqtt_willTopic);
|
|
|
+ Serial.print("willQos: ");
|
|
|
+ Serial.println(mqtt_willQos);
|
|
|
+ Serial.print("willRet: ");
|
|
|
+ Serial.println(mqtt_willRetain);
|
|
|
+ Serial.print("willMsg: ");
|
|
|
+ Serial.println(mqtt_willMsg);
|
|
|
+ Serial.print("connMsg: ");
|
|
|
+ Serial.println(mqtt_connMsg);
|
|
|
+ Serial.print("domOutTop: ");
|
|
|
+ Serial.println(domoticz_out_topic);
|
|
|
+ Serial.println();
|
|
|
+}
|
|
|
+void printConfig2() {
|
|
|
+ Serial.println("\nconfdata2:");
|
|
|
+ Serial.print("domIdxTherm: ");
|
|
|
+ Serial.println(domoticzIdx_Thermostat);
|
|
|
+ Serial.print("domIdxMode: ");
|
|
|
+ Serial.println(domoticzIdx_ThermostatMode);
|
|
|
+ Serial.print("domIdxTempHum: ");
|
|
|
+ Serial.println(domoticzIdx_TempHumSensor);
|
|
|
+ Serial.print("domIdxHeating: ");
|
|
|
+ Serial.println(domoticzIdx_Heating);
|
|
|
+ Serial.print("domIdxPIR: ");
|
|
|
+ Serial.println(domoticzIdx_PIR);
|
|
|
+ Serial.print("outTempTop: ");
|
|
|
+ Serial.println(outTemp_topic_in);
|
|
|
+ Serial.print("outHumTop: ");
|
|
|
+ Serial.println(outHum_topic_in);
|
|
|
+ Serial.print("PIRTop: ");
|
|
|
+ Serial.println(mqtt_topic_pir);
|
|
|
+ Serial.print("autoSaveTemp: ");
|
|
|
+ Serial.println(autoSaveSetTemp);
|
|
|
+ Serial.print("autoSaveMode: ");
|
|
|
+ Serial.println(autoSaveHeatingMode);
|
|
|
+ Serial.print("minOffTime: ");
|
|
|
+ Serial.println(heatingMinOffTime);
|
|
|
+ Serial.print("tempMin: ");
|
|
|
+ Serial.println(setTempMin);
|
|
|
+ Serial.print("tempMax: ");
|
|
|
+ Serial.println(setTempMax);
|
|
|
+ Serial.print("tempLow: ");
|
|
|
+ Serial.print(setTempLow);
|
|
|
+ Serial.print("tempLow2: ");
|
|
|
+ Serial.print(setTempLow2);
|
|
|
+ Serial.print("tempDec: ");
|
|
|
+ Serial.println(setTempDecreaseVal);
|
|
|
+ Serial.print("hyst: ");
|
|
|
+ Serial.println(hysteresis);
|
|
|
+ Serial.print("tempCorr: ");
|
|
|
+ Serial.println(tempCorrVal);
|
|
|
+ Serial.print("humCorr: ");
|
|
|
+ Serial.println(humCorrVal);
|
|
|
+ Serial.print("measInt: ");
|
|
|
+ Serial.println(measureInterval);
|
|
|
+ Serial.print("dispInt: ");
|
|
|
+ Serial.println(displayInterval);
|
|
|
+ Serial.print("dispTout: ");
|
|
|
+ Serial.println(displayTimeout);
|
|
|
+ Serial.print("modename0: ");
|
|
|
+ Serial.println(modename0);
|
|
|
+ Serial.print("modename1: ");
|
|
|
+ Serial.println(modename1);
|
|
|
+ Serial.print("psetname0: ");
|
|
|
+ Serial.println(psetname0);
|
|
|
+ Serial.print("psetname1: ");
|
|
|
+ Serial.println(psetname1);
|
|
|
+ Serial.print("psetname2: ");
|
|
|
+ Serial.println(psetname2);
|
|
|
+ Serial.print("offMsg: ");
|
|
|
+ Serial.println(offMessage);
|
|
|
+ Serial.print("PIRenDisp: ");
|
|
|
+ Serial.println(PIR_enablesDisplay);
|
|
|
+ Serial.print("togTHdisp: ");
|
|
|
+ Serial.println(togglingTempHumAIDisplay);
|
|
|
+ Serial.println();
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+boolean loadConfig() { // loadConfig 1
|
|
|
+ if (SPIFFS.exists("/conf.json")) {
|
|
|
+ File configFile = SPIFFS.open("/conf.json", "r");
|
|
|
+ if (!configFile) {
|
|
|
+ Serial.println("ERR: Failed to open file /conf.json");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Serial.println("file /conf.json opened");
|
|
|
+ size_t size = configFile.size();
|
|
|
+
|
|
|
+ Serial.print("file size: ");
|
|
|
+ Serial.println(size);
|
|
|
+
|
|
|
+ // 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 > 1000) {
|
|
|
+ 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<1050> jsonBuffer;
|
|
|
+ JsonObject& json = jsonBuffer.parseObject(buf.get());
|
|
|
+
|
|
|
+ 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(http_token, json["httpToken"] | "", 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);
|
|
|
+
|
|
|
+ if (atoi(json["outRet"] | "") == 1) mqtt_outRetain = true;
|
|
|
+ else mqtt_outRetain = false;
|
|
|
+
|
|
|
+ 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(mqtt_connMsg, json["connMsg"] | "", 31);
|
|
|
+ strlcpy(domoticz_out_topic, json["domOutTop"] | "", 51);
|
|
|
+
|
|
|
+ Serial.println("Loaded config values:");
|
|
|
+ printConfig();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ configFile.close();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Serial.println("file /config.json file does not exist");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+} // loadConfig 1
|
|
|
+
|
|
|
+boolean loadConfig2() {
|
|
|
+ if (SPIFFS.exists("/conf2.json")) {
|
|
|
+ File configFile = SPIFFS.open("/conf2.json", "r");
|
|
|
+ if (!configFile) {
|
|
|
+ Serial.println("ERR: Failed to open file /conf2.json");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Serial.println("file /conf2.json opened");
|
|
|
+ size_t size = configFile.size();
|
|
|
+ Serial.print("file size: ");
|
|
|
+ Serial.println(size);
|
|
|
+ if (size > 1000) {
|
|
|
+ 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.
|
|
|
+ configFile.readBytes(buf.get(), size);
|
|
|
+
|
|
|
+ StaticJsonBuffer<1050> jsonBuffer;
|
|
|
+ JsonObject& json = jsonBuffer.parseObject(buf.get());
|
|
|
+
|
|
|
+ if (!json.success()) {
|
|
|
+ Serial.println("Failed to parse config file");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ domoticzIdx_Thermostat = atoi(json["domIdxTherm"] | "");
|
|
|
+ domoticzIdx_ThermostatMode = atoi(json["domIdxMode"] | "");
|
|
|
+ domoticzIdx_TempHumSensor = atoi(json["domIdxTempHum"] | "");
|
|
|
+ domoticzIdx_Heating = atoi(json["domIdxHeating"] | "");
|
|
|
+
|
|
|
+ domoticzIdx_PIR = atoi(json["domIdxPIR"] | "");
|
|
|
+ strlcpy(outTemp_topic_in, json["outTempTop"] | "", 51);
|
|
|
+ strlcpy(outHum_topic_in, json["outHumTop"] | "", 51);
|
|
|
+ strlcpy(mqtt_topic_pir, json["PIRTop"] | "", 51);
|
|
|
+
|
|
|
+ if (atoi(json["autoSaveTemp"] | "") == 1) autoSaveSetTemp = true;
|
|
|
+ else autoSaveSetTemp = false;
|
|
|
+
|
|
|
+ if (atoi(json["autoSaveMode"] | "") == 1) autoSaveHeatingMode = true;
|
|
|
+ else autoSaveHeatingMode = false;
|
|
|
+
|
|
|
+ heatingMinOffTime = atoi(json["minOffTime"] | "");
|
|
|
+ setTempMin = atof(json["tempMin"] | "");
|
|
|
+ setTempMax = atof(json["tempMax"] | "");
|
|
|
+ setTempLow = atof(json["tempLow"] | "");
|
|
|
+ setTempLow2 = atof(json["tempLow2"] | "");
|
|
|
+ setTempDecreaseVal = atof(json["tempDec"] | "");
|
|
|
+ hysteresis = atof(json["hyst"] | "");
|
|
|
+ tempCorrVal = atof(json["tempCorr"] | "");
|
|
|
+ humCorrVal = atoi(json["humCorr"] | "");
|
|
|
+ measureInterval = atoi(json["measInt"] | "");
|
|
|
+ displayInterval = atoi(json["dispInt"] | "");
|
|
|
+ displayInterval_saved = displayInterval;
|
|
|
+ displayTimeout = atoi(json["dispTout"] | "");
|
|
|
+ strlcpy(modename0, json["modename0"] | "", 14);
|
|
|
+ strlcpy(modename1, json["modename1"] | "", 14);
|
|
|
+ strlcpy(psetname0, json["psetname0"] | "", 14);
|
|
|
+ strlcpy(psetname1, json["psetname1"] | "", 14);
|
|
|
+ strlcpy(psetname2, json["psetname2"] | "", 14);
|
|
|
+ strlcpy(offMessage, json["offMsg"] | "", 14);
|
|
|
+
|
|
|
+ if (atoi(json["PIRenDisp"] | "") == 1) PIR_enablesDisplay = true;
|
|
|
+ else PIR_enablesDisplay = false;
|
|
|
+
|
|
|
+ if (atoi(json["togTHdisp"] | "") == 1) togglingTempHumAIDisplay = true;
|
|
|
+ else togglingTempHumAIDisplay = false;
|
|
|
+
|
|
|
+ Serial.println("Loaded config values:");
|
|
|
+ printConfig2();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Serial.println("file /conf2.json file does not exist");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+} //loadConfig2
|
|
|
+
|
|
|
+
|
|
|
+boolean loadSetTemp() { // loadSetTemp
|
|
|
+ File configFile = SPIFFS.open("/setTemp", "r");
|
|
|
+ if (!configFile) {
|
|
|
+ Serial.println("ERR: Failed to open file /setTemp");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String s = configFile.readStringUntil('\n');
|
|
|
+ configFile.close();
|
|
|
+ float tmpSetTemp = s.toFloat();
|
|
|
+ if ( tmpSetTemp >= setTempMin && tmpSetTemp <= setTempMax ) {
|
|
|
+ setTemp = tmpSetTemp;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else return false;
|
|
|
+} // loadSetTemp
|
|
|
+
|
|
|
+
|
|
|
+boolean loadHeatingMode() { // loadHeatingMode
|
|
|
+ File configFile = SPIFFS.open("/heatingMode", "r");
|
|
|
+ if (!configFile) {
|
|
|
+ Serial.println("ERR: Failed to open file /heatingMode");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String s = configFile.readStringUntil('\n');
|
|
|
+ configFile.close();
|
|
|
+ int tmpHeatingMode = s.toInt();
|
|
|
+ if ( tmpHeatingMode >= 0 && tmpHeatingMode <= 1 ) {
|
|
|
+ heatingMode = tmpHeatingMode;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else return false;
|
|
|
+} // loadHeatingMode
|
|
|
+
|
|
|
+boolean loadPreset() { // loadPreset
|
|
|
+ File configFile = SPIFFS.open("/preset", "r");
|
|
|
+ if (!configFile) {
|
|
|
+ Serial.println("ERR: Failed to open file /preset");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String s = configFile.readStringUntil('\n');
|
|
|
+ configFile.close();
|
|
|
+ int tmpPreset = s.toInt();
|
|
|
+ if ( tmpPreset >= 0 && tmpPreset <= 2 ) {
|
|
|
+ preset = tmpPreset;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else return false;
|
|
|
+} // loadPreset
|
|
|
+
|
|
|
+boolean saveConfig() { // safeConfig
|
|
|
+ StaticJsonBuffer<1050> jsonBuffer;
|
|
|
+ JsonObject& json = jsonBuffer.createObject();
|
|
|
+
|
|
|
+ json["devName"] = deviceName;
|
|
|
+ json["httpUser"] = http_user;
|
|
|
+ json["httpPass"] = http_pass;
|
|
|
+ json["httpToken"] = http_token;
|
|
|
+ json["mqttHost"] = mqtt_server;
|
|
|
+ json["mqttPort"] = mqtt_port;
|
|
|
+ json["mqttUser"] = mqtt_user;
|
|
|
+ json["mqttPass"] = mqtt_pass;
|
|
|
+ json["inTop"] = mqtt_topic_in;
|
|
|
+ json["outTop"] = mqtt_topic_out;
|
|
|
+
|
|
|
+ if (mqtt_outRetain) json["outRet"] = 1;
|
|
|
+ else json["outRet"] = 0;
|
|
|
+
|
|
|
+ json["willTop"] = mqtt_willTopic;
|
|
|
+ json["willQos"] = mqtt_willQos;
|
|
|
+
|
|
|
+ if (mqtt_willRetain) json["willRet"] = 1;
|
|
|
+ else json["willRet"] = 0;
|
|
|
+
|
|
|
+ json["willMsg"] = mqtt_willMsg;
|
|
|
+ json["connMsg"] = mqtt_connMsg;
|
|
|
+ json["domOutTop"] = domoticz_out_topic;
|
|
|
+
|
|
|
+ yield();
|
|
|
+
|
|
|
+ File configFile = SPIFFS.open("/conf.json", "w");
|
|
|
+ if (!configFile) {
|
|
|
+ Serial.println("Failed to open conf file for writing");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ json.printTo(configFile);
|
|
|
+ configFile.close();
|
|
|
+ return true;
|
|
|
+} // safeConfig
|
|
|
+
|
|
|
+
|
|
|
+boolean saveConfig2() { // safeConfig2
|
|
|
+ StaticJsonBuffer<1050> jsonBuffer;
|
|
|
+ JsonObject& json = jsonBuffer.createObject();
|
|
|
+
|
|
|
+ json["domIdxTherm"] = domoticzIdx_Thermostat;
|
|
|
+ json["domIdxMode"] = domoticzIdx_ThermostatMode;
|
|
|
+ json["domIdxTempHum"] = domoticzIdx_TempHumSensor;
|
|
|
+ json["domIdxHeating"] = domoticzIdx_Heating;
|
|
|
+ json["domIdxPIR"] = domoticzIdx_PIR;
|
|
|
+ json["outTempTop"] = outTemp_topic_in;
|
|
|
+ json["outHumTop"] = outHum_topic_in;
|
|
|
+ json["PIRTop"] = mqtt_topic_pir;
|
|
|
+
|
|
|
+ if (autoSaveSetTemp) json["autoSaveTemp"] = 1;
|
|
|
+ else json["autoSaveTemp"] = 0;
|
|
|
+
|
|
|
+ if (autoSaveHeatingMode) json["autoSaveMode"] = 1;
|
|
|
+ else json["autoSaveMode"] = 0;
|
|
|
+
|
|
|
+ json["minOffTime"] = heatingMinOffTime;
|
|
|
+ json["tempMin"] = setTempMin;
|
|
|
+ json["tempMax"] = setTempMax;
|
|
|
+ json["tempLow"] = setTempLow;
|
|
|
+ json["tempLow2"] = setTempLow2;
|
|
|
+ json["tempDec"] = setTempDecreaseVal;
|
|
|
+ json["hyst"] = hysteresis;
|
|
|
+ json["tempCorr"] = tempCorrVal;
|
|
|
+ json["humCorr"] = humCorrVal;
|
|
|
+ json["measInt"] = measureInterval;
|
|
|
+ json["dispInt"] = displayInterval;
|
|
|
+ json["dispTout"] = displayTimeout;
|
|
|
+
|
|
|
+ json["modename0"] = modename0;
|
|
|
+ json["modename1"] = modename1;
|
|
|
+ json["psetname0"] = psetname0;
|
|
|
+ json["psetname1"] = psetname1;
|
|
|
+ json["psetname2"] = psetname2;
|
|
|
+ json["offMsg"] = offMessage;
|
|
|
+
|
|
|
+ if (PIR_enablesDisplay) json["PIRenDisp"] = 1;
|
|
|
+ else json["PIRenDisp"] = 0;
|
|
|
+
|
|
|
+ if (togglingTempHumAIDisplay) json["togTHdisp"] = 1;
|
|
|
+ else json["togTHdisp"] = 0;
|
|
|
+
|
|
|
+ yield();
|
|
|
+
|
|
|
+ File configFile = SPIFFS.open("/conf2.json", "w");
|
|
|
+ if (!configFile) {
|
|
|
+ Serial.println("Failed to open conf2 file for writing");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ json.printTo(configFile);
|
|
|
+ configFile.close();
|
|
|
+ return true;
|
|
|
+} // safeConfig2
|
|
|
+
|
|
|
+
|
|
|
+boolean saveSetTemp() { // saveSetTemp
|
|
|
+ File configFile = SPIFFS.open("/setTemp", "w");
|
|
|
+ if (!configFile) {
|
|
|
+ Serial.println("Failed to open setTemp file for writing");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ configFile.println(setTemp);
|
|
|
+ configFile.close();
|
|
|
+ setTempSaved = setTemp;
|
|
|
+ return true;
|
|
|
+} // saveSetTemp
|
|
|
+
|
|
|
+boolean saveHeatingMode() { // saveHeatingMode
|
|
|
+ File configFile = SPIFFS.open("/heatingMode", "w");
|
|
|
+ if (!configFile) {
|
|
|
+ Serial.println("Failed to open heatingMode file for writing");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ configFile.println(heatingMode);
|
|
|
+ configFile.close();
|
|
|
+ heatingModeSaved = heatingMode;
|
|
|
+ return true;
|
|
|
+} // saveHeatingMode
|
|
|
+
|
|
|
+
|
|
|
+boolean savePreset() { // savePreset
|
|
|
+ File configFile = SPIFFS.open("/preset", "w");
|
|
|
+ if (!configFile) {
|
|
|
+ Serial.println("Failed to open preset file for writing");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ configFile.println(preset);
|
|
|
+ configFile.close();
|
|
|
+ presetSaved = preset;
|
|
|
+ return true;
|
|
|
+} // savePreset
|
|
|
+
|
|
|
+
|
|
|
+void checkSaveConfigTriggered() {
|
|
|
+ if (saveConfigToFlash) {
|
|
|
+ saveConfigToFlash = false;
|
|
|
+ saveConfig();
|
|
|
+ }
|
|
|
+ if (saveConfig2ToFlash) {
|
|
|
+ saveConfig2ToFlash = false;
|
|
|
+ saveConfig2();
|
|
|
+ }
|
|
|
+ // if (saveSetTempToFlash) {
|
|
|
+ // saveSetTempToFlash = false;
|
|
|
+ // saveSetTemp();
|
|
|
+ // }
|
|
|
+ // if (saveHeatingModeToFlash) {
|
|
|
+ // saveHeatingModeToFlash = false;
|
|
|
+ // saveHeatingMode();
|
|
|
+ // }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void deleteConfig() {
|
|
|
+ Serial.println("deleting configuration");
|
|
|
+ if (SPIFFS.remove("/formatComplete.txt")) {
|
|
|
+ Serial.println("config will be deleted after reboot");
|
|
|
+ delay(100);
|
|
|
+ ESP.restart();
|
|
|
+ }
|
|
|
+}
|