// sets the corresponding config variable for 'param' to new value // does not trigger saving to flash // does not distinguish between config sets as they are only split on flash and // in web interface called from commands: // serial command: set [param] [value] // MQTT cmd topic, payload "set [param] [value]" // -> must be committed by command 'save' after all desired values are set // called from web interface setConf functions, which also saves the changed // conf set to flash immediately void setConfig(char *param, char *value) { if (confLog.logLevelSerial >= LOGLEVEL_VERBOSE) { Serial.print("setConfig - '"); Serial.print(param); Serial.print("' to '"); Serial.print(value); Serial.println("'"); } //char param_l[15]; strlwr(param); // values if (strcmp(param, "temp") == 0) { float valueFloat = round(atof(value) * 2.0) / 2.0; setTempTo(valueFloat); } else if (strcmp(param, "templow") == 0) { float valueFloat = round(atof(value) * 2.0) / 2.0; setTempLowTo(valueFloat); } else if (strcmp(param, "templow2") == 0) { float valueFloat = round(atof(value) * 2.0) / 2.0; setTempLow2To(valueFloat); } else if (strcmp(param, "mode") == 0) { int val = atoi(value); if (val >= 0 && val <= 1) { setHeatingmodeTo(val); } } else if (strcmp(param, "preset") == 0) { int val = atoi(value); if (val >= 0 && val <= 2) { setPresetTo(val); } } // confDevWiFi else if (strcmp(param, "devname") == 0) { if (strcmp(value, confDevWiFi.deviceName) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confDevWiFi.deviceName, "", sizeof(confDevWiFi.deviceName)); configChangedRestartRequired = true; confDevWiFi.wasChanged = true; } else { if (strlen(value) >= 4) { strlcpy(confDevWiFi.deviceName, value, sizeof(confDevWiFi.deviceName)); configChangedRestartRequired = true; confDevWiFi.wasChanged = true; } } } } else if (strcmp(param, "hostname") == 0) { if (strcmp(value, confDevWiFi.hostName) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confDevWiFi.hostName, "", sizeof(confDevWiFi.hostName)); configChangedRestartRequired = true; confDevWiFi.wasChanged = true; } else { if (strlen(value) >= 4) { strlcpy(confDevWiFi.hostName, value, sizeof(confDevWiFi.hostName)); configChangedRestartRequired = true; confDevWiFi.wasChanged = true; } } } } else if (strcmp(param, "ssid1") == 0) { if (strcmp(value, confDevWiFi.WiFiSSID1) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confDevWiFi.WiFiSSID1, "", sizeof(confDevWiFi.WiFiSSID1)); configChangedRestartRequired = true; confDevWiFi.wasChanged = true; } else { strlcpy(confDevWiFi.WiFiSSID1, value, sizeof(confDevWiFi.WiFiSSID1)); configChangedRestartRequired = true; confDevWiFi.wasChanged = true; } } } else if (strcmp(param, "wpw1") == 0) { if (strcmp(value, confDevWiFi.WiFiPW1) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confDevWiFi.WiFiPW1, "", sizeof(confDevWiFi.WiFiPW1)); configChangedRestartRequired = true; confDevWiFi.wasChanged = true; } else { if (!strcmp(value, "****") == 0) { strlcpy(confDevWiFi.WiFiPW1, value, sizeof(confDevWiFi.WiFiPW1)); configChangedRestartRequired = true; confDevWiFi.wasChanged = true; } } } } else if (strcmp(param, "ssid2") == 0) { if (strcmp(value, confDevWiFi.WiFiSSID2) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confDevWiFi.WiFiSSID2, "", sizeof(confDevWiFi.WiFiSSID2)); configChangedRestartRequired = true; confDevWiFi.wasChanged = true; } else { strlcpy(confDevWiFi.WiFiSSID2, value, sizeof(confDevWiFi.WiFiSSID2)); configChangedRestartRequired = true; confDevWiFi.wasChanged = true; } } } else if (strcmp(param, "wpw2") == 0) { if (strcmp(value, confDevWiFi.WiFiPW2) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confDevWiFi.WiFiPW2, "", sizeof(confDevWiFi.WiFiPW2)); configChangedRestartRequired = true; confDevWiFi.wasChanged = true; } else { if (!strcmp(value, "****") == 0) { strlcpy(confDevWiFi.WiFiPW2, value, sizeof(confDevWiFi.WiFiPW2)); configChangedRestartRequired = true; confDevWiFi.wasChanged = true; } } } } else if (strcmp(param, "wpwap") == 0) { if (strcmp(value, confDevWiFi.WiFiAPModePassword) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confDevWiFi.WiFiAPModePassword, "", sizeof(confDevWiFi.WiFiAPModePassword)); confDevWiFi.wasChanged = true; } else { if (!strcmp(value, "****") == 0) { strlcpy(confDevWiFi.WiFiAPModePassword, value, sizeof(confDevWiFi.WiFiAPModePassword)); confDevWiFi.wasChanged = true; } } } } else if (strcmp(param, "waptout") == 0) { int tmpval = atoi(value); if (tmpval != confDevWiFi.WiFiAPModeTimeout) { if (tmpval >= 0 && tmpval <= 120) { confDevWiFi.WiFiAPModeTimeout = tmpval; confDevWiFi.wasChanged = true; } } } else if (strcmp(param, "wconncheck") == 0) { int tmpval = atoi(value); if (tmpval != confDevWiFi.WiFiConnCheckInterval) { if (tmpval == 0) { confDevWiFi.WiFiConnCheckInterval = 0; confDevWiFi.wasChanged = true; } else { if (tmpval >= 10 && tmpval <= 3600) { confDevWiFi.WiFiConnCheckInterval = tmpval; confDevWiFi.wasChanged = true; } } } } else if (strcmp(param, "wretry") == 0) { int tmpval = atoi(value); if (tmpval != confDevWiFi.WiFiRetryInterval) { if (tmpval >= 0 && tmpval <= 120) { confDevWiFi.WiFiRetryInterval = tmpval; confDevWiFi.wasChanged = true; } } } else if (strcmp(param, "wreboot") == 0) { int tmpval = atoi(value); if (tmpval != confDevWiFi.WiFiRebootOnNoConnect) { if (tmpval >= 0 && tmpval <= 2880) { confDevWiFi.WiFiRebootOnNoConnect = tmpval; confDevWiFi.wasChanged = true; } } } // confWeb else if (strcmp(param, "apitoken") == 0) { if (strcmp(value, confWeb.http_token) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confWeb.http_token, "", sizeof(confWeb.http_token)); confWeb.wasChanged = true; } else { if (!strcmp(value, "****") == 0) { strlcpy(confWeb.http_token, value, sizeof(confWeb.http_token)); confWeb.wasChanged = true; } } } } else if (strcmp(param, "httpua") == 0) { if (strcmp(value, confWeb.http_user) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confWeb.http_user, "", sizeof(confWeb.http_user)); confWeb.wasChanged = true; } else { strlcpy(confWeb.http_user, value, sizeof(confWeb.http_user)); confWeb.wasChanged = true; } } } else if (strcmp(param, "httppa") == 0) { if (strcmp(value, confWeb.http_pass) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confWeb.http_pass, "", sizeof(confWeb.http_pass)); confWeb.wasChanged = true; } else { if (!strcmp(value, "****") == 0) { strlcpy(confWeb.http_pass, value, sizeof(confWeb.http_pass)); confWeb.wasChanged = true; } } } } else if (strcmp(param, "httpauth") == 0) { bool tmpval; if (atoi(value) == 1) tmpval = true; else tmpval = false; if (confWeb.http_user_auth != tmpval) { confWeb.http_user_auth = tmpval; confWeb.wasChanged = true; } } else if (strcmp(param, "httpu1") == 0) { if (strcmp(value, confWeb.http_user1) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confWeb.http_user1, "", sizeof(confWeb.http_user1)); confWeb.wasChanged = true; } else { strlcpy(confWeb.http_user1, value, sizeof(confWeb.http_user1)); confWeb.wasChanged = true; } } } else if (strcmp(param, "httpp1") == 0) { if (strcmp(value, confWeb.http_pass1) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confWeb.http_pass1, "", sizeof(confWeb.http_pass1)); confWeb.wasChanged = true; } else { if (!strcmp(value, "****") == 0) { strlcpy(confWeb.http_pass1, value, sizeof(confWeb.http_pass1)); confWeb.wasChanged = true; } } } } else if (strcmp(param, "httpu2") == 0) { if (strcmp(value, confWeb.http_user2) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confWeb.http_user2, "", sizeof(confWeb.http_user2)); confWeb.wasChanged = true; } else { strlcpy(confWeb.http_user2, value, sizeof(confWeb.http_user2)); confWeb.wasChanged = true; } } } else if (strcmp(param, "httpp2") == 0) { if (strcmp(value, confWeb.http_pass2) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confWeb.http_pass2, "", sizeof(confWeb.http_pass2)); confWeb.wasChanged = true; } else { if (!strcmp(value, "****") == 0) { strlcpy(confWeb.http_pass2, value, sizeof(confWeb.http_pass2)); confWeb.wasChanged = true; } } } } else if (strcmp(param, "wconsole") == 0) { bool tmpval; if (atoi(value) == 1) tmpval = true; else tmpval = false; if (confWeb.wConsole != tmpval) { confWeb.wConsole = tmpval; configChangedRestartRequired = true; confWeb.wasChanged = true; } } else if (strcmp(param, "wsconsole") == 0) { bool tmpval; if (atoi(value) == 1) tmpval = true; else tmpval = false; if (confWeb.wsConsole != tmpval) { confWeb.wsConsole = tmpval; configChangedRestartRequired = true; confWeb.wasChanged = true; } } // confMqtt else if (strcmp(param, "mqttenable") == 0) { bool tmpval; if (atoi(value) == 1) tmpval = true; else tmpval = false; if (confMqtt.mqtt_enable != tmpval) { confMqtt.mqtt_enable = tmpval; configChangedMqttConnResetRequired = true; confMqtt.wasChanged = true; } } else if (strcmp(param, "mqtthost") == 0) { if (strcmp(value, confMqtt.mqtt_server) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confMqtt.mqtt_server, "", sizeof(confMqtt.mqtt_server)); configChangedMqttConnResetRequired = true; confMqtt.wasChanged = true; } else { strlcpy(confMqtt.mqtt_server, value, sizeof(confMqtt.mqtt_server)); configChangedMqttConnResetRequired = true; confMqtt.wasChanged = true; } } } else if (strcmp(param, "mqttport") == 0) { if (atoi(value) != confMqtt.mqtt_port) { confMqtt.mqtt_port = atoi(value); configChangedMqttConnResetRequired = true; confMqtt.wasChanged = true; } } else if (strcmp(param, "mqttuser") == 0) { if (strcmp(value, confMqtt.mqtt_user) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confMqtt.mqtt_user, "", sizeof(confMqtt.mqtt_user)); configChangedMqttConnResetRequired = true; confMqtt.wasChanged = true; } else { strlcpy(confMqtt.mqtt_user, value, sizeof(confMqtt.mqtt_user)); configChangedMqttConnResetRequired = true; confMqtt.wasChanged = true; } } } else if (strcmp(param, "mqttpass") == 0) { if (strcmp(value, confMqtt.mqtt_pass) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confMqtt.mqtt_pass, "", sizeof(confMqtt.mqtt_pass)); configChangedMqttConnResetRequired = true; confMqtt.wasChanged = true; } else { if (!strcmp(value, "****") == 0) { strlcpy(confMqtt.mqtt_pass, value, sizeof(confMqtt.mqtt_pass)); configChangedMqttConnResetRequired = true; confMqtt.wasChanged = true; } } } } else if (strcmp(param, "intop") == 0) { if (strcmp(value, confMqtt.mqtt_topic_in) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confMqtt.mqtt_topic_in, "", sizeof(confMqtt.mqtt_topic_in)); configChangedMqttConnResetRequired = true; confMqtt.wasChanged = true; } else { strlcpy(confMqtt.mqtt_topic_in, value, sizeof(confMqtt.mqtt_topic_in)); configChangedMqttConnResetRequired = true; confMqtt.wasChanged = true; } } } else if (strcmp(param, "outtop") == 0) { if (strcmp(value, confMqtt.mqtt_topic_out) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confMqtt.mqtt_topic_out, "", sizeof(confMqtt.mqtt_topic_out)); confMqtt.wasChanged = true; } else { strlcpy(confMqtt.mqtt_topic_out, value, sizeof(confMqtt.mqtt_topic_out)); confMqtt.wasChanged = true; } } } else if (strcmp(param, "outret") == 0) { bool tmpval; if (atoi(value) == 1) tmpval = true; else tmpval = false; if (confMqtt.mqtt_outRetain != tmpval) { confMqtt.mqtt_outRetain = tmpval; confMqtt.wasChanged = true; if (tmpval == false) { publishDeleteRetainedOutMessages(); } } } else if (strcmp(param, "outretsens") == 0) { bool tmpval; if (atoi(value) == 1) tmpval = true; else tmpval = false; if (confMqtt.mqtt_outRetain_sensors != tmpval) { confMqtt.mqtt_outRetain_sensors = tmpval; confMqtt.wasChanged = true; if (tmpval == false) { publishDeleteRetainedOutMessages_sensors(); } } } else if (strcmp(param, "outpubint") == 0) { if (atoi(value) != confMqtt.mqtt_outPubInterval) { confMqtt.mqtt_outPubInterval = atoi(value); confMqtt.wasChanged = true; } } else if (strcmp(param, "outpubintsens") == 0) { if (atoi(value) != confMqtt.mqtt_outPubInterval_sensors) { confMqtt.mqtt_outPubInterval_sensors = atoi(value); confMqtt.wasChanged = true; } } else if (strcmp(param, "willtop") == 0) { if (strcmp(value, confMqtt.mqtt_willTopic) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confMqtt.mqtt_willTopic, "", sizeof(confMqtt.mqtt_willTopic)); configChangedMqttConnResetRequired = true; confMqtt.wasChanged = true; } else { strlcpy(confMqtt.mqtt_willTopic, value, sizeof(confMqtt.mqtt_willTopic)); configChangedMqttConnResetRequired = true; confMqtt.wasChanged = true; } } } else if (strcmp(param, "willqos") == 0) { int tmpval = atoi(value); if (tmpval != confMqtt.mqtt_willQos) { if (tmpval >= 0 && tmpval <= 2) { confMqtt.mqtt_willQos = tmpval; configChangedMqttConnResetRequired = true; confMqtt.wasChanged = true; } } } else if (strcmp(param, "willret") == 0) { bool tmpval; if (atoi(value) == 1) tmpval = true; else tmpval = false; if (confMqtt.mqtt_willRetain != tmpval) { confMqtt.mqtt_willRetain = tmpval; configChangedMqttConnResetRequired = true; confMqtt.wasChanged = true; } } else if (strcmp(param, "willmsg") == 0) { if (strcmp(value, confMqtt.mqtt_willMsg) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confMqtt.mqtt_willMsg, "", sizeof(confMqtt.mqtt_willMsg)); configChangedMqttConnResetRequired = true; confMqtt.wasChanged = true; } else { strlcpy(confMqtt.mqtt_willMsg, value, sizeof(confMqtt.mqtt_willMsg)); configChangedMqttConnResetRequired = true; confMqtt.wasChanged = true; } } } else if (strcmp(param, "connmsg") == 0) { if (strcmp(value, confMqtt.mqtt_connMsg) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confMqtt.mqtt_connMsg, "", sizeof(confMqtt.mqtt_connMsg)); configChangedMqttConnResetRequired = true; confMqtt.wasChanged = true; } else { strlcpy(confMqtt.mqtt_connMsg, value, sizeof(confMqtt.mqtt_connMsg)); configChangedMqttConnResetRequired = true; confMqtt.wasChanged = true; } } } else if (strcmp(param, "hbenable") == 0) { bool tmpval; if (atoi(value) == 1) tmpval = true; else tmpval = false; if (confMqtt.mqtt_enable_heartbeat != tmpval) { confMqtt.mqtt_enable_heartbeat = tmpval; confMqtt.wasChanged = true; } } else if (strcmp(param, "hbreconn") == 0) { unsigned int tmpval = atoi(value); if ((tmpval * 60000) != confMqtt.mqtt_heartbeat_maxage_reconnect) { if (tmpval == 0) { confMqtt.mqtt_heartbeat_maxage_reconnect = 0; confMqtt.wasChanged = true; } else if (tmpval >= 2 && tmpval <= 10) { confMqtt.mqtt_heartbeat_maxage_reconnect = tmpval * 60000; confMqtt.wasChanged = true; } } } else if (strcmp(param, "hbreboot") == 0) { unsigned int tmpval = atoi(value); if ((tmpval * 60000) != confMqtt.mqtt_heartbeat_maxage_reboot) { if (tmpval == 0) { confMqtt.mqtt_heartbeat_maxage_reboot = 0; confMqtt.wasChanged = true; } else if (tmpval >= 10 && tmpval <= 120) { confMqtt.mqtt_heartbeat_maxage_reboot = tmpval * 60000; confMqtt.wasChanged = true; } } } // confBas else if (strcmp(param, "autosavetemp") == 0) { bool tmpval; if (atoi(value) == 1) tmpval = true; else tmpval = false; if (confBas.autoSaveSetTemp != tmpval) { confBas.autoSaveSetTemp = tmpval; confBas.wasChanged = true; } } else if (strcmp(param, "autosavemode") == 0) { bool tmpval; if (atoi(value) == 1) tmpval = true; else tmpval = false; if (confBas.autoSaveHeatingMode != tmpval) { confBas.autoSaveHeatingMode = tmpval; confBas.wasChanged = true; } } else if (strcmp(param, "savetomqttret") == 0) { bool tmpval; if (atoi(value) == 1) tmpval = true; else tmpval = false; if (confBas.saveToMqttRetained != tmpval) { confBas.saveToMqttRetained = tmpval; confBas.wasChanged = true; if (tmpval == false) { publishDeleteRetainedSavedStates(); } } } else if (strcmp(param, "tempmin") == 0) { float valueFloat = round(atof(value) * 2.0) / 2.0; if (valueFloat != confBas.setTempMin) { if (valueFloat >= 10 && valueFloat <= 16) { confBas.setTempMin = valueFloat; confBas.wasChanged = true; } } } else if (strcmp(param, "tempmax") == 0) { float valueFloat = round(atof(value) * 2.0) / 2.0; if (valueFloat != confBas.setTempMax) { if (valueFloat >= 18 && valueFloat <= 30) { confBas.setTempMax = valueFloat; confBas.wasChanged = true; } } } else if (strcmp(param, "measint") == 0) { int valueInt = atoi(value); if (valueInt != confBas.measureInterval) { if (valueInt >= 5 && valueInt <= 60) { confBas.measureInterval = valueInt; confBas.wasChanged = true; } } } else if (strcmp(param, "dispint") == 0) { int valueInt = atoi(value); if (valueInt != confBas.displayInterval) { if (valueInt >= 1 && valueInt <= 60) { confBas.displayInterval = valueInt; confBas.wasChanged = true; } } } else if (strcmp(param, "disptout") == 0) { int valueInt = atoi(value); if (valueInt != confBas.displayTimeout) { if (valueInt >= 2 && valueInt <= 3600) { confBas.displayTimeout = valueInt; confBas.wasChanged = true; } } } else if (strcmp(param, "pirendisp") == 0) { bool tmpval; if (atoi(value) == 1) tmpval = true; else tmpval = false; if (tmpval != confBas.PIR_enablesDisplay) { confBas.PIR_enablesDisplay = tmpval; confBas.wasChanged = true; } } else if (strcmp(param, "pirendispps0") == 0) { bool tmpval; if (atoi(value) == 1) tmpval = true; else tmpval = false; if (tmpval != confBas.PIR_enablesDisplay_preset0only) { confBas.PIR_enablesDisplay_preset0only = tmpval; confBas.wasChanged = true; } } else if (strcmp(param, "togthdisp") == 0) { bool tmpval; if (atoi(value) == 1) tmpval = true; else tmpval = false; if (tmpval != confBas.togglingTempHumAIDisplay) { confBas.togglingTempHumAIDisplay = tmpval; confBas.wasChanged = true; } } // confAdv else if (strcmp(param, "minofftime") == 0) { int valueInt = atoi(value); if (valueInt != confAdv.heatingMinOffTime) { confAdv.heatingMinOffTime = valueInt; confAdv.wasChanged = true; } } else if (strcmp(param, "tempdec") == 0) { float valueFloat = atof(value); if (valueFloat != confAdv.setTempDecreaseVal) { if (valueFloat >= 0.0 && valueFloat <= 1.5) { confAdv.setTempDecreaseVal = valueFloat; confAdv.wasChanged = true; } } } else if (strcmp(param, "hyst") == 0) { float valueFloat = atof(value); if (valueFloat != confAdv.hysteresis) { if (valueFloat >= 0.1 && valueFloat <= 4.0) { confAdv.hysteresis = valueFloat; confAdv.wasChanged = true; } } } else if (strcmp(param, "tempcorr") == 0) { float valueFloat = atof(value); if (valueFloat != confAdv.tempCorrVal) { if (valueFloat >= -5.0 && valueFloat <= 5.0) { confAdv.tempCorrVal = valueFloat; confAdv.wasChanged = true; } } } else if (strcmp(param, "humcorr") == 0) { int valueInt = atoi(value); if (valueInt != confAdv.humCorrVal) { if (valueInt >= -40 && valueInt <= 40) { confAdv.humCorrVal = valueInt; confAdv.wasChanged = true; } } } else if (strcmp(param, "offmsg") == 0) { if (strcmp(value, confAdv.offMessage) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confAdv.offMessage, "", sizeof(confAdv.offMessage)); confAdv.wasChanged = true; } else { strlcpy(confAdv.offMessage, value, sizeof(confAdv.offMessage)); confAdv.wasChanged = true; } } } else if (strcmp(param, "modename0") == 0) { if (strcmp(value, confAdv.modeName0) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confAdv.modeName0, "", sizeof(confAdv.modeName0)); confAdv.wasChanged = true; } else { strlcpy(confAdv.modeName0, value, sizeof(confAdv.modeName0)); confAdv.wasChanged = true; } } } else if (strcmp(param, "modename1") == 0) { if (strcmp(value, confAdv.modeName1) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confAdv.modeName1, "", sizeof(confAdv.modeName1)); confAdv.wasChanged = true; } else { strlcpy(confAdv.modeName1, value, sizeof(confAdv.modeName1)); confAdv.wasChanged = true; } } } else if (strcmp(param, "psetname0") == 0) { if (strcmp(value, confAdv.psetName0) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confAdv.psetName0, "", sizeof(confAdv.psetName0)); confAdv.wasChanged = true; } else { strlcpy(confAdv.psetName0, value, sizeof(confAdv.psetName0)); confAdv.wasChanged = true; } } } else if (strcmp(param, "psetname1") == 0) { if (strcmp(value, confAdv.psetName1) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confAdv.psetName1, "", sizeof(confAdv.psetName1)); confAdv.wasChanged = true; } else { strlcpy(confAdv.psetName1, value, sizeof(confAdv.psetName1)); confAdv.wasChanged = true; } } } else if (strcmp(param, "psetname2") == 0) { if (strcmp(value, confAdv.psetName2) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confAdv.psetName2, "", sizeof(confAdv.psetName2)); confAdv.wasChanged = true; } else { strlcpy(confAdv.psetName2, value, sizeof(confAdv.psetName2)); confAdv.wasChanged = true; } } } else if (strcmp(param, "itemplab") == 0) { if (strcmp(value, confAdv.iTempLabel) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confAdv.iTempLabel, "I", sizeof(confAdv.iTempLabel)); confAdv.wasChanged = true; } else { strlcpy(confAdv.iTempLabel, value, sizeof(confAdv.iTempLabel)); confAdv.wasChanged = true; } } } else if (strcmp(param, "otemplab") == 0) { if (strcmp(value, confAdv.oTempLabel) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confAdv.oTempLabel, "O", sizeof(confAdv.oTempLabel)); confAdv.wasChanged = true; } else { strlcpy(confAdv.oTempLabel, value, sizeof(confAdv.oTempLabel)); confAdv.wasChanged = true; } } } else if (strcmp(param, "pausetout") == 0) { int valueInt = atoi(value); if (valueInt != confAdv.pauseTout) { if (valueInt >= 0 && valueInt <= 3600) { confAdv.pauseTout = valueInt; confAdv.wasChanged = true; } } } // confAdd else if (strcmp(param, "outtemptop") == 0) { if (strcmp(value, confAdd.outTemp_topic_in) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confAdd.outTemp_topic_in, "", sizeof(confAdd.outTemp_topic_in)); configChangedMqttConnResetRequired = true; confAdd.wasChanged = true; } else { strlcpy(confAdd.outTemp_topic_in, value, sizeof(confAdd.outTemp_topic_in)); configChangedMqttConnResetRequired = true; confAdd.wasChanged = true; } } } else if (strcmp(param, "outhumtop") == 0) { if (strcmp(value, confAdd.outHum_topic_in) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confAdd.outHum_topic_in, "", sizeof(confAdd.outHum_topic_in)); configChangedMqttConnResetRequired = true; confAdd.wasChanged = true; } else { strlcpy(confAdd.outHum_topic_in, value, sizeof(confAdd.outHum_topic_in)); configChangedMqttConnResetRequired = true; confAdd.wasChanged = true; } } } else if (strcmp(param, "pirtop") == 0) { if (strcmp(value, confAdd.mqtt_topic_pir) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confAdd.mqtt_topic_pir, "", sizeof(confAdd.mqtt_topic_pir)); confAdd.wasChanged = true; } else { strlcpy(confAdd.mqtt_topic_pir, value, sizeof(confAdd.mqtt_topic_pir)); confAdd.wasChanged = true; } } } else if (strcmp(param, "pironpld") == 0) { if (strcmp(value, confAdd.mqtt_payload_pir_on) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confAdd.mqtt_payload_pir_on, "", sizeof(confAdd.mqtt_payload_pir_on)); confAdd.wasChanged = true; } else { strlcpy(confAdd.mqtt_payload_pir_on, value, sizeof(confAdd.mqtt_payload_pir_on)); confAdd.wasChanged = true; } } } else if (strcmp(param, "piroffpld") == 0) { if (strcmp(value, confAdd.mqtt_payload_pir_off) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confAdd.mqtt_payload_pir_off, "", sizeof(confAdd.mqtt_payload_pir_off)); confAdd.wasChanged = true; } else { strlcpy(confAdd.mqtt_payload_pir_off, value, sizeof(confAdd.mqtt_payload_pir_off)); confAdd.wasChanged = true; } } } #ifdef ENABLE_FEATURE_NTP_TIME // confTime else if (strcmp(param, "tzstr") == 0) { if (strcmp(value, confTime.timeZoneStr) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confTime.timeZoneStr, "", sizeof(confTime.timeZoneStr)); configChangedRestartRequired = true; confTime.wasChanged = true; } else { strlcpy(confTime.timeZoneStr, value, sizeof(confTime.timeZoneStr)); configChangedRestartRequired = true; confTime.wasChanged = true; } } } else if (strcmp(param, "ntpenable") == 0) { bool tmpval; if (atoi(value) == 1) tmpval = true; else tmpval = false; if (confTime.ntpEnable != tmpval) { confTime.ntpEnable = tmpval; configChangedRestartRequired = true; confTime.wasChanged = true; } } else if (strcmp(param, "ntpserver1") == 0) { if (strcmp(value, confTime.ntpServer1) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confTime.ntpServer1, "", sizeof(confTime.ntpServer1)); configChangedRestartRequired = true; confTime.wasChanged = true; } else { strlcpy(confTime.ntpServer1, value, sizeof(confTime.ntpServer1)); configChangedRestartRequired = true; confTime.wasChanged = true; } } } else if (strcmp(param, "ntpserver2") == 0) { if (strcmp(value, confTime.ntpServer2) != 0) { if (strcmp(value, "0") == 0) { strlcpy(confTime.ntpServer2, "", sizeof(confTime.ntpServer2)); configChangedRestartRequired = true; confTime.wasChanged = true; } else { strlcpy(confTime.ntpServer2, value, sizeof(confTime.ntpServer2)); configChangedRestartRequired = true; confTime.wasChanged = true; } } } else if (strcmp(param, "ntpsyncint") == 0) { unsigned int valueInt = atoi(value) * 60; if (confTime.ntpSyncInterval != valueInt) { confTime.ntpSyncInterval = valueInt; configChangedRestartRequired = true; confTime.wasChanged = true; } } #endif // confLog else if (strcmp(param, "loglevser") == 0) { int valueInt = atoi(value); if (confLog.logLevelSerial != valueInt) { if (valueInt >= 0 && valueInt <= 5) { confLog.logLevelSerial = valueInt; confLog.wasChanged = true; } } } else if (strcmp(param, "loglevweb") == 0) { int valueInt = atoi(value); if (confLog.logLevelWeb != valueInt) { if (valueInt >= 0 && valueInt <= 5) { confLog.logLevelWeb = valueInt; confLog.wasChanged = true; } } } else if (strcmp(param, "loglevmqtt") == 0) { int valueInt = atoi(value); if (confLog.logLevelMqtt != valueInt) { if (valueInt >= 0 && valueInt <= 5) { confLog.logLevelMqtt = valueInt; confLog.wasChanged = true; } } } else if (strcmp(param, "logwebrequests") == 0) { bool tmpval; if (atoi(value) == 1) tmpval = true; else tmpval = false; if (confLog.logWebRequests != tmpval) { confLog.logWebRequests = tmpval; confLog.wasChanged = true; } } getConfig(param); if (confCheckUnsaved()) { lastConfigChange = millis(); lastConfigChangeNoteAlreadyDone = false; } } void getConfig(char *param) { // gets and prints the corresponding config variable for 'param' //if (serialdebug) //{ // Serial.print("getConfig - '"); // Serial.print(param); // Serial.println("'"); //} strlwr(param); int isConfPage = 0; if (strcmp(param, "values") == 0) isConfPage = 100; else if (strcmp(param, "confdevwifi") == 0) isConfPage = 1; else if (strcmp(param, "confdev") == 0) isConfPage = 1; else if (strcmp(param, "confwifi") == 0) isConfPage = 1; else if (strcmp(param, "confweb") == 0) isConfPage = 2; else if (strcmp(param, "confmqtt") == 0) isConfPage = 3; else if (strcmp(param, "confbas") == 0) isConfPage = 4; else if (strcmp(param, "confadv") == 0) isConfPage = 5; else if (strcmp(param, "confadd") == 0) isConfPage = 6; #ifdef ENABLE_FEATURE_NTP_TIME else if (strcmp(param, "conftime") == 0) isConfPage = 7; #endif else if (strcmp(param, "conflog") == 0) isConfPage = 8; char buf[101]; // values if (strcmp(param, "temp") == 0 || isConfPage == 100) { sprintf(buf, "setTemp: %2.1f", setTemp); sendLog(buf); } if (strcmp(param, "templow") == 0 || isConfPage == 100) { sprintf(buf, "setTempLow: %2.1f", setTempLow); sendLog(buf); } if (strcmp(param, "templow2") == 0 || isConfPage == 100) { sprintf(buf, "setTempLow2: %2.1f", setTempLow2); sendLog(buf); } if (strcmp(param, "mode") == 0 || isConfPage == 100) { sprintf(buf, "heatingMode: %d", heatingMode); sendLog(buf); } if (strcmp(param, "preset") == 0 || isConfPage == 100) { sprintf(buf, "preset: %d", preset); sendLog(buf); } // confDevWiFi if (strcmp(param, "devname") == 0 || isConfPage == 1) { sprintf_P(buf, "%s.devName: '%s'", PGMStr_confDevWiFi, confDevWiFi.deviceName); sendLog(buf); } if (strcmp(param, "hostname") == 0 || isConfPage == 1) { sprintf_P(buf, "%s.hostName: '%s'", PGMStr_confDevWiFi, confDevWiFi.hostName); sendLog(buf); } if (strcmp(param, "ssid1") == 0 || isConfPage == 1) { sprintf_P(buf, "%s.SSID1: '%s'", PGMStr_confDevWiFi, confDevWiFi.WiFiSSID1); sendLog(buf); } if (strcmp(param, "wpw1") == 0 || isConfPage == 1) { #ifdef DEBUGMODE sprintf_P(buf, "%s.WPW1: '%s'", PGMStr_confDevWiFi, confDevWiFi.WiFiPW1); #else sprintf_P(buf, "%s.WPW1: '******'", PGMStr_confDevWiFi); #endif sendLog(buf); } if (strcmp(param, "ssid2") == 0 || isConfPage == 1) { sprintf_P(buf, "%s.SSID2: '%s'", PGMStr_confDevWiFi, confDevWiFi.WiFiSSID2); sendLog(buf); } if (strcmp(param, "wpw2") == 0 || isConfPage == 1) { #ifdef DEBUGMODE sprintf_P(buf, "%s.WPW2: '%s'", PGMStr_confDevWiFi, confDevWiFi.WiFiPW2); #else sprintf_P(buf, "%s.WPW2: '******'", PGMStr_confDevWiFi); #endif sendLog(buf); } if (strcmp(param, "wpwap") == 0 || isConfPage == 1) { #ifdef DEBUGMODE sprintf_P(buf, "%s.WPWAp: '%s'", PGMStr_confDevWiFi, confDevWiFi.WiFiAPModePassword); #else sprintf_P(buf, "%s.WPWAp: '******'", PGMStr_confDevWiFi); #endif sendLog(buf); } if (strcmp(param, "waptout") == 0 || isConfPage == 1) { sprintf_P(buf, "%s.WApTout: %d", PGMStr_confDevWiFi, confDevWiFi.WiFiAPModeTimeout); sendLog(buf); } if (strcmp(param, "wconncheck") == 0 || isConfPage == 1) { sprintf_P(buf, "%s.WConnCheck: %d", PGMStr_confDevWiFi, confDevWiFi.WiFiConnCheckInterval); sendLog(buf); } if (strcmp(param, "wretry") == 0 || isConfPage == 1) { sprintf_P(buf, "%s.WRetry: %d", PGMStr_confDevWiFi, confDevWiFi.WiFiRetryInterval); sendLog(buf); } if (strcmp(param, "wreboot") == 0 || isConfPage == 1) { sprintf_P(buf, "%s.WReboot: %d", PGMStr_confDevWiFi, confDevWiFi.WiFiRebootOnNoConnect); sendLog(buf); } //confWeb if (strcmp(param, "apitoken") == 0 || isConfPage == 2) { sprintf_P(buf, "%s.apiToken: '%s'", PGMStr_confWeb, confWeb.http_token); sendLog(buf); } if (strcmp(param, "httpua") == 0 || isConfPage == 2) { sprintf_P(buf, "%s.httpUA: '%s'", PGMStr_confWeb, confWeb.http_user); sendLog(buf); } if (strcmp(param, "httppa") == 0 || isConfPage == 2) { #ifdef DEBUGMODE sprintf_P(buf, "%s.httpPA: '%s'", PGMStr_confWeb, confWeb.http_pass); #else sprintf_P(buf, "%s.httpPA: '****'", PGMStr_confWeb); #endif sendLog(buf); } if (strcmp(param, "httpauth") == 0 || isConfPage == 2) { int tmp; if (confWeb.http_user_auth) tmp = 1; else tmp = 0; sprintf_P(buf, "%s.httpAuth: %d", PGMStr_confWeb, tmp); sendLog(buf); } if (strcmp(param, "httpu1") == 0 || isConfPage == 2) { sprintf_P(buf, "%s.httpU1: '%s'", PGMStr_confWeb, confWeb.http_user1); sendLog(buf); } if (strcmp(param, "httpp1") == 0 || isConfPage == 2) { #ifdef DEBUGMODE sprintf_P(buf, "%s.httpP1: '%s'", PGMStr_confWeb, confWeb.http_pass1); #else sprintf_P(buf, "%s.httpP1: '****'", PGMStr_confWeb); #endif sendLog(buf); } if (strcmp(param, "httpu2") == 0 || isConfPage == 2) { sprintf_P(buf, "%s.httpU2: '%s'", PGMStr_confWeb, confWeb.http_user2); sendLog(buf); } if (strcmp(param, "httpp2") == 0 || isConfPage == 2) { #ifdef DEBUGMODE sprintf_P(buf, "%s.httpP2: '%s'", PGMStr_confWeb, confWeb.http_pass2); #else sprintf_P(buf, "%s.httpP2: '****'", PGMStr_confWeb); #endif sendLog(buf); } if (strcmp(param, "wconsole") == 0 || isConfPage == 2) { int tmp; if (confWeb.wConsole) tmp = 1; else tmp = 0; sprintf_P(buf, "%s.wConsole: %d", PGMStr_confWeb, tmp); sendLog(buf); } if (strcmp(param, "wsconsole") == 0 || isConfPage == 2) { int tmp; if (confWeb.wsConsole) tmp = 1; else tmp = 0; sprintf_P(buf, "%s.wsConsole: %d", PGMStr_confWeb, tmp); sendLog(buf); } //confMqtt if (strcmp(param, "mqttenable") == 0 || isConfPage == 3) { int tmp; if (confMqtt.mqtt_enable) tmp = 1; else tmp = 0; sprintf_P(buf, "%s.mqttEnable: %d", PGMStr_confMqtt, tmp); sendLog(buf); } if (strcmp(param, "mqtthost") == 0 || isConfPage == 3) { sprintf_P(buf, "%s.mqttHost: '%s'", PGMStr_confMqtt, confMqtt.mqtt_server); sendLog(buf); } if (strcmp(param, "mqttport") == 0 || isConfPage == 3) { sprintf_P(buf, "%s.mqttPort: %d", PGMStr_confMqtt, confMqtt.mqtt_port); sendLog(buf); } if (strcmp(param, "mqttuser") == 0 || isConfPage == 3) { sprintf_P(buf, "%s.mqttUser: '%s'", PGMStr_confMqtt, confMqtt.mqtt_user); sendLog(buf); } if (strcmp(param, "mqttpass") == 0 || isConfPage == 3) { #ifdef DEBUGMODE sprintf_P(buf, "%s.mqttPass: '%s'", PGMStr_confMqtt, confMqtt.mqtt_pass); #else sprintf_P(buf, "%s.mqttPass: '****'", PGMStr_confMqtt); #endif sendLog(buf); } if (strcmp(param, "intop") == 0 || isConfPage == 3) { sprintf_P(buf, "%s.inTop: '%s'", PGMStr_confMqtt, confMqtt.mqtt_topic_in); sendLog(buf); } if (strcmp(param, "outtop") == 0 || isConfPage == 3) { sprintf_P(buf, "%s.outTop: '%s'", PGMStr_confMqtt, confMqtt.mqtt_topic_out); sendLog(buf); } if (strcmp(param, "outret") == 0 || isConfPage == 3) { int tmp; if (confMqtt.mqtt_outRetain) tmp = 1; else tmp = 0; sprintf_P(buf, "%s.outRet: %d", PGMStr_confMqtt, tmp); sendLog(buf); } if (strcmp(param, "outretsens") == 0 || isConfPage == 3) { int tmp; if (confMqtt.mqtt_outRetain_sensors) tmp = 1; else tmp = 0; sprintf_P(buf, "%s.outRetSens: %d", PGMStr_confMqtt, tmp); sendLog(buf); } if (strcmp(param, "outpubint") == 0 || isConfPage == 3) { sprintf_P(buf, "%s.outPubInt: %d", PGMStr_confMqtt, confMqtt.mqtt_outPubInterval); sendLog(buf); } if (strcmp(param, "outpubintsens") == 0 || isConfPage == 3) { sprintf_P(buf, "%s.outPubIntSens: %d", PGMStr_confMqtt, confMqtt.mqtt_outPubInterval_sensors); sendLog(buf); } if (strcmp(param, "willtop") == 0 || isConfPage == 3) { sprintf_P(buf, "%s.willTop: '%s'", PGMStr_confMqtt, confMqtt.mqtt_willTopic); sendLog(buf); } if (strcmp(param, "willqos") == 0 || isConfPage == 3) { sprintf_P(buf, "%s.willQos: %d", PGMStr_confMqtt, confMqtt.mqtt_willQos); sendLog(buf); } if (strcmp(param, "willret") == 0 || isConfPage == 3) { int tmp; if (confMqtt.mqtt_willRetain) tmp = 1; else tmp = 0; sprintf_P(buf, "%s.willRet: %d", PGMStr_confMqtt, tmp); sendLog(buf); } if (strcmp(param, "willmsg") == 0 || isConfPage == 3) { sprintf_P(buf, "%s.willMsg: '%s'", PGMStr_confMqtt, confMqtt.mqtt_willMsg); sendLog(buf); } if (strcmp(param, "connmsg") == 0 || isConfPage == 3) { sprintf_P(buf, "%s.connMsg: '%s'", PGMStr_confMqtt, confMqtt.mqtt_connMsg); sendLog(buf); } if (strcmp(param, "hbenable") == 0 || isConfPage == 3) { int tmp; if (confMqtt.mqtt_enable_heartbeat) tmp = 1; else tmp = 0; sprintf_P(buf, "%s.hbEnable: %d", PGMStr_confMqtt, tmp); sendLog(buf); } if (strcmp(param, "hbreconn") == 0 || isConfPage == 3) { sprintf_P(buf, "%s.hbReconn: %lu", PGMStr_confMqtt, confMqtt.mqtt_heartbeat_maxage_reconnect / 60000); sendLog(buf); } if (strcmp(param, "hbreboot") == 0 || isConfPage == 3) { sprintf_P(buf, "%s.hbReboot: %lu", PGMStr_confMqtt, confMqtt.mqtt_heartbeat_maxage_reboot / 60000); sendLog(buf); } // confBas if (strcmp(param, "autosavetemp") == 0 || isConfPage == 4) { int tmp; if (confBas.autoSaveSetTemp) tmp = 1; else tmp = 0; sprintf_P(buf, "%s.autoSaveTemp: %d", PGMStr_confBas, tmp); sendLog(buf); } if (strcmp(param, "autosavemode") == 0 || isConfPage == 4) { int tmp; if (confBas.autoSaveHeatingMode) tmp = 1; else tmp = 0; sprintf_P(buf, "%s.autoSaveMode: %d", PGMStr_confBas, tmp); sendLog(buf); } if (strcmp(param, "savetomqttret") == 0 || isConfPage == 4) { int tmp; if (confBas.saveToMqttRetained) tmp = 1; else tmp = 0; sprintf_P(buf, "%s.savetoMqttRet: %d", PGMStr_confBas, tmp); sendLog(buf); } if (strcmp(param, "tempmin") == 0 || isConfPage == 4) { sprintf_P(buf, "%s.tempMin: '%2.1f'", PGMStr_confBas, confBas.setTempMin); sendLog(buf); } if (strcmp(param, "tempmax") == 0 || isConfPage == 4) { sprintf_P(buf, "%s.tempMax: '%2.1f'", PGMStr_confBas, confBas.setTempMax); sendLog(buf); } if (strcmp(param, "measint") == 0 || isConfPage == 4) { sprintf_P(buf, "%s.measInt: %d", PGMStr_confBas, confBas.measureInterval); sendLog(buf); } if (strcmp(param, "dispint") == 0 || isConfPage == 4) { sprintf_P(buf, "%s.dispInt: %d", PGMStr_confBas, confBas.displayInterval); sendLog(buf); } if (strcmp(param, "disptout") == 0 || isConfPage == 4) { sprintf_P(buf, "%s.dispTout: %d", PGMStr_confBas, confBas.displayTimeout); sendLog(buf); } if (strcmp(param, "pirendisp") == 0 || isConfPage == 4) { int tmp; if (confBas.PIR_enablesDisplay) tmp = 1; else tmp = 0; sprintf_P(buf, "%s.pirEnDisp: %d", PGMStr_confBas, tmp); sendLog(buf); } if (strcmp(param, "pirendispps0") == 0 || isConfPage == 4) { int tmp; if (confBas.PIR_enablesDisplay_preset0only) tmp = 1; else tmp = 0; sprintf_P(buf, "%s.pirEnDispPs0: %d", PGMStr_confBas, tmp); sendLog(buf); } if (strcmp(param, "togthdisp") == 0 || isConfPage == 4) { int tmp; if (confBas.togglingTempHumAIDisplay) tmp = 1; else tmp = 0; sprintf_P(buf, "%s.togTHdisp: %d", PGMStr_confBas, tmp); sendLog(buf); } // confAdv if (strcmp(param, "minofftime") == 0 || isConfPage == 5) { sprintf_P(buf, "%s.minOffTime: %d", PGMStr_confAdv, confAdv.heatingMinOffTime); sendLog(buf); } if (strcmp(param, "tempdec") == 0 || isConfPage == 5) { sprintf_P(buf, "%s.tempDec: %1.2f", PGMStr_confAdv, confAdv.setTempDecreaseVal); sendLog(buf); } if (strcmp(param, "hyst") == 0 || isConfPage == 5) { sprintf_P(buf, "%s.hyst: %1.2f", PGMStr_confAdv, confAdv.hysteresis); sendLog(buf); } if (strcmp(param, "tempcorr") == 0 || isConfPage == 5) { sprintf_P(buf, "%s.tempCorr: %1.2f", PGMStr_confAdv, confAdv.tempCorrVal); sendLog(buf); } if (strcmp(param, "humcorr") == 0 || isConfPage == 5) { sprintf_P(buf, "%s.humCorr: %d", PGMStr_confAdv, confAdv.humCorrVal); sendLog(buf); } if (strcmp(param, "offmsg") == 0 || isConfPage == 5) { sprintf_P(buf, "%s.offMsg: '%s'", PGMStr_confAdv, confAdv.offMessage); sendLog(buf); } if (strcmp(param, "modename0") == 0 || isConfPage == 5) { sprintf_P(buf, "%s.modeName0: '%s'", PGMStr_confAdv, confAdv.modeName0); sendLog(buf); } if (strcmp(param, "modename1") == 0 || isConfPage == 5) { sprintf_P(buf, "%s.modeName1: '%s'", PGMStr_confAdv, confAdv.modeName1); sendLog(buf); } if (strcmp(param, "psetname0") == 0 || isConfPage == 5) { sprintf_P(buf, "%s.psetName0: '%s'", PGMStr_confAdv, confAdv.psetName0); sendLog(buf); } if (strcmp(param, "psetname1") == 0 || isConfPage == 5) { sprintf_P(buf, "%s.psetName1: '%s'", PGMStr_confAdv, confAdv.psetName1); sendLog(buf); } if (strcmp(param, "psetname2") == 0 || isConfPage == 5) { sprintf_P(buf, "%s.psetName2: '%s'", PGMStr_confAdv, confAdv.psetName2); sendLog(buf); } if (strcmp(param, "itemplab") == 0 || isConfPage == 5) { sprintf_P(buf, "%s.iTempLab: '%s'", PGMStr_confAdv, confAdv.iTempLabel); sendLog(buf); } if (strcmp(param, "otemplab") == 0 || isConfPage == 5) { sprintf_P(buf, "%s.oTempLab: '%s'", PGMStr_confAdv, confAdv.oTempLabel); sendLog(buf); } if (strcmp(param, "pausetout") == 0 || isConfPage == 5) { sprintf_P(buf, "%s.pauseTout: %d", PGMStr_confAdv, confAdv.pauseTout); sendLog(buf); } // confAdd if (strcmp(param, "outtemptop") == 0 || isConfPage == 6) { sprintf_P(buf, "%s.outTempTop: '%s'", PGMStr_confAdd, confAdd.outTemp_topic_in); sendLog(buf); } if (strcmp(param, "outhumtop") == 0 || isConfPage == 6) { sprintf_P(buf, "%s.outHumTop: '%s'", PGMStr_confAdd, confAdd.outHum_topic_in); sendLog(buf); } if (strcmp(param, "pirtop") == 0 || isConfPage == 6) { sprintf_P(buf, "%s.PIRTop: '%s'", PGMStr_confAdd, confAdd.mqtt_topic_pir); sendLog(buf); } if (strcmp(param, "pironpld") == 0 || isConfPage == 6) { sprintf_P(buf, "%s.PIROnPld: '%s'", PGMStr_confAdd, confAdd.mqtt_payload_pir_on); sendLog(buf); } if (strcmp(param, "piroffpld") == 0 || isConfPage == 6) { sprintf_P(buf, "%s.PIROffPld: '%s'", PGMStr_confAdd, confAdd.mqtt_payload_pir_off); sendLog(buf); } #ifdef ENABLE_FEATURE_NTP_TIME // confTime if (strcmp(param, "tzstr") == 0 || isConfPage == 7) { sprintf_P(buf, "%s.TZstr: '%s'", PGMStr_confTime, confTime.timeZoneStr); sendLog(buf); } if (strcmp(param, "ntpenable") == 0 || isConfPage == 7) { int tmp; if (confTime.ntpEnable) tmp = 1; else tmp = 0; sprintf_P(buf, "%s.ntpEnable: %d", PGMStr_confTime, tmp); sendLog(buf); } if (strcmp(param, "ntpserver1") == 0 || isConfPage == 7) { sprintf_P(buf, "%s.ntpServer1: '%s'", PGMStr_confTime, confTime.ntpServer1); sendLog(buf); } if (strcmp(param, "ntpserver2") == 0 || isConfPage == 7) { sprintf_P(buf, "%s.ntpServer2: '%s'", PGMStr_confTime, confTime.ntpServer2); sendLog(buf); } if (strcmp(param, "ntpsyncint") == 0 || isConfPage == 7) { sprintf_P(buf, "%s.ntpSyncInt: %lu", PGMStr_confTime, confTime.ntpSyncInterval / 60); sendLog(buf); } #endif // confLog if (strcmp(param, "loglevser") == 0 || isConfPage == 8) { sprintf_P(buf, "%s.logLevSer: %d", PGMStr_confLog, confLog.logLevelSerial); sendLog(buf); } if (strcmp(param, "loglevweb") == 0 || isConfPage == 8) { sprintf_P(buf, "%s.logLevWeb: %d", PGMStr_confLog, confLog.logLevelWeb); sendLog(buf); } if (strcmp(param, "loglevmqtt") == 0 || isConfPage == 8) { sprintf_P(buf, "%s.logLevMqtt: %d", PGMStr_confLog, confLog.logLevelMqtt); sendLog(buf); } if (strcmp(param, "logwebrequests") == 0 || isConfPage == 8) { int tmp; if (confLog.logWebRequests) tmp = 1; else tmp = 0; sprintf_P(buf, "%s.logWebRequests: %d", PGMStr_confLog, tmp); sendLog(buf); } } boolean loadConfigDevWiFi() { char configFileName[] = "/confDevWiFi.json"; if (SPIFFS.exists(configFileName)) { File configFile = SPIFFS.open(configFileName, "r"); if (!configFile) { Serial.print(F("ERR: Failed to open file '")); Serial.print(configFileName); Serial.println("'"); return false; } else { Serial.print("file '"); Serial.print(configFileName); Serial.print("' opened. "); size_t size = configFile.size(); Serial.print("size="); Serial.println(size); if (size > 1000) { Serial.println(F("Config file size is too large")); return false; } std::unique_ptr buf(new char[size]); #ifdef DEBUGMODE Serial.println(F("file content:")); while (configFile.available()) { Serial.write(configFile.read()); } Serial.println(); configFile.seek(0, SeekSet); // reset so that we can read again #endif configFile.readBytes(buf.get(), size); DynamicJsonDocument json(size + 50); DeserializationError error = deserializeJson(json, buf.get()); if (error) { Serial.println(F("Failed to parse config file")); return false; } #ifdef ENABLE_FEATURE_PW_ENCRYPTION char tmp[101]; #endif strlcpy(confDevWiFi.deviceName, json["devName"] | "", sizeof(confDevWiFi.deviceName)); strlcpy(confDevWiFi.hostName, json["hostName"] | "", sizeof(confDevWiFi.hostName)); strlcpy(confDevWiFi.WiFiSSID1, json["SSID1"] | "", sizeof(confDevWiFi.WiFiSSID1)); #ifdef ENABLE_FEATURE_PW_ENCRYPTION if (confEncryptionEnabled) { strlcpy(tmp, json["WPW1"] | "", sizeof(tmp)); strlcpy(confDevWiFi.WiFiPW1, XORENC(tmp, encKey), sizeof(confDevWiFi.WiFiPW1)); } else strlcpy(confDevWiFi.WiFiPW1, json["WPW1"] | "", sizeof(confDevWiFi.WiFiPW1)); #else strlcpy(confDevWiFi.WiFiPW1, json["WPW1"] | "", sizeof(confDevWiFi.WiFiPW1)); #endif strlcpy(confDevWiFi.WiFiSSID2, json["SSID2"] | "", sizeof(confDevWiFi.WiFiSSID2)); #ifdef ENABLE_FEATURE_PW_ENCRYPTION if (confEncryptionEnabled) { strlcpy(tmp, json["WPW2"] | "", sizeof(tmp)); strlcpy(confDevWiFi.WiFiPW2, XORENC(tmp, encKey), sizeof(confDevWiFi.WiFiPW2)); } else strlcpy(confDevWiFi.WiFiPW2, json["WPW2"] | "", sizeof(confDevWiFi.WiFiPW2)); #else strlcpy(confDevWiFi.WiFiPW2, json["WPW2"] | "", sizeof(confDevWiFi.WiFiPW2)); #endif #ifdef ENABLE_FEATURE_PW_ENCRYPTION if (confEncryptionEnabled) { strlcpy(tmp, json["WPWAP"] | "", sizeof(tmp)); strlcpy(confDevWiFi.WiFiAPModePassword, XORENC(tmp, encKey), sizeof(confDevWiFi.WiFiAPModePassword)); } else strlcpy(confDevWiFi.WiFiAPModePassword, json["WPWAP"] | "", sizeof(confDevWiFi.WiFiAPModePassword)); #else strlcpy(confDevWiFi.WiFiAPModePassword, json["WPWAP"] | "", sizeof(confDevWiFi.WiFiAPModePassword)); #endif confDevWiFi.WiFiAPModeTimeout = json["WAPtout"] | DEFAULT_WIFI_APMODE_TIMEOUT; confDevWiFi.WiFiRetryInterval = json["Wretry"] | DEFAULT_WIFI_RETRY_INTERVAL; confDevWiFi.WiFiConnCheckInterval = json["WConnCheck"] | DEFAULT_WIFI_CONNCHECK_INTERVAL; confDevWiFi.WiFiRebootOnNoConnect = json["Wreboot"] | DEFAULT_WIFI_REBOOT_ONNOCONNECT; Serial.println(F("Loaded config values.")); //getConfig((char *)"confDevWiFi"); return true; } configFile.close(); } else { Serial.print(F("NOTE: could not load confDevWiFi - file '")); Serial.print(configFileName); Serial.println(F("' does not exist.")); return false; } } // loadConfigDevWiFi boolean loadConfigWeb() { // loadConfigWeb char configFileName[] = "/confWeb.json"; if (SPIFFS.exists(configFileName)) { File configFile = SPIFFS.open(configFileName, "r"); if (!configFile) { Serial.print(F("ERR: Failed to open file '")); Serial.print(configFileName); Serial.println("'"); return false; } else { Serial.print("file '"); Serial.print(configFileName); Serial.print("' opened. "); size_t size = configFile.size(); Serial.print("size="); Serial.println(size); if (size > 1000) { Serial.println(F("Config file size is too large")); return false; } std::unique_ptr buf(new char[size]); #ifdef DEBUGMODE Serial.println(F("file content:")); while (configFile.available()) { Serial.write(configFile.read()); } Serial.println(); configFile.seek(0, SeekSet); // reset so that we can read again #endif configFile.readBytes(buf.get(), size); DynamicJsonDocument json(size + 50); DeserializationError error = deserializeJson(json, buf.get()); if (error) { Serial.println(F("Failed to parse config file")); return false; } #ifdef ENABLE_FEATURE_PW_ENCRYPTION char tmp[101]; #endif #ifdef ENABLE_FEATURE_PW_ENCRYPTION if (confEncryptionEnabled) { strlcpy(tmp, json["apiToken"] | "", sizeof(tmp)); strlcpy(confWeb.http_token, XORENC(tmp, encKey), sizeof(confWeb.http_token)); } else strlcpy(confWeb.http_token, json["apiToken"] | "", sizeof(confWeb.http_token)); #else strlcpy(confWeb.http_token, json["apiToken"] | "", sizeof(confWeb.http_token)); #endif strlcpy(confWeb.http_user, json["httpUA"] | "", sizeof(confWeb.http_user)); #ifdef ENABLE_FEATURE_PW_ENCRYPTION if (confEncryptionEnabled) { strlcpy(tmp, json["httpPA"] | "", sizeof(tmp)); strlcpy(confWeb.http_pass, XORENC(tmp, encKey), sizeof(confWeb.http_pass)); } else strlcpy(confWeb.http_pass, json["httpPA"] | "", sizeof(confWeb.http_pass)); #else strlcpy(confWeb.http_pass, json["httpPA"] | "", sizeof(confWeb.http_pass)); #endif if ((json["httpAuth"] | 0) == 1) confWeb.http_user_auth = true; else confWeb.http_user_auth = false; strlcpy(confWeb.http_user1, json["httpU1"] | "", sizeof(confWeb.http_user1)); #ifdef ENABLE_FEATURE_PW_ENCRYPTION if (confEncryptionEnabled) { strlcpy(tmp, json["httpP1"] | "", sizeof(tmp)); strlcpy(confWeb.http_pass1, XORENC(tmp, encKey), sizeof(confWeb.http_pass1)); } else strlcpy(confWeb.http_pass1, json["httpP1"] | "", sizeof(confWeb.http_pass1)); #else strlcpy(confWeb.http_pass1, json["httpP1"] | "", sizeof(confWeb.http_pass1)); #endif strlcpy(confWeb.http_user2, json["httpU2"] | "", sizeof(confWeb.http_user2)); #ifdef ENABLE_FEATURE_PW_ENCRYPTION if (confEncryptionEnabled) { strlcpy(tmp, json["httpP2"] | "", sizeof(tmp)); strlcpy(confWeb.http_pass2, XORENC(tmp, encKey), sizeof(confWeb.http_pass2)); } else strlcpy(confWeb.http_pass2, json["httpP2"] | "", sizeof(confWeb.http_pass2)); #else strlcpy(confWeb.http_pass2, json["httpP2"] | "", sizeof(confWeb.http_pass2)); #endif if ((json["wConsole"] | 0) == 1) confWeb.wConsole = true; else confWeb.wConsole = false; if ((json["wsConsole"] | 0) == 1) confWeb.wsConsole = true; else confWeb.wsConsole = false; Serial.println(F("Loaded config values.")); //getConfig((char *)"confWeb"); return true; } configFile.close(); } else { Serial.print(F("NOTE: could not load confWeb - file '")); Serial.print(configFileName); Serial.println(F("' does not exist.")); return false; } } // loadConfigWeb boolean loadConfigMqtt() { // loadConfigMqtt char configFileName[] = "/confMqtt.json"; if (SPIFFS.exists(configFileName)) { File configFile = SPIFFS.open(configFileName, "r"); if (!configFile) { Serial.print(F("ERR: Failed to open file '")); Serial.print(configFileName); Serial.println("'"); return false; } else { Serial.print("file '"); Serial.print(configFileName); Serial.print("' opened. "); size_t size = configFile.size(); Serial.print("size="); Serial.println(size); if (size > 1000) { Serial.println(F("Config file size is too large")); return false; } std::unique_ptr buf(new char[size]); #ifdef DEBUGMODE Serial.println(F("file content:")); while (configFile.available()) { Serial.write(configFile.read()); } Serial.println(); configFile.seek(0, SeekSet); // reset so that we can read again #endif configFile.readBytes(buf.get(), size); DynamicJsonDocument json(size + 50); DeserializationError error = deserializeJson(json, buf.get()); if (error) { Serial.println(F("Failed to parse config file")); return false; } if ((json["mqttEnable"] | 0) == 1) confMqtt.mqtt_enable = true; else confMqtt.mqtt_enable = false; strlcpy(confMqtt.mqtt_server, json["mqttHost"] | "", sizeof(confMqtt.mqtt_server)); confMqtt.mqtt_port = json["mqttPort"] | 1883; strlcpy(confMqtt.mqtt_user, json["mqttUser"] | "", sizeof(confMqtt.mqtt_user)); #ifdef ENABLE_FEATURE_PW_ENCRYPTION char tmp[101]; #endif #ifdef ENABLE_FEATURE_PW_ENCRYPTION if (confEncryptionEnabled) { strlcpy(tmp, json["mqttPass"] | "", sizeof(tmp)); strlcpy(confMqtt.mqtt_pass, XORENC(tmp, encKey), sizeof(confMqtt.mqtt_pass)); } else strlcpy(confMqtt.mqtt_pass, json["mqttPass"] | "", sizeof(confMqtt.mqtt_pass)); #else strlcpy(confMqtt.mqtt_pass, json["mqttPass"] | "", sizeof(confMqtt.mqtt_pass)); #endif strlcpy(confMqtt.mqtt_topic_in, json["inTop"] | "", sizeof(confMqtt.mqtt_topic_in)); strlcpy(confMqtt.mqtt_topic_out, json["outTop"] | "", sizeof(confMqtt.mqtt_topic_out)); if ((json["outRet"] | 0) == 1) confMqtt.mqtt_outRetain = true; else confMqtt.mqtt_outRetain = false; if ((json["outRetSens"] | 0) == 1) confMqtt.mqtt_outRetain_sensors = true; else confMqtt.mqtt_outRetain_sensors = false; confMqtt.mqtt_outPubInterval = json["outPubInt"] | MQTT_OUT_PUBLISH_INTERVAL; confMqtt.mqtt_outPubInterval_sensors = json["outPubIntSens"] | MQTT_OUT_PUBLISH_INTERVAL_SENSORS; strlcpy(confMqtt.mqtt_willTopic, json["willTop"] | "", sizeof(confMqtt.mqtt_willTopic)); confMqtt.mqtt_willQos = json["willQos"] | 0; if ((json["willRet"] | 0) == 1) confMqtt.mqtt_willRetain = true; else confMqtt.mqtt_willRetain = false; strlcpy(confMqtt.mqtt_willMsg, json["willMsg"] | "", sizeof(confMqtt.mqtt_willMsg)); strlcpy(confMqtt.mqtt_connMsg, json["connMsg"] | "", sizeof(confMqtt.mqtt_connMsg)); if ((json["hbEnable"] | 0) == 1) confMqtt.mqtt_enable_heartbeat = true; else confMqtt.mqtt_enable_heartbeat = false; uint16_t tmpval; tmpval = json["hbReconn"] | 0; if (tmpval == 0) confMqtt.mqtt_heartbeat_maxage_reconnect = 0; else if (tmpval >= 2 && tmpval <= 10) confMqtt.mqtt_heartbeat_maxage_reconnect = tmpval * 60000; tmpval = json["hbReboot"] | 0; if (tmpval == 0) confMqtt.mqtt_heartbeat_maxage_reboot = 0; else if (tmpval >= 2 && tmpval <= 10) confMqtt.mqtt_heartbeat_maxage_reboot = tmpval * 60000; Serial.println(F("Loaded config values.")); //getConfig((char *)"confMqtt"); return true; } configFile.close(); } else { Serial.print(F("NOTE: could not load confMqtt - file '")); Serial.print(configFileName); Serial.println(F("' does not exist.")); return false; } } // loadConfigMqtt boolean loadConfigBas() { char configFileName[] = "/confBas.json"; if (SPIFFS.exists(configFileName)) { File configFile = SPIFFS.open(configFileName, "r"); if (!configFile) { Serial.print(F("ERR: Failed to open file '")); Serial.print(configFileName); Serial.println("'"); return false; } else { Serial.print("file '"); Serial.print(configFileName); Serial.print("' opened. "); size_t size = configFile.size(); Serial.print("size="); Serial.println(size); if (size > 1000) { Serial.println(F("Config file size is too large")); return false; } std::unique_ptr buf(new char[size]); #ifdef DEBUGMODE Serial.println(F("file content:")); while (configFile.available()) { Serial.write(configFile.read()); } Serial.println(); configFile.seek(0, SeekSet); // reset so that we can read again #endif configFile.readBytes(buf.get(), size); DynamicJsonDocument json(size + 50); DeserializationError error = deserializeJson(json, buf.get()); if (error) { Serial.println(F("Failed to parse config file")); return false; } if ((json["autoSaveTemp"] | 0) == 1) confBas.autoSaveSetTemp = true; else confBas.autoSaveSetTemp = false; if ((json["autoSaveMode"] | 0) == 1) confBas.autoSaveHeatingMode = true; else confBas.autoSaveHeatingMode = false; if ((json["saveToMqttRet"] | 0) == 1) confBas.saveToMqttRetained = true; else confBas.saveToMqttRetained = false; if ((json["PIRenDisp"] | 0) == 1) confBas.PIR_enablesDisplay = true; else confBas.PIR_enablesDisplay = false; if ((json["PIRenDispPs0"] | 0) == 1) confBas.PIR_enablesDisplay_preset0only = true; else confBas.PIR_enablesDisplay_preset0only = false; if ((json["togTHdisp"] | 0) == 1) confBas.togglingTempHumAIDisplay = true; else confBas.togglingTempHumAIDisplay = false; confBas.setTempMin = json["tempMin"] | DEFAULT_SETTEMP_MIN; confBas.setTempMax = json["tempMax"] | DEFAULT_SETTEMP_MAX; confBas.measureInterval = json["measInt"] | DEFAULT_MEASURE_INTERVAL; confBas.displayInterval = json["dispInt"] | DEFAULT_DISPLAY_INTERVAL; confBas.displayTimeout = json["dispTout"] | DEFAULT_DISPLAY_TIMEOUT; // Serial.println(F("Loaded config values.")); //getConfig((char *)"confBas"); return true; } configFile.close(); } else { Serial.print(F("NOTE: could not load confBas - file '")); Serial.print(configFileName); Serial.println(F("' does not exist.")); return false; } } // loadConfigBas boolean loadConfigAdv() { char configFileName[] = "/confAdv.json"; if (SPIFFS.exists(configFileName)) { File configFile = SPIFFS.open(configFileName, "r"); if (!configFile) { Serial.print(F("ERR: Failed to open file '")); Serial.print(configFileName); Serial.println("'"); return false; } else { Serial.print("file '"); Serial.print(configFileName); Serial.print("' opened. "); size_t size = configFile.size(); Serial.print("size="); Serial.println(size); if (size > 1000) { Serial.println(F("Config file size is too large")); return false; } std::unique_ptr buf(new char[size]); #ifdef DEBUGMODE Serial.println(F("file content:")); while (configFile.available()) { Serial.write(configFile.read()); } Serial.println(); configFile.seek(0, SeekSet); // reset so that we can read again #endif configFile.readBytes(buf.get(), size); DynamicJsonDocument json(size + 50); DeserializationError error = deserializeJson(json, buf.get()); if (error) { Serial.println(F("Failed to parse config file")); return false; } confAdv.hysteresis = json["hyst"] | 0.2; confAdv.heatingMinOffTime = json["minOffTime"] | 600; confAdv.tempCorrVal = json["tempCorr"] | 0.0; confAdv.humCorrVal = json["humCorr"] | 0; confAdv.setTempDecreaseVal = json["tempDec"] | 0.0; strlcpy(confAdv.offMessage, json["offMsg"] | "", sizeof(confAdv.offMessage)); strlcpy(confAdv.iTempLabel, json["iTempLab"] | "", sizeof(confAdv.iTempLabel)); strlcpy(confAdv.oTempLabel, json["oTempLab"] | "", sizeof(confAdv.oTempLabel)); strlcpy(confAdv.modeName0, json["modeName0"] | "", sizeof(confAdv.modeName0)); strlcpy(confAdv.modeName1, json["modeName1"] | "", sizeof(confAdv.modeName1)); strlcpy(confAdv.psetName0, json["psetName0"] | "", sizeof(confAdv.psetName0)); strlcpy(confAdv.psetName1, json["psetName1"] | "", sizeof(confAdv.psetName1)); strlcpy(confAdv.psetName2, json["psetName2"] | "", sizeof(confAdv.psetName2)); confAdv.pauseTout = json["pauseTout"] | 1800; // Serial.println("Loaded config values:"); //getConfig((char *)"confAdv"); return true; } configFile.close(); } else { Serial.print(F("NOTE: could not load confAdv - file '")); Serial.print(configFileName); Serial.println(F("' does not exist.")); return false; } } // loadConfigAdv boolean loadConfigAdd() { char configFileName[] = "/confAdd.json"; if (SPIFFS.exists(configFileName)) { File configFile = SPIFFS.open(configFileName, "r"); if (!configFile) { Serial.print(F("ERR: Failed to open file '")); Serial.print(configFileName); Serial.println("'"); return false; } else { Serial.print("file '"); Serial.print(configFileName); Serial.print("' opened. "); size_t size = configFile.size(); Serial.print("size="); Serial.println(size); if (size > 1000) { Serial.println(F("Config file size is too large")); return false; } std::unique_ptr buf(new char[size]); #ifdef DEBUGMODE Serial.println(F("file content:")); while (configFile.available()) { Serial.write(configFile.read()); } Serial.println(); configFile.seek(0, SeekSet); // reset so that we can read again #endif configFile.readBytes(buf.get(), size); DynamicJsonDocument json(size + 50); DeserializationError error = deserializeJson(json, buf.get()); if (error) { Serial.println(F("Failed to parse config file")); return false; } strlcpy(confAdd.mqtt_topic_pir, json["PIRTop"] | "", sizeof(confAdd.mqtt_topic_pir)); strlcpy(confAdd.mqtt_payload_pir_on, json["PIROnPld"] | "", sizeof(confAdd.mqtt_payload_pir_on)); strlcpy(confAdd.mqtt_payload_pir_off, json["PIROffPld"] | "", sizeof(confAdd.mqtt_payload_pir_off)); strlcpy(confAdd.outTemp_topic_in, json["outTempTop"] | "", sizeof(confAdd.outTemp_topic_in)); strlcpy(confAdd.outHum_topic_in, json["outHumTop"] | "", sizeof(confAdd.outHum_topic_in)); // Serial.println("Loaded config values:"); //getConfig((char *)"confAdd"); return true; } configFile.close(); } else { Serial.print(F("NOTE: could not load confAdd - file '")); Serial.print(configFileName); Serial.println(F("' does not exist.")); return false; } } // loadConfigAdd #ifdef ENABLE_FEATURE_NTP_TIME boolean loadConfigTime() { char configFileName[] = "/confTime.json"; if (SPIFFS.exists(configFileName)) { File configFile = SPIFFS.open(configFileName, "r"); if (!configFile) { Serial.print(F("ERR: Failed to open file '")); Serial.print(configFileName); Serial.println("'"); return false; } else { Serial.print("file '"); Serial.print(configFileName); Serial.print("' opened. "); size_t size = configFile.size(); Serial.print("size="); Serial.println(size); if (size > 1000) { Serial.println(F("Config file size is too large")); return false; } std::unique_ptr buf(new char[size]); #ifdef DEBUGMODE Serial.println(F("file content:")); while (configFile.available()) { Serial.write(configFile.read()); } Serial.println(); configFile.seek(0, SeekSet); // reset so that we can read again #endif configFile.readBytes(buf.get(), size); DynamicJsonDocument json(size + 50); DeserializationError error = deserializeJson(json, buf.get()); if (error) { Serial.println(F("Failed to parse config file")); return false; } if ((json["NTPEnable"] | 0) == 1) confTime.ntpEnable = true; else confTime.ntpEnable = false; strlcpy(confTime.ntpServer1, json["NTPServer1"] | "", sizeof(confTime.ntpServer1)); strlcpy(confTime.ntpServer2, json["NTPServer2"] | "", sizeof(confTime.ntpServer2)); unsigned int ntpSyncInterval = json["NTPSyncInt"]; confTime.ntpSyncInterval = ntpSyncInterval * 60; strlcpy(confTime.timeZoneStr, json["TZstr"] | "", sizeof(confTime.timeZoneStr)); // Serial.println("Loaded config values:"); //getConfig((char *)"confTime"); return true; } configFile.close(); } else { Serial.print(F("NOTE: could not load confTime - file '")); Serial.print(configFileName); Serial.println(F("' does not exist.")); return false; } } // loadConfigTime #endif boolean loadConfigLog() { char configFileName[] = "/confLog.json"; if (SPIFFS.exists(configFileName)) { File configFile = SPIFFS.open(configFileName, "r"); if (!configFile) { Serial.print(F("ERR: Failed to open file '")); Serial.print(configFileName); Serial.println("'"); return false; } else { Serial.print("file '"); Serial.print(configFileName); Serial.print("' opened. "); size_t size = configFile.size(); Serial.print("size="); Serial.println(size); if (size > 1000) { Serial.println(F("Config file size is too large")); return false; } std::unique_ptr buf(new char[size]); #ifdef DEBUGMODE Serial.println(F("file content:")); while (configFile.available()) { Serial.write(configFile.read()); } Serial.println(); configFile.seek(0, SeekSet); // reset so that we can read again #endif configFile.readBytes(buf.get(), size); DynamicJsonDocument json(size + 50); DeserializationError error = deserializeJson(json, buf.get()); if (error) { Serial.println(F("Failed to parse config file")); return false; } //if ((json["NTPEnable"] | 0) == 1) // confTime.ntpEnable = true; //else // confTime.ntpEnable = false; confLog.logLevelSerial = json["logLevSer"]; confLog.logLevelWeb = json["logLevWeb"]; confLog.logLevelMqtt = json["logLevMqtt"]; if ((json["logWebRequests"] | 0) == 1) confLog.logWebRequests = true; else confLog.logWebRequests = false; // Serial.println("Loaded config values:"); //getConfig((char *)"confLog"); return true; } configFile.close(); } else { Serial.print(F("NOTE: could not load confTime - file '")); Serial.print(configFileName); Serial.println(F("' does not exist.")); return false; } } // loadConfigLog boolean loadSetTemp() { // loadSetTemp File configFile = SPIFFS.open("/setTemp", "r"); if (!configFile) { Serial.println(F("NOTE: Failed to open file /setTemp")); return false; } String s = configFile.readStringUntil('\n'); configFile.close(); float tmpSetTemp = s.toFloat(); if (tmpSetTemp >= confBas.setTempMin && tmpSetTemp <= confBas.setTempMax) { setTemp = tmpSetTemp; setTempSaved = tmpSetTemp; return true; } else return false; } // loadSetTemp boolean loadSetTempLow() { // loadSetTempLow File configFile = SPIFFS.open("/setTempLow", "r"); if (!configFile) { Serial.println(F("NOTE: Failed to open file /setTempLow")); return false; } String s = configFile.readStringUntil('\n'); configFile.close(); float tmpSetTempLow = s.toFloat(); if (tmpSetTempLow >= setTempLowMin && tmpSetTempLow <= setTempLowMax) { setTempLow = tmpSetTempLow; setTempLowSaved = tmpSetTempLow; return true; } else return false; } // loadSetTempLow boolean loadSetTempLow2() { // loadSetTempLow2 File configFile = SPIFFS.open("/setTempLow2", "r"); if (!configFile) { Serial.println(F("NOTE: Failed to open file /setTempLow2")); return false; } String s = configFile.readStringUntil('\n'); configFile.close(); float tmpSetTempLow2 = s.toFloat(); if (tmpSetTempLow2 >= setTempLowMin && tmpSetTempLow2 <= setTempLowMax) { setTempLow2 = tmpSetTempLow2; setTempLow2Saved = tmpSetTempLow2; return true; } else return false; } // loadSetTempLow2 boolean loadHeatingMode() { // loadHeatingMode File configFile = SPIFFS.open("/heatingMode", "r"); if (!configFile) { Serial.println(F("NOTE: 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; heatingModeSaved = tmpHeatingMode; return true; } else return false; } // loadHeatingMode boolean loadPreset() { // loadPreset File configFile = SPIFFS.open("/preset", "r"); if (!configFile) { Serial.println(F("NOTE: 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; presetSaved = tmpPreset; return true; } else return false; } // loadPreset boolean saveConfigWeb() { // saveConfig if (confWeb.wasChanged) { char configFileName[] = "/confWeb.json"; DynamicJsonDocument json(1050); #ifdef ENABLE_FEATURE_PW_ENCRYPTION if (confEncryptionEnabled) json["apiToken"] = XORENC(confWeb.http_token, encKey); else json["apiToken"] = confWeb.http_token; #else json["apiToken"] = confWeb.http_token; #endif json["httpUA"] = confWeb.http_user; #ifdef ENABLE_FEATURE_PW_ENCRYPTION if (confEncryptionEnabled) json["httpPA"] = XORENC(confWeb.http_pass, encKey); else json["httpPA"] = confWeb.http_pass; #else json["httpPA"] = confWeb.http_pass; #endif if (confWeb.http_user_auth) json["httpAuth"] = 1; else json["httpAuth"] = 0; json["httpU1"] = confWeb.http_user1; #ifdef ENABLE_FEATURE_PW_ENCRYPTION if (confEncryptionEnabled) json["httpP1"] = XORENC(confWeb.http_pass1, encKey); else json["httpP1"] = confWeb.http_pass1; #else json["httpP1"] = confWeb.http_pass1; #endif json["httpU2"] = confWeb.http_user2; #ifdef ENABLE_FEATURE_PW_ENCRYPTION if (confEncryptionEnabled) json["httpP2"] = XORENC(confWeb.http_pass2, encKey); else json["httpP2"] = confWeb.http_pass2; #else json["httpP2"] = confWeb.http_pass2; #endif if (confWeb.wConsole) json["wConsole"] = 1; else json["wConsole"] = 0; if (confWeb.wsConsole) json["wsConsole"] = 1; else json["wsConsole"] = 0; yield(); File configFile = SPIFFS.open(configFileName, "w"); if (!configFile) { Serial.print("Failed to open file '"); Serial.print(configFileName); Serial.println("' for writing"); return false; } serializeJson(json, configFile); confWeb.wasChanged = false; return true; } else return false; } // saveConfigWeb boolean saveConfigMqtt() { // safeConfig if (confMqtt.wasChanged) { char configFileName[] = "/confMqtt.json"; DynamicJsonDocument json(1050); if (confMqtt.mqtt_enable) json["mqttEnable"] = 1; else json["mqttEnable"] = 0; json["mqttHost"] = confMqtt.mqtt_server; json["mqttPort"] = confMqtt.mqtt_port; json["mqttUser"] = confMqtt.mqtt_user; #ifdef ENABLE_FEATURE_PW_ENCRYPTION if (confEncryptionEnabled) json["mqttPass"] = XORENC(confMqtt.mqtt_pass, encKey); else json["mqttPass"] = confMqtt.mqtt_pass; #else json["mqttPass"] = confMqtt.mqtt_pass; #endif json["inTop"] = confMqtt.mqtt_topic_in; json["outTop"] = confMqtt.mqtt_topic_out; if (confMqtt.mqtt_outRetain) json["outRet"] = 1; else json["outRet"] = 0; if (confMqtt.mqtt_outRetain_sensors) json["outRetSens"] = 1; else json["outRetSens"] = 0; json["outPubInt"] = confMqtt.mqtt_outPubInterval; json["outPubIntSens"] = confMqtt.mqtt_outPubInterval_sensors; json["willTop"] = confMqtt.mqtt_willTopic; json["willQos"] = confMqtt.mqtt_willQos; if (confMqtt.mqtt_willRetain) json["willRet"] = 1; else json["willRet"] = 0; json["willMsg"] = confMqtt.mqtt_willMsg; json["connMsg"] = confMqtt.mqtt_connMsg; if (confMqtt.mqtt_enable_heartbeat) json["hbEnable"] = 1; else json["hbEnable"] = 0; json["hbReconn"] = confMqtt.mqtt_heartbeat_maxage_reconnect / 60000; json["hbReboot"] = confMqtt.mqtt_heartbeat_maxage_reboot / 60000; yield(); File configFile = SPIFFS.open(configFileName, "w"); if (!configFile) { Serial.print("Failed to open file '"); Serial.print(configFileName); Serial.println("' for writing"); return false; } serializeJson(json, configFile); confMqtt.wasChanged = false; return true; } else return false; } // saveConfigMqtt boolean saveConfigDevWiFi() { // saveConfig if (confDevWiFi.wasChanged) { char configFileName[] = "/confDevWiFi.json"; DynamicJsonDocument json(1050); json["devName"] = confDevWiFi.deviceName; json["hostName"] = confDevWiFi.hostName; json["SSID1"] = confDevWiFi.WiFiSSID1; #ifdef ENABLE_FEATURE_PW_ENCRYPTION if (confEncryptionEnabled) json["WPW1"] = XORENC(confDevWiFi.WiFiPW1, encKey); else json["WPW1"] = confDevWiFi.WiFiPW1; #else json["WPW1"] = confDevWiFi.WiFiPW1; #endif json["SSID2"] = confDevWiFi.WiFiSSID2; #ifdef ENABLE_FEATURE_PW_ENCRYPTION if (confEncryptionEnabled) json["WPW2"] = XORENC(confDevWiFi.WiFiPW2, encKey); else json["WPW2"] = confDevWiFi.WiFiPW2; #else json["WPW2"] = confDevWiFi.WiFiPW2; #endif #ifdef ENABLE_FEATURE_PW_ENCRYPTION if (confEncryptionEnabled) json["WPWAP"] = XORENC(confDevWiFi.WiFiAPModePassword, encKey); else json["WPWAP"] = confDevWiFi.WiFiAPModePassword; #else json["WPWAP"] = confDevWiFi.WiFiAPModePassword; #endif json["WAPtout"] = confDevWiFi.WiFiAPModeTimeout; json["WConnCheck"] = confDevWiFi.WiFiConnCheckInterval; json["Wretry"] = confDevWiFi.WiFiRetryInterval; json["Wreboot"] = confDevWiFi.WiFiRebootOnNoConnect; yield(); File configFile = SPIFFS.open(configFileName, "w"); if (!configFile) { Serial.print("Failed to open file '"); Serial.print(configFileName); Serial.println("' for writing"); return false; } serializeJson(json, configFile); confDevWiFi.wasChanged = false; return true; } else return false; } // saveConfigDevWiFi boolean saveConfigBas() { // safeConfig if (confBas.wasChanged) { char configFileName[] = "/confBas.json"; DynamicJsonDocument json(1050); if (confBas.autoSaveSetTemp) json["autoSaveTemp"] = 1; else json["autoSaveTemp"] = 0; if (confBas.autoSaveHeatingMode) json["autoSaveMode"] = 1; else json["autoSaveMode"] = 0; if (confBas.saveToMqttRetained) json["saveToMqttRet"] = 1; else json["saveToMqttRet"] = 0; json["tempMin"] = confBas.setTempMin; json["tempMax"] = confBas.setTempMax; json["measInt"] = confBas.measureInterval; json["dispInt"] = confBas.displayInterval; json["dispTout"] = confBas.displayTimeout; if (confBas.PIR_enablesDisplay) json["PIRenDisp"] = 1; else json["PIRenDisp"] = 0; if (confBas.PIR_enablesDisplay_preset0only) json["PIRenDispPs0"] = 1; else json["PIRenDispPs0"] = 0; if (confBas.togglingTempHumAIDisplay) json["togTHdisp"] = 1; else json["togTHdisp"] = 0; yield(); File configFile = SPIFFS.open(configFileName, "w"); if (!configFile) { Serial.print("Failed to open file '"); Serial.print(configFileName); Serial.println("' for writing"); return false; } serializeJson(json, configFile); confBas.wasChanged = false; return true; } else return false; } // saveConfigBas boolean saveConfigAdv() { // safeConfig if (confAdv.wasChanged) { char configFileName[] = "/confAdv.json"; DynamicJsonDocument json(1050); json["hyst"] = confAdv.hysteresis; json["minOffTime"] = confAdv.heatingMinOffTime; json["tempCorr"] = confAdv.tempCorrVal; json["humCorr"] = confAdv.humCorrVal; json["tempDec"] = confAdv.setTempDecreaseVal; json["offMsg"] = confAdv.offMessage; json["iTempLab"] = confAdv.iTempLabel; json["oTempLab"] = confAdv.oTempLabel; json["modeName0"] = confAdv.modeName0; json["modeName1"] = confAdv.modeName1; json["psetName0"] = confAdv.psetName0; json["psetName1"] = confAdv.psetName1; json["psetName2"] = confAdv.psetName2; json["pauseTout"] = confAdv.pauseTout; yield(); File configFile = SPIFFS.open(configFileName, "w"); if (!configFile) { Serial.print("Failed to open file '"); Serial.print(configFileName); Serial.println("' for writing"); return false; } serializeJson(json, configFile); confAdv.wasChanged = false; return true; } else return false; } // saveConfigAdv boolean saveConfigAdd() { // safeConfig if (confAdd.wasChanged) { char configFileName[] = "/confAdd.json"; DynamicJsonDocument json(1050); json["PIRTop"] = confAdd.mqtt_topic_pir; json["PIROnPld"] = confAdd.mqtt_payload_pir_on; json["PIROffPld"] = confAdd.mqtt_payload_pir_off; json["outTempTop"] = confAdd.outTemp_topic_in; json["outHumTop"] = confAdd.outHum_topic_in; yield(); File configFile = SPIFFS.open(configFileName, "w"); if (!configFile) { Serial.print("Failed to open file '"); Serial.print(configFileName); Serial.println("' for writing"); return false; } serializeJson(json, configFile); confAdd.wasChanged = false; return true; } else return false; } // saveConfigAdd #ifdef ENABLE_FEATURE_NTP_TIME boolean saveConfigTime() { if (confTime.wasChanged) { char configFileName[] = "/confTime.json"; DynamicJsonDocument json(1050); if (confTime.ntpEnable) json["NTPEnable"] = 1; else json["NTPEnable"] = 0; json["NTPServer1"] = confTime.ntpServer1; json["NTPServer2"] = confTime.ntpServer2; json["NTPSyncInt"] = confTime.ntpSyncInterval / 60; json["TZstr"] = confTime.timeZoneStr; yield(); File configFile = SPIFFS.open(configFileName, "w"); if (!configFile) { Serial.print("Failed to open file '"); Serial.print(configFileName); Serial.println("' for writing"); return false; } serializeJson(json, configFile); confTime.wasChanged = false; return true; } else return false; } // saveConfigTime #endif boolean saveConfigLog() { if (confLog.wasChanged) { char configFileName[] = "/confLog.json"; DynamicJsonDocument json(1050); //if(confTime.ntpEnable) json["NTPEnable"] = 1; //else json["NTPEnable"] = 0; json["logLevSer"] = confLog.logLevelSerial; json["logLevWeb"] = confLog.logLevelWeb; json["logLevMqtt"] = confLog.logLevelMqtt; if (confLog.logWebRequests) json["logWebRequests"] = 1; else json["logWebRequests"] = 0; yield(); File configFile = SPIFFS.open(configFileName, "w"); if (!configFile) { Serial.print("Failed to open file '"); Serial.print(configFileName); Serial.println("' for writing"); return false; } serializeJson(json, configFile); confLog.wasChanged = false; return true; } else return false; } // saveConfigLog boolean saveSetTemp() { // saveSetTemp File configFile = SPIFFS.open("/setTemp", "w"); if (!configFile) { sendLog(F("Failed to write file /setTemp"), LOGLEVEL_ERROR); return false; } configFile.println(setTemp); configFile.close(); setTempSaved = setTemp; return true; } // saveSetTemp boolean saveSetTempLow() { // saveSetTempLow File configFile = SPIFFS.open("/setTempLow", "w"); if (!configFile) { sendLog(F("Failed to write file /setTempLow"), LOGLEVEL_ERROR); return false; } configFile.println(setTempLow); configFile.close(); setTempLowSaved = setTempLow; return true; } // saveSetTempLow boolean saveSetTempLow2() { // saveSetTempLow File configFile = SPIFFS.open("/setTempLow2", "w"); if (!configFile) { sendLog(F("Failed to write file setTempLow2"), LOGLEVEL_ERROR); return false; } configFile.println(setTempLow2); configFile.close(); setTempLow2Saved = setTempLow2; return true; } // saveSetTempLow boolean saveHeatingMode() { // saveHeatingMode File configFile = SPIFFS.open("/heatingMode", "w"); if (!configFile) { sendLog(F("Failed to write file /heatingMode"), LOGLEVEL_ERROR); return false; } configFile.println(heatingMode); configFile.close(); heatingModeSaved = heatingMode; return true; } // saveHeatingMode boolean savePreset() { // savePreset File configFile = SPIFFS.open("/preset", "w"); if (!configFile) { sendLog(F("Failed to write file /preset"), LOGLEVEL_ERROR); return false; } configFile.println(preset); configFile.close(); presetSaved = preset; return true; } // savePreset void deleteConfig() { sendLog(F("deleting configuration...")); SPIFFS_format(); delay(100); ESP.restart(); } void loadConf_all() { sendLog("CONF: loading configurations..."); loadConfigDevWiFi(); loadConfigWeb(); loadConfigMqtt(); loadConfigBas(); loadConfigAdv(); loadConfigAdd(); #ifdef ENABLE_FEATURE_NTP_TIME loadConfigTime(); #endif loadConfigLog(); sendLog("CONF: done."); } void saveConfig_all() { if(confCheckUnsaved()) { sendLog(F("CONF: saving...")); saveConfigDevWiFi(); yield(); saveConfigWeb(); yield(); saveConfigMqtt(); yield(); saveConfigBas(); yield(); saveConfigAdv(); yield(); saveConfigAdd(); yield(); #ifdef ENABLE_FEATURE_NTP_TIME saveConfigTime(); yield(); #endif saveConfigLog(); yield(); sendLog(F("CONF: saving to SPIFFS DONE")); } else sendLog(F("CONF: nothing changed.")); } void loadSavedValues() { loadSetTemp(); loadSetTempLow(); loadSetTempLow2(); loadHeatingMode(); loadPreset(); } void saveValues() { sendLog(F("saving values...")); saveSetTemp(); yield(); saveSetTempLow(); yield(); saveSetTempLow2(); yield(); saveHeatingMode(); yield(); sendLog(F("saved values to SPIFFS - DONE")); } void SPIFFS_format() { sendLog(F("formatting SPIFFS, please wait 30 secs")); SPIFFS.format(); sendLog(F("SPIFFS formatted")); File f = SPIFFS.open("/formatted", "w"); if (!f) { sendLog(F("creating file '/formatted' failed")); } else { f.println(F("Format Complete")); } f.close(); } void SPIFFS_formatIfIsnt() { if (!SPIFFS.exists("/formatted")) { SPIFFS_format(); } // else //{ // if (serialdebug) // Serial.println(F("SPIFFS is formatted. Moving along...")); //} } void SPIFFS_listFiles() { //Serial.println(F("files in SPIFFS:")); sendLog(F("ls SPIFFS:")); Dir dir = SPIFFS.openDir("/"); while (dir.next()) { //Serial.print(dir.fileName()); File f = dir.openFile("r"); //Serial.print(" "); //Serial.println(f.size()); char buf[101]; sprintf(buf, " %s %d", dir.fileName().c_str(), f.size()); sendLog(buf); f.close(); } sendLog(F("--------")); //Serial.println(F("----")); } void loadConf_defaults() { // set initial deviceName createDeviceName(); // confDevWiFi // strlcpy(deviceName, DEVICE_NAME, sizeof(deviceName)); // now done via createDeviceName() strlcpy(confDevWiFi.hostName, confDevWiFi.deviceName, sizeof(confDevWiFi.hostName)); // copy deviceName to hostName as initial value strlcpy(confDevWiFi.WiFiAPModePassword, DEFAULT_WIFI_APMODE_PASSWORD, sizeof(confDevWiFi.WiFiAPModePassword)); confDevWiFi.WiFiAPModeTimeout = DEFAULT_WIFI_APMODE_TIMEOUT; confDevWiFi.WiFiRetryInterval = DEFAULT_WIFI_RETRY_INTERVAL; confDevWiFi.WiFiConnCheckInterval = DEFAULT_WIFI_CONNCHECK_INTERVAL; confDevWiFi.WiFiRebootOnNoConnect = DEFAULT_WIFI_REBOOT_ONNOCONNECT; confDevWiFi.wasChanged = false; // confWeb strlcpy(confWeb.http_token, HTTP_SET_TOKEN, sizeof(confWeb.http_token)); strlcpy(confWeb.http_user, DEFAULT_HTTP_USER, sizeof(confWeb.http_user)); strlcpy(confWeb.http_pass, DEFAULT_HTTP_PASS, sizeof(confWeb.http_pass)); confWeb.http_user_auth = DEFAULT_HTTP_USER_AUTH; confWeb.wasChanged = false; // confMqtt confMqtt.mqtt_enable = MQTT_ENABLE; strlcpy(confMqtt.mqtt_server, MQTT_SERVER, sizeof(confMqtt.mqtt_server)); confMqtt.mqtt_port = MQTT_PORT; strlcpy(confMqtt.mqtt_user, MQTT_USER, sizeof(confMqtt.mqtt_user)); strlcpy(confMqtt.mqtt_pass, MQTT_PASS, sizeof(confMqtt.mqtt_pass)); strlcpy(confMqtt.mqtt_topic_in, MQTT_TOPIC_IN, sizeof(confMqtt.mqtt_topic_in)); strlcpy(confMqtt.mqtt_topic_out, MQTT_TOPIC_OUT, sizeof(confMqtt.mqtt_topic_out)); strlcpy(confMqtt.mqtt_willTopic, MQTT_WILLTOPIC, sizeof(confMqtt.mqtt_willTopic)); confMqtt.mqtt_willQos = MQTT_WILLQOS; confMqtt.mqtt_willRetain = MQTT_WILLRETAIN; strlcpy(confMqtt.mqtt_willMsg, MQTT_WILLMSG, sizeof(confMqtt.mqtt_willMsg)); strlcpy(confMqtt.mqtt_connMsg, MQTT_CONNMSG, sizeof(confMqtt.mqtt_connMsg)); confMqtt.mqtt_outRetain = MQTT_OUT_RETAIN; confMqtt.mqtt_outRetain_sensors = MQTT_OUT_RETAIN_SENSORS; confMqtt.mqtt_enable_heartbeat = MQTT_ENABLE_HEARTBEAT; confMqtt.mqtt_heartbeat_maxage_reconnect = MQTT_HEARTBEAT_MAXAGE; confMqtt.mqtt_heartbeat_maxage_reboot = MQTT_HEARTBEAT_MAXAGE_REBOOT; confMqtt.wasChanged = false; // confBas confBas.setTempMin = DEFAULT_SETTEMP_MIN; confBas.setTempMax = DEFAULT_SETTEMP_MAX; confBas.autoSaveSetTemp = AUTOSAVE_SETTEMP; confBas.autoSaveHeatingMode = AUTOSAVE_SETMODE; confBas.saveToMqttRetained = SAVE_TO_MQTT_RETAINED; confBas.measureInterval = DEFAULT_MEASURE_INTERVAL; confBas.displayInterval = DEFAULT_DISPLAY_INTERVAL; confBas.displayTimeout = DEFAULT_DISPLAY_TIMEOUT; confBas.PIR_enablesDisplay = DEFAULT_PIR_ENABLES_DISPLAY; confBas.PIR_enablesDisplay_preset0only = DEFAULT_PIR_ENABLES_DISPLAY_PRESET0_ONLY; confBas.togglingTempHumAIDisplay = DEFAULT_TOGGLING_I_O_TEMPHUM; confBas.wasChanged = false; // confAdv confAdv.hysteresis = DEFAULT_HYSTERESIS; confAdv.heatingMinOffTime = DEFAULT_HEATING_MIN_OFFTIME; confAdv.tempCorrVal = TEMPSENSOR_CORRECTION_VALUE; confAdv.humCorrVal = HUMSENSOR_CORRECTION_VALUE; confAdv.setTempDecreaseVal = SETTEMP_DECREASE_VALUE; strlcpy(confAdv.offMessage, OFF_MESSAGE, sizeof(confAdv.offMessage)); strlcpy(confAdv.iTempLabel, INSIDE_TEMP_LABEL, sizeof(confAdv.iTempLabel)); strlcpy(confAdv.oTempLabel, OUTSIDE_TEMP_LABEL, sizeof(confAdv.oTempLabel)); strlcpy(confAdv.modeName0, MODE_NAME_0, sizeof(confAdv.modeName0)); strlcpy(confAdv.modeName1, MODE_NAME_1, sizeof(confAdv.modeName1)); strlcpy(confAdv.psetName0, PRESET_NAME_0, sizeof(confAdv.psetName0)); strlcpy(confAdv.psetName1, PRESET_NAME_1, sizeof(confAdv.psetName1)); strlcpy(confAdv.psetName2, PRESET_NAME_2, sizeof(confAdv.psetName2)); confAdv.pauseTout = 1800; confAdv.wasChanged = false; // confAdd strlcpy(confAdd.mqtt_topic_pir, MQTT_TOPIC_PIR, sizeof(confAdd.mqtt_topic_pir)); strlcpy(confAdd.mqtt_payload_pir_on, MQTT_TOPIC_PIR_ON, sizeof(confAdd.mqtt_payload_pir_on)); strlcpy(confAdd.mqtt_payload_pir_off, MQTT_TOPIC_PIR_OFF, sizeof(confAdd.mqtt_payload_pir_off)); strlcpy(confAdd.outTemp_topic_in, OUTTEMP_TOPIC_IN, sizeof(confAdd.outTemp_topic_in)); strlcpy(confAdd.outHum_topic_in, OUTHUM_TOPIC_IN, sizeof(confAdd.outHum_topic_in)); confAdd.wasChanged = false; // confTime #ifdef ENABLE_FEATURE_NTP_TIME confTime.ntpEnable = DEFAULT_NTP_ENABLED; strlcpy(confTime.timeZoneStr, DEFAULT_TIMEZONE, sizeof(confTime.timeZoneStr)); strlcpy(confTime.ntpServer1, DEFAULT_NTP_SERVER, sizeof(confTime.ntpServer1)); confTime.ntpSyncInterval = DEFAULT_NTP_SYNC_INTERVAL; confTime.wasChanged = false; #endif // confLog confLog.logLevelSerial = DEFAULT_LOGLEVEL_SERIAL; confLog.logLevelWeb = DEFAULT_LOGLEVEL_WEB; confLog.logLevelMqtt = DEFAULT_LOGLEVEL_MQTT; confLog.logLevelSyslog = DEFAULT_LOGLEVEL_SYSLOG; confLog.wasChanged = false; } void loadConf_restoreDefaultWhenMissing() { if (strlen(confDevWiFi.deviceName) < 4) createDeviceName(); if (strlen(confDevWiFi.hostName) < 4) strlcpy(confDevWiFi.hostName, confDevWiFi.deviceName, sizeof(confDevWiFi.hostName)); if (confAdv.modeName0[0] == '\0') strlcpy(confAdv.modeName0, MODE_NAME_0, sizeof(confAdv.modeName0)); if (confAdv.modeName1[0] == '\0') strlcpy(confAdv.modeName1, MODE_NAME_1, sizeof(confAdv.modeName1)); if (confAdv.psetName0[0] == '\0') strlcpy(confAdv.psetName0, PRESET_NAME_0, sizeof(confAdv.psetName0)); if (confAdv.psetName1[0] == '\0') strlcpy(confAdv.psetName1, PRESET_NAME_1, sizeof(confAdv.psetName1)); if (confAdv.psetName2[0] == '\0') strlcpy(confAdv.psetName2, PRESET_NAME_2, sizeof(confAdv.psetName2)); if (confAdv.iTempLabel[0] == '\0') strlcpy(confAdv.iTempLabel, INSIDE_TEMP_LABEL, sizeof(confAdv.iTempLabel)); if (confAdv.oTempLabel[0] == '\0') strlcpy(confAdv.oTempLabel, OUTSIDE_TEMP_LABEL, sizeof(confAdv.oTempLabel)); if (confDevWiFi.WiFiConnCheckInterval == 0) confDevWiFi.WiFiConnCheckInterval = DEFAULT_WIFI_CONNCHECK_INTERVAL; //NTP #ifdef ENABLE_FEATURE_NTP_TIME if (confTime.ntpEnable && strlen(confTime.ntpServer1) == 0) strlcpy(confTime.ntpServer1, DEFAULT_NTP_SERVER, sizeof(confTime.ntpServer1)); if (confTime.ntpEnable && strlen(confTime.timeZoneStr) == 0) strlcpy(confTime.timeZoneStr, DEFAULT_TIMEZONE, sizeof(confTime.timeZoneStr)); #endif } void confClearCredentials() { strcpy(confWeb.http_token, ""); strcpy(confWeb.http_pass, ""); strcpy(confWeb.http_pass1, ""); strcpy(confWeb.http_pass2, ""); saveConfigWeb(); strcpy(confMqtt.mqtt_pass, ""); saveConfigMqtt(); sendLog(F("CONF: cleared credentials")); } void confClearWiFiCredentials() { strcpy(confDevWiFi.WiFiPW1, ""); strcpy(confDevWiFi.WiFiPW2, ""); strcpy(confDevWiFi.WiFiAPModePassword, ""); saveConfigDevWiFi(); sendLog(F("CONF: cleared WiFi credentials")); } bool confCheckEncrypted() { if (SPIFFS.exists("/isEncrypted")) { confEncryptionEnabled = true; sendLog("CONF: is encrypted"); return true; } else { confEncryptionEnabled = false; sendLog("CONF: is NOT encrypted"); return false; } } void confEncrypt() { if (!confCheckEncrypted()) { sendLog(F("CONF: encrypting config...")); confEncryptionEnabled = true; saveConfig_all(); File configFile = SPIFFS.open("/isEncrypted", "w"); configFile.close(); sendLog(F("CONF: config encryption DONE")); } else { sendLog(F("CONF: already encrypted.")); } } void confDecrypt() { if (confCheckEncrypted()) { sendLog(F("CONF: decrypting config...")); confEncryptionEnabled = false; confClearCredentials(); confClearWiFiCredentials(); SPIFFS.remove("/isEncrypted"); sendLog(F("CONF: config decrypted. all credentials were deleted. please re-enter WiFi credentials before reboot!")); } else { sendLog(F("CONF: config is not encrypted.")); } } bool confCheckUnsaved() { bool confChanged = false; if (confDevWiFi.wasChanged) confChanged = true; if (confWeb.wasChanged) confChanged = true; if (confMqtt.wasChanged) confChanged = true; if (confBas.wasChanged) confChanged = true; if (confAdv.wasChanged) confChanged = true; if (confAdd.wasChanged) confChanged = true; if (confTime.wasChanged) confChanged = true; if (confLog.wasChanged) confChanged = true; return confChanged; } void confChangedLogNote(bool force = false) { if (confCheckUnsaved() && (force || (!lastConfigChangeNoteAlreadyDone && (millis() - lastConfigChange) > 5000))) { sendLog(F("NOTE: pending config changes. Execute 'saveconf' to save or 'loadconf' to discard.")); confMqttConnResetRequiredLogNote(); confRestartRequiredLogNote(); lastConfigChangeNoteAlreadyDone = true; } if(force) { confMqttConnResetRequiredLogNote(); confRestartRequiredLogNote(); } } void confRestartRequiredLogNote() { if (configChangedRestartRequired) sendLog(F("NOTE: config changes require restart. Remember 'saveconf' before!")); } void confMqttConnResetRequiredLogNote() { if (configChangedMqttConnResetRequired) sendLog(F("NOTE: MQTT config changes require connection reset -> will be done automatically on 'saveconf'.")); }