1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021 |
- 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 ) {
- if (strlen(value) >= 4) strlcpy(deviceName, value, 31);
- }
- else if ( strcmp(param, "hostName") == 0 ) {
- strlcpy(hostName, value, 31);
- }
- else if ( strcmp(param, "wifiappw") == 0 ) {
- if (strlen(value) >= 8) strlcpy(wifiAPModePassword, 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, 15);
- }
- else if ( strcmp(param, "modename0") == 0 ) {
- strlcpy(modename0, value, 15);
- }
- else if ( strcmp(param, "modename1") == 0 ) {
- strlcpy(modename1, value, 15);
- }
- else if ( strcmp(param, "psetname0") == 0 ) {
- strlcpy(psetname0, value, 15);
- }
- else if ( strcmp(param, "psetname1") == 0 ) {
- strlcpy(psetname1, value, 15);
- }
- else if ( strcmp(param, "psetname2") == 0 ) {
- strlcpy(psetname2, value, 15);
- }
- else if ( strcmp(param, "itemplab") == 0 ) {
- strlcpy(itemplab, value, 2);
- }
- else if ( strcmp(param, "otemplab") == 0 ) {
- strlcpy(otemplab, value, 2);
- }
- 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, "hostName") == 0 ) {
- sprintf(buf, "hostName: '%s'", hostName);
- sendStatus(buf);
- }
- else if ( strcmp(param, "wifiappw") == 0 ) {
- sprintf(buf, "wifiappw: '%s'", wifiAPModePassword);
- 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, "itemplab") == 0 ) {
- sprintf(buf, "itemplab: '%s'", itemplab);
- sendStatus(buf);
- }
- else if ( strcmp(param, "otemplab") == 0 ) {
- sprintf(buf, "otemplab: '%s'", otemplab);
- 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("hostName: ");
- Serial.println(hostName);
- Serial.print("wifiappw: ");
- Serial.println(wifiAPModePassword);
- 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("itemplab: ");
- Serial.println(itemplab);
- Serial.print("otemplab: ");
- Serial.println(otemplab);
- 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(hostName, json["hostName"] | "", 31);
- strlcpy(wifiAPModePassword, json["wifiappw"] | "", 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"] | "", 15);
- strlcpy(modename1, json["modename1"] | "", 15);
- strlcpy(psetname0, json["psetname0"] | "", 15);
- strlcpy(psetname1, json["psetname1"] | "", 15);
- strlcpy(psetname2, json["psetname2"] | "", 15);
- strlcpy(itemplab, json["itemplab"] | "", 2);
- strlcpy(otemplab, json["otemplab"] | "", 2);
- strlcpy(offMessage, json["offMsg"] | "", 15);
- 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["hostName"] = hostName;
- json["wifiappw"] = wifiAPModePassword;
- 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["itemplab"] = itemplab;
- json["otemplab"] = otemplab;
- 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();
- }
- }
|