123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220 |
- // 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 (serialdebug)
- {
- 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 (strlen(value) >= 4)
- strlcpy(confDevWiFi.deviceName, value, sizeof(confDevWiFi.deviceName));
- }
- else if (strcmp(param, "hostname") == 0)
- {
- if (strlen(value) >= 4)
- strlcpy(confDevWiFi.hostName, value, sizeof(confDevWiFi.hostName));
- }
- else if (strcmp(param, "ssid1") == 0)
- {
- strlcpy(confDevWiFi.WiFiSSID1, value, sizeof(confDevWiFi.WiFiSSID1));
- }
- else if (strcmp(param, "wpw1") == 0)
- {
- if(!strcmp(value,"****") == 0) strlcpy(confDevWiFi.WiFiPW1, value, sizeof(confDevWiFi.WiFiPW1));
- }
- else if (strcmp(param, "ssid2") == 0)
- {
- strlcpy(confDevWiFi.WiFiSSID2, value, sizeof(confDevWiFi.WiFiSSID2));
- }
- else if (strcmp(param, "wpw2") == 0)
- {
- if(!strcmp(value,"****") == 0) strlcpy(confDevWiFi.WiFiPW2, value, sizeof(confDevWiFi.WiFiPW2));
- }
- else if (strcmp(param, "wpwap") == 0)
- {
- if(!strcmp(value,"****") == 0) strlcpy(confDevWiFi.WiFiAPModePassword, value, sizeof(confDevWiFi.WiFiAPModePassword));
- }
- else if (strcmp(param, "waptout") == 0)
- {
- int tmpval = atoi(value);
- if (tmpval >= 0 && tmpval <= 120)
- confDevWiFi.WiFiAPModeTimeout = tmpval;
- }
- else if (strcmp(param, "wconncheck") == 0)
- {
- int tmpval = atoi(value);
- if (tmpval >= 10 && tmpval <= 3600)
- confDevWiFi.WiFiConnCheckInterval = tmpval;
- }
- else if (strcmp(param, "wretry") == 0)
- {
- int tmpval = atoi(value);
- if (tmpval >= 0 && tmpval <= 120)
- confDevWiFi.WiFiRetryInterval = tmpval;
- }
- else if (strcmp(param, "wreboot") == 0)
- {
- int tmpval = atoi(value);
- if (tmpval >= 0 && tmpval <= 2880)
- confDevWiFi.WiFiRebootOnNoConnect = tmpval;
- }
- // confWeb
- else if (strcmp(param, "apitoken") == 0)
- {
- if(!strcmp(value,"****") == 0) strlcpy(confWeb.http_token, value, sizeof(confWeb.http_token));
- }
- else if (strcmp(param, "httpua") == 0)
- {
- strlcpy(confWeb.http_user, value, sizeof(confWeb.http_user));
- }
- else if (strcmp(param, "httppa") == 0)
- {
- if(!strcmp(value,"****") == 0) strlcpy(confWeb.http_pass, value, sizeof(confWeb.http_pass));
- }
- else if (strcmp(param, "httpauth") == 0)
- {
- if (atoi(value) == 1)
- confWeb.http_user_auth = true;
- else
- confWeb.http_user_auth = false;
- }
- else if (strcmp(param, "httpu1") == 0)
- {
- strlcpy(confWeb.http_user1, value, sizeof(confWeb.http_user1));
- }
- else if (strcmp(param, "httpp1") == 0)
- {
- if(!strcmp(value,"****") == 0) strlcpy(confWeb.http_pass1, value, sizeof(confWeb.http_pass1));
- }
- else if (strcmp(param, "httpu2") == 0)
- {
- strlcpy(confWeb.http_user2, value, sizeof(confWeb.http_user2));
- }
- else if (strcmp(param, "httpp2") == 0)
- {
- if(!strcmp(value,"****") == 0) strlcpy(confWeb.http_pass2, value, sizeof(confWeb.http_pass2));
- }
- else if (strcmp(param, "enableconsole") == 0)
- {
- if (atoi(value) == 1)
- confWeb.enableConsole = true;
- else
- confWeb.enableConsole = false;
- }
- // confMqtt
- else if (strcmp(param, "mqttenable") == 0)
- {
- if (atoi(value) == 1)
- confMqtt.mqtt_enable = true;
- else
- confMqtt.mqtt_enable = false;
- }
- else if (strcmp(param, "mqtthost") == 0)
- {
- strlcpy(confMqtt.mqtt_server, value, sizeof(confMqtt.mqtt_server));
- }
- else if (strcmp(param, "mqttport") == 0)
- {
- confMqtt.mqtt_port = atoi(value);
- }
- else if (strcmp(param, "mqttuser") == 0)
- {
- strlcpy(confMqtt.mqtt_user, value, sizeof(confMqtt.mqtt_user));
- }
- else if (strcmp(param, "mqttpass") == 0)
- {
- if(!strcmp(value,"****") == 0) strlcpy(confMqtt.mqtt_pass, value, sizeof(confMqtt.mqtt_pass));
- }
- else if (strcmp(param, "intop") == 0)
- {
- strlcpy(confMqtt.mqtt_topic_in, value, sizeof(confMqtt.mqtt_topic_in));
- }
- else if (strcmp(param, "outtop") == 0)
- {
- strlcpy(confMqtt.mqtt_topic_out, value, sizeof(confMqtt.mqtt_topic_out));
- }
- else if (strcmp(param, "outret") == 0)
- {
- if (atoi(value) == 1)
- confMqtt.mqtt_outRetain = true;
- else
- confMqtt.mqtt_outRetain = false;
- publishDeleteRetainedOutMessages();
- }
- else if (strcmp(param, "outretsens") == 0)
- {
- if (atoi(value) == 1)
- confMqtt.mqtt_outRetain_sensors = true;
- else
- confMqtt.mqtt_outRetain_sensors = false;
- publishDeleteRetainedOutMessages_sensors();
- }
- else if (strcmp(param, "outpubint") == 0) {
- confMqtt.mqtt_outPubInterval = atoi(value);
- }
- else if (strcmp(param, "outpubintsens") == 0) {
- confMqtt.mqtt_outPubInterval_sensors = atoi(value);
- }
- else if (strcmp(param, "willtop") == 0)
- {
- strlcpy(confMqtt.mqtt_willTopic, value, sizeof(confMqtt.mqtt_willTopic));
- }
- else if (strcmp(param, "willqos") == 0)
- {
- int tmpval = atoi(value);
- if (tmpval >= 0 && tmpval <= 2)
- confMqtt.mqtt_willQos = tmpval;
- }
- else if (strcmp(param, "willret") == 0)
- {
- if (atoi(value) == 1)
- confMqtt.mqtt_willRetain = true;
- else
- confMqtt.mqtt_willRetain = false;
- }
- else if (strcmp(param, "willmsg") == 0)
- {
- strlcpy(confMqtt.mqtt_willMsg, value, sizeof(confMqtt.mqtt_willMsg));
- }
- else if (strcmp(param, "connmsg") == 0)
- {
- strlcpy(confMqtt.mqtt_connMsg, value, sizeof(confMqtt.mqtt_connMsg));
- }
- else if (strcmp(param, "hbenable") == 0)
- {
- if (atoi(value) == 1)
- confMqtt.mqtt_enable_heartbeat = true;
- else
- confMqtt.mqtt_enable_heartbeat = false;
- }
- else if (strcmp(param, "hbreconn") == 0)
- {
- int tmpval = atoi(value);
- if (tmpval == 0)
- confMqtt.mqtt_heartbeat_maxage_reconnect = 0;
- else if (tmpval >= 2 && tmpval <= 10)
- confMqtt.mqtt_heartbeat_maxage_reconnect = tmpval * 60000;
- }
- else if (strcmp(param, "hbreboot") == 0)
- {
- int tmpval = atoi(value);
- if (tmpval == 0)
- confMqtt.mqtt_heartbeat_maxage_reboot = 0;
- else if (tmpval >= 10 && tmpval <= 120)
- confMqtt.mqtt_heartbeat_maxage_reboot = tmpval * 60000;
- }
- // confBas
- else if (strcmp(param, "autosavetemp") == 0)
- {
- if (atoi(value) == 1)
- confBas.autoSaveSetTemp = true;
- else
- confBas.autoSaveSetTemp = false;
- }
- else if (strcmp(param, "autosavemode") == 0)
- {
- if (atoi(value) == 1)
- confBas.autoSaveHeatingMode = true;
- else
- confBas.autoSaveHeatingMode = false;
- }
- else if (strcmp(param, "savetomqttret") == 0)
- {
- if (atoi(value) == 1)
- confBas.saveToMqttRetained = true;
- else
- confBas.saveToMqttRetained = false;
- publishDeleteRetainedSavedStates();
- }
- else if (strcmp(param, "tempmin") == 0)
- {
- float valueFloat = round(atof(value) * 2.0) / 2.0;
- if (valueFloat >= 10 && valueFloat <= 16)
- {
- confBas.setTempMin = valueFloat;
- }
- }
- else if (strcmp(param, "tempmax") == 0)
- {
- float valueFloat = round(atof(value) * 2.0) / 2.0;
- if (valueFloat >= 18 && valueFloat <= 30)
- {
- confBas.setTempMax = valueFloat;
- }
- }
- else if (strcmp(param, "measint") == 0)
- {
- int valueInt = atoi(value);
- if (valueInt >= 5 && valueInt <= 120)
- {
- confBas.measureInterval = valueInt;
- }
- }
- else if (strcmp(param, "dispint") == 0)
- {
- int valueInt = atoi(value);
- if (valueInt >= 2 && valueInt <= 120)
- {
- confBas.displayInterval = valueInt;
- }
- }
- else if (strcmp(param, "disptout") == 0)
- {
- int valueInt = atoi(value);
- if (valueInt >= 2 && valueInt <= 1200)
- {
- confBas.displayTimeout = valueInt;
- }
- }
- else if (strcmp(param, "pirendisp") == 0)
- {
- int valueInt = atoi(value);
- if (valueInt == 1)
- confBas.PIR_enablesDisplay = true;
- else
- confBas.PIR_enablesDisplay = false;
- }
- else if (strcmp(param, "pirendispps0") == 0)
- {
- int valueInt = atoi(value);
- if (valueInt == 1)
- confBas.PIR_enablesDisplay_preset0only = true;
- else
- confBas.PIR_enablesDisplay_preset0only = false;
- }
- else if (strcmp(param, "togthdisp") == 0)
- {
- int valueInt = atoi(value);
- if (valueInt == 1)
- confBas.togglingTempHumAIDisplay = true;
- else
- confBas.togglingTempHumAIDisplay = false;
- }
- // confAdv
- else if (strcmp(param, "minofftime") == 0)
- {
- confAdv.heatingMinOffTime = atoi(value);
- }
- else if (strcmp(param, "tempdec") == 0)
- {
- float valueFloat = atof(value);
- if (valueFloat >= 0.0 && valueFloat <= 1.5)
- {
- confAdv.setTempDecreaseVal = valueFloat;
- }
- }
- else if (strcmp(param, "hyst") == 0)
- {
- float valueFloat = atof(value);
- if (valueFloat >= 0.1 && valueFloat <= 4.0)
- {
- confAdv.hysteresis = valueFloat;
- }
- }
- else if (strcmp(param, "tempcorr") == 0)
- {
- float valueFloat = atof(value);
- if (valueFloat >= -5.0 && valueFloat <= 5.0)
- {
- confAdv.tempCorrVal = valueFloat;
- }
- }
- else if (strcmp(param, "humcorr") == 0)
- {
- int valueInt = atoi(value);
- if (valueInt >= -40 && valueInt <= 40)
- {
- confAdv.humCorrVal = valueInt;
- }
- }
- else if (strcmp(param, "offmsg") == 0)
- {
- strlcpy(confAdv.offMessage, value, sizeof(confAdv.offMessage));
- }
- else if (strcmp(param, "modename0") == 0)
- {
- strlcpy(confAdv.modeName0, value, sizeof(confAdv.modeName0));
- }
- else if (strcmp(param, "modename1") == 0)
- {
- strlcpy(confAdv.modeName1, value, sizeof(confAdv.modeName1));
- }
- else if (strcmp(param, "psetname0") == 0)
- {
- strlcpy(confAdv.psetName0, value, sizeof(confAdv.psetName0));
- }
- else if (strcmp(param, "psetname1") == 0)
- {
- strlcpy(confAdv.psetName1, value, sizeof(confAdv.psetName1));
- }
- else if (strcmp(param, "psetname2") == 0)
- {
- strlcpy(confAdv.psetName2, value, sizeof(confAdv.psetName2));
- }
- else if (strcmp(param, "itemplab") == 0)
- {
- strlcpy(confAdv.iTempLabel, value, sizeof(confAdv.iTempLabel));
- }
- else if (strcmp(param, "otemplab") == 0)
- {
- strlcpy(confAdv.oTempLabel, value, sizeof(confAdv.oTempLabel));
- }
- // confAdd
- else if (strcmp(param, "outtemptop") == 0)
- {
- strlcpy(confAdd.outTemp_topic_in, value, sizeof(confAdd.outTemp_topic_in));
- }
- else if (strcmp(param, "outhumtop") == 0)
- {
- strlcpy(confAdd.outHum_topic_in, value, sizeof(confAdd.outHum_topic_in));
- }
- else if (strcmp(param, "pirtop") == 0)
- {
- strlcpy(confAdd.mqtt_topic_pir, value, sizeof(confAdd.mqtt_topic_pir));
- }
- else if (strcmp(param, "pironpld") == 0)
- {
- strlcpy(confAdd.mqtt_payload_pir_on, value, sizeof(confAdd.mqtt_payload_pir_on));
- }
- else if (strcmp(param, "piroffpld") == 0)
- {
- strlcpy(confAdd.mqtt_payload_pir_off, value, sizeof(confAdd.mqtt_payload_pir_off));
- }
- // confTime
- else if (strcmp(param, "tzstr") == 0)
- {
- strlcpy(confTime.timeZoneStr, value, sizeof(confTime.timeZoneStr));
- }
- else if (strcmp(param, "ntpenable") == 0)
- {
- int valueInt = atoi(value);
- if (valueInt == 1)
- confTime.ntpEnable = true;
- else
- confTime.ntpEnable = false;
- }
- else if (strcmp(param, "ntpserver1") == 0)
- {
- strlcpy(confTime.ntpServer1, value, sizeof(confTime.ntpServer1));
- }
- else if (strcmp(param, "ntpserver2") == 0)
- {
- strlcpy(confTime.ntpServer2, value, sizeof(confTime.ntpServer2));
- }
- else if (strcmp(param, "ntpsyncint") == 0)
- {
- confTime.ntpSyncInterval = atoi(value);
- }
- // confLog
- else if (strcmp(param, "loglevser") == 0)
- {
- int valueInt = atoi(value);
- if (valueInt >= 0 && valueInt <= 5)
- confLog.logLevelSerial = valueInt;
- }
- else if (strcmp(param, "loglevweb") == 0)
- {
- int valueInt = atoi(value);
- if (valueInt >= 0 && valueInt <= 5)
- confLog.logLevelWeb = valueInt;
- }
- else if (strcmp(param, "loglevmqtt") == 0)
- {
- int valueInt = atoi(value);
- if (valueInt >= 0 && valueInt <= 5)
- confLog.logLevelMqtt = valueInt;
- }
- }
- /*
- void getConfig(char *param)
- {
- // gets and prints the corresponding config variable for 'param'
- if (serialdebug)
- {
- 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);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "tempLow") == 0)
- {
- char buf2[11];
- dtostrf(setTempLow, 2, 1, buf2);
- sprintf(buf, "setTempLow: '%s'", buf2);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "tempLow2") == 0)
- {
- char buf2[11];
- dtostrf(setTempLow2, 2, 1, buf2);
- sprintf(buf, "setTempLow2: '%s'", buf2);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "mode") == 0)
- {
- sprintf(buf, "heatingMode: '%d'", heatingMode);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "preset") == 0)
- {
- sprintf(buf, "preset: '%d'", preset);
- mqttSendLog(buf);
- }
- // confdata
- else if (strcmp(param, "devName") == 0)
- {
- sprintf(buf, "devName: '%s'", deviceName);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "hostName") == 0)
- {
- sprintf(buf, "hostName: '%s'", hostName);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "wifiappw") == 0)
- {
- sprintf(buf, "wifiappw: '%s'", WiFiAPModePassword);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "httpUser") == 0)
- {
- sprintf(buf, "httpUser: '%s'", http_user);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "httpPass") == 0)
- {
- sprintf(buf, "httpPass: '%s'", http_pass);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "httpToken") == 0)
- {
- sprintf(buf, "httpToken: '%s'", http_token);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "mqttHost") == 0)
- {
- sprintf(buf, "mqttHost: '%s'", mqtt_server);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "mqttPort") == 0)
- {
- sprintf(buf, "mqttPort: '%d'", mqtt_port);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "mqttUser") == 0)
- {
- sprintf(buf, "mqttUser: '%s'", mqtt_user);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "mqttPass") == 0)
- {
- sprintf(buf, "mqttPass: '%s'", mqtt_pass);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "inTop") == 0)
- {
- sprintf(buf, "inTop: '%s'", mqtt_topic_in);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "outTop") == 0)
- {
- sprintf(buf, "outTop: '%s'", mqtt_topic_out);
- mqttSendLog(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);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "willTop") == 0)
- {
- sprintf(buf, "willTop: '%s'", mqtt_willTopic);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "willQos") == 0)
- {
- sprintf(buf, "willQos: '%d'", mqtt_willQos);
- mqttSendLog(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);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "willMsg") == 0)
- {
- sprintf(buf, "willMsg: '%s'", mqtt_willMsg);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "connMsg") == 0)
- {
- sprintf(buf, "connMsg: '%s'", mqtt_connMsg);
- mqttSendLog(buf);
- }
- // confdata2
- else if (strcmp(param, "outTempTop") == 0)
- {
- sprintf(buf, "outTempTop: '%s'", outTemp_topic_in);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "outHumTop") == 0)
- {
- sprintf(buf, "outHumTop: '%s'", outHum_topic_in);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "PIRTop") == 0)
- {
- sprintf(buf, "PIRTop: '%s'", mqtt_topic_pir);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "autoSaveTemp") == 0)
- {
- char buf2[11];
- if (autoSaveSetTemp)
- strcpy(buf2, "1");
- else
- strcpy(buf2, "0");
- sprintf(buf, "autoSaveTemp: '%s'", buf2);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "autoSaveMode") == 0)
- {
- char buf2[11];
- if (autoSaveHeatingMode)
- strcpy(buf2, "1");
- else
- strcpy(buf2, "0");
- sprintf(buf, "autoSaveMode: '%s'", buf2);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "minOffTime") == 0)
- {
- sprintf(buf, "minOffTime: '%d'", heatingMinOffTime);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "tempMin") == 0)
- {
- char buf2[11];
- dtostrf(setTempMin, 2, 1, buf2);
- sprintf(buf, "tempMin: '%s'", buf2);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "tempMax") == 0)
- {
- char buf2[11];
- dtostrf(setTempMax, 2, 1, buf2);
- sprintf(buf, "tempMax: '%s'", buf2);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "tempDec") == 0)
- {
- char buf2[11];
- dtostrf(setTempDecreaseVal, 2, 1, buf2);
- sprintf(buf, "tempDec: '%s'", buf2);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "hyst") == 0)
- {
- char buf2[11];
- dtostrf(hysteresis, 2, 1, buf2);
- sprintf(buf, "hyst: '%s'", buf2);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "tempCorr") == 0)
- {
- char buf2[11];
- dtostrf(tempCorrVal, 2, 1, buf2);
- sprintf(buf, "tempCorr: '%s'", buf2);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "humCorr") == 0)
- {
- sprintf(buf, "humCorr: '%d'", humCorrVal);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "measInt") == 0)
- {
- sprintf(buf, "measInt: '%d'", measureInterval);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "dispInt") == 0)
- {
- sprintf(buf, "dispInt: '%d'", displayInterval);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "dispTout") == 0)
- {
- sprintf(buf, "dispTout: '%d'", displayTimeout);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "offMsg") == 0)
- {
- sprintf(buf, "offMsg: '%s'", offMessage);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "modename0") == 0)
- {
- sprintf(buf, "modename0: '%s'", modename0);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "modename1") == 0)
- {
- sprintf(buf, "modename1: '%s'", modename1);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "psetname0") == 0)
- {
- sprintf(buf, "psetname0: '%s'", psetname0);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "psetname1") == 0)
- {
- sprintf(buf, "psetname1: '%s'", psetname1);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "psetname2") == 0)
- {
- sprintf(buf, "psetname2: '%s'", psetname2);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "itemplab") == 0)
- {
- sprintf(buf, "itemplab: '%s'", itemplab);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "otemplab") == 0)
- {
- sprintf(buf, "otemplab: '%s'", otemplab);
- mqttSendLog(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);
- mqttSendLog(buf);
- }
- else if (strcmp(param, "togTHdisp") == 0)
- {
- char buf2[11];
- if (togglingTempHumAIDisplay)
- strcpy(buf2, "1");
- else
- strcpy(buf2, "0");
- sprintf(buf, "togTHdisp: '%d'", togglingTempHumAIDisplay);
- mqttSendLog(buf);
- }
- }*/
- void printConfigDevWiFi()
- {
- // prints current config vars to serial
- Serial.print("\nconfDataDevWiFi: ");
- Serial.print("devName: ");
- Serial.print(confDevWiFi.deviceName);
- Serial.print(", hostName: ");
- Serial.print(confDevWiFi.hostName);
- Serial.print(", WiFiSSID1: ");
- Serial.print(confDevWiFi.WiFiSSID1);
- //Serial.print(", WiFiPW1: ");
- //Serial.print(confDevWiFi.WiFiPW1);
- Serial.print(", WiFiSSID2: ");
- Serial.print(confDevWiFi.WiFiSSID2);
- //Serial.print(", WiFiPW2: ");
- //Serial.print(confDevWiFi.WiFiPW2);
- Serial.print(", WiFiAPModePassword: ");
- Serial.print(confDevWiFi.WiFiAPModePassword);
- Serial.print(", WiFiAPModeTimeout: ");
- Serial.print(confDevWiFi.WiFiAPModeTimeout);
- Serial.print(", WiFiConnCheckInterval: ");
- Serial.print(confDevWiFi.WiFiConnCheckInterval);
- Serial.print(", WiFiRetryInterval: ");
- Serial.print(confDevWiFi.WiFiRetryInterval);
- Serial.print(", WiFiRebootNoConnect: ");
- Serial.print(confDevWiFi.WiFiRebootOnNoConnect);
- Serial.println();
- }
- void printConfigWeb()
- {
- // prints current config vars to serial
- Serial.print("\nconfDataWeb: ");
- Serial.print("apiToken: ");
- Serial.print(confWeb.http_token);
- Serial.print(", httpUA: ");
- Serial.print(confWeb.http_user);
- //Serial.print(", httpPA: ");
- //Serial.print(confWeb.http_pass);
- Serial.print(", httpAuth: ");
- Serial.print(confWeb.http_user_auth);
- Serial.print(", httpU1: ");
- Serial.print(confWeb.http_user1);
- //Serial.print(", httpP1: ");
- //Serial.print(confWeb.http_pass1);
- Serial.print(", httpU2: ");
- Serial.print(confWeb.http_user2);
- //Serial.print(", httpP2: ");
- //Serial.print(confWeb.http_pass2);
- Serial.println();
- }
- void printConfigMqtt()
- {
- // prints current config vars to serial
- Serial.print("\nconfDataMqtt: ");
- Serial.print("mqttEnable: ");
- Serial.print(confMqtt.mqtt_enable);
- Serial.print(", mqttHost: ");
- Serial.print(confMqtt.mqtt_server);
- Serial.print(", mqttPort: ");
- Serial.print(confMqtt.mqtt_port);
- Serial.print(", mqttUser: ");
- Serial.print(confMqtt.mqtt_user);
- //Serial.print(", mqttPass: ");
- //Serial.print(confMqtt.mqtt_pass);
- Serial.print(", inTop: ");
- Serial.print(confMqtt.mqtt_topic_in);
- Serial.print(", outTop: ");
- Serial.print(confMqtt.mqtt_topic_out);
- Serial.print(", outRet: ");
- Serial.print(confMqtt.mqtt_outRetain);
- Serial.print(", outRetSens: ");
- Serial.print(confMqtt.mqtt_outRetain_sensors);
- Serial.print(", outPubInt: ");
- Serial.print(confMqtt.mqtt_outPubInterval);
- Serial.print(", outPubIntSens: ");
- Serial.print(confMqtt.mqtt_outPubInterval_sensors);
- Serial.print(", willTop: ");
- Serial.print(confMqtt.mqtt_willTopic);
- Serial.print(", willQos: ");
- Serial.print(confMqtt.mqtt_willQos);
- Serial.print(", willRet: ");
- Serial.print(confMqtt.mqtt_willRetain);
- Serial.print(", willMsg: ");
- Serial.print(confMqtt.mqtt_willMsg);
- Serial.print(", connMsg: ");
- Serial.print(confMqtt.mqtt_connMsg);
- Serial.print(", hbEnable: ");
- Serial.print(confMqtt.mqtt_enable_heartbeat);
- Serial.print(", hbReconn: ");
- Serial.print(confMqtt.mqtt_heartbeat_maxage_reconnect);
- Serial.print(", hbReboot: ");
- Serial.print(confMqtt.mqtt_heartbeat_maxage_reboot);
- Serial.println();
- }
- 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<char[]> 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(confDevWiFi.deviceName, json["devName"] | "", sizeof(confDevWiFi.deviceName));
- strlcpy(confDevWiFi.hostName, json["hostName"] | "", sizeof(confDevWiFi.hostName));
- strlcpy(confDevWiFi.WiFiSSID1, json["SSID1"] | "", sizeof(confDevWiFi.WiFiSSID1));
- strlcpy(confDevWiFi.WiFiPW1, json["WPW1"] | "", sizeof(confDevWiFi.WiFiPW1));
- strlcpy(confDevWiFi.WiFiSSID2, json["SSID2"] | "", sizeof(confDevWiFi.WiFiSSID2));
- strlcpy(confDevWiFi.WiFiPW2, json["WPW2"] | "", sizeof(confDevWiFi.WiFiPW2));
- strlcpy(confDevWiFi.WiFiAPModePassword, json["WPWAP"] | "", sizeof(confDevWiFi.WiFiAPModePassword));
- 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:"));
- printConfigDevWiFi();
- 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<char[]> 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(confWeb.http_token, json["apiToken"] | "", sizeof(confWeb.http_token));
- strlcpy(confWeb.http_user, json["httpUA"] | "", sizeof(confWeb.http_user));
- strlcpy(confWeb.http_pass, json["httpPA"] | "", sizeof(confWeb.http_pass));
- 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));
- strlcpy(confWeb.http_pass1, json["httpP1"] | "", sizeof(confWeb.http_pass1));
- strlcpy(confWeb.http_user2, json["httpU2"] | "", sizeof(confWeb.http_user2));
- strlcpy(confWeb.http_pass2, json["httpP2"] | "", sizeof(confWeb.http_pass2));
- if ((json["enableConsole"] | 0) == 1)
- confWeb.enableConsole = true;
- else
- confWeb.enableConsole = false;
- Serial.println(F("Loaded config values:"));
- printConfigWeb();
- 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<char[]> 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));
- strlcpy(confMqtt.mqtt_pass, json["mqttPass"] | "", sizeof(confMqtt.mqtt_pass));
- 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:"));
- printConfigMqtt();
- 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<char[]> 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:"));
- // printConfigBas();
- 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<char[]> 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.1;
- confAdv.heatingMinOffTime = json["minOffTime"] | 120;
- confAdv.tempCorrVal = json["tempCorr"] | 0;
- confAdv.humCorrVal = json["humCorr"] | 0;
- confAdv.setTempDecreaseVal = json["tempDec"] | 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));
- // Serial.println("Loaded config values:");
- // printConfigWeb();
- 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<char[]> 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:");
- // printConfigWeb();
- 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
- 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<char[]> 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));
- confTime.ntpSyncInterval = json["NTPSyncInt"];
- strlcpy(confTime.timeZoneStr, json["TZstr"] | "", sizeof(confTime.timeZoneStr));
- // Serial.println("Loaded config values:");
- // printConfigWeb();
- 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
- 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<char[]> 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"];
- // Serial.println("Loaded config values:");
- // printConfigWeb();
- 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
- char configFileName[] = "/confWeb.json";
- DynamicJsonDocument json(1050);
- json["apiToken"] = confWeb.http_token;
- json["httpUA"] = confWeb.http_user;
- json["httpPA"] = confWeb.http_pass;
- if (confWeb.http_user_auth)
- json["httpAuth"] = 1;
- else
- json["httpAuth"] = 0;
- json["httpU1"] = confWeb.http_user1;
- json["httpP1"] = confWeb.http_pass1;
- json["httpU2"] = confWeb.http_user2;
- json["httpP2"] = confWeb.http_pass2;
- if (confWeb.enableConsole)
- json["enableConsole"] = 1;
- else
- json["enableConsole"] = 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);
- return true;
- } // saveConfigWeb
- boolean saveConfigMqtt()
- { // safeConfig
- 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;
- json["mqttPass"] = confMqtt.mqtt_pass;
- 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);
- return true;
- } // saveConfigMqtt
- boolean saveConfigDevWiFi()
- { // saveConfig
- char configFileName[] = "/confDevWiFi.json";
- DynamicJsonDocument json(1050);
- json["devName"] = confDevWiFi.deviceName;
- json["hostName"] = confDevWiFi.hostName;
- json["SSID1"] = confDevWiFi.WiFiSSID1;
- json["WPW1"] = confDevWiFi.WiFiPW1;
- json["SSID2"] = confDevWiFi.WiFiSSID2;
- json["WPW2"] = confDevWiFi.WiFiPW2;
- json["WPWAP"] = confDevWiFi.WiFiAPModePassword;
- 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);
- return true;
- } // saveConfigDev
- boolean saveConfigBas()
- { // safeConfig
- 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);
- return true;
- } // saveConfigBas
- boolean saveConfigAdv()
- { // safeConfig
- 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;
- 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);
- return true;
- } // saveConfigAdv
- boolean saveConfigAdd()
- { // safeConfig
- 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);
- return true;
- } // saveConfigAdd
- boolean saveConfigTime()
- {
- 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;
- 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);
- return true;
- } // saveConfigTime
- boolean saveConfigLog()
- {
- 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;
- 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);
- return true;
- } // saveConfigLog
- 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 saveSetTempLow()
- { // saveSetTempLow
- File configFile = SPIFFS.open("/setTempLow", "w");
- if (!configFile)
- {
- Serial.println("Failed to open setTempLow file for writing");
- return false;
- }
- configFile.println(setTempLow);
- configFile.close();
- setTempLowSaved = setTempLow;
- return true;
- } // saveSetTempLow
- boolean saveSetTempLow2()
- { // saveSetTempLow
- File configFile = SPIFFS.open("/setTempLow2", "w");
- if (!configFile)
- {
- Serial.println("Failed to open setTempLow2 file for writing");
- return false;
- }
- configFile.println(setTempLow2);
- configFile.close();
- setTempLow2Saved = setTempLow2;
- return true;
- } // saveSetTempLow
- 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 deleteConfig()
- {
- Serial.println("deleting configuration");
- SPIFFS_format();
- delay(100);
- ESP.restart();
- }
- void loadConf_all()
- {
- loadConfigDevWiFi();
- loadConfigWeb();
- loadConfigMqtt();
- loadConfigBas();
- loadConfigAdv();
- loadConfigAdd();
- loadConfigTime();
- loadConfigLog();
- }
- void loadSavedValues()
- {
- loadSetTemp();
- loadSetTempLow();
- loadSetTempLow2();
- loadHeatingMode();
- loadPreset();
- }
- void SPIFFS_format()
- {
- Serial.println(F("formatting SPIFFS, please wait 30 secs"));
- SPIFFS.format();
- Serial.println(F("SPIFFS formatted"));
- File f = SPIFFS.open("/formatted", "w");
- if (!f)
- {
- Serial.println(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:"));
- Dir dir = SPIFFS.openDir("/");
- while (dir.next())
- {
- Serial.print(dir.fileName());
- File f = dir.openFile("r");
- Serial.print(" ");
- Serial.println(f.size());
- f.close();
- }
- Serial.println(F("----"));
- }
- void loadConf_defaults()
- {
- // confDev
- // strlcpy(deviceName, DEVICE_NAME, sizeof(deviceName));
- strlcpy(confDevWiFi.hostName, HOST_NAME, sizeof(confDevWiFi.hostName));
- strlcpy(confDevWiFi.WiFiAPModePassword, WIFI_APMODE_PASSWORD, sizeof(confDevWiFi.WiFiAPModePassword));
- // 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;
- // 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;
- // 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;
- // 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));
- // 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));
- // confTime
- strlcpy(confTime.timeZoneStr, TIMEZONE, sizeof(confTime.timeZoneStr));
- strlcpy(confTime.ntpServer1, NTP_SERVER, sizeof(confTime.ntpServer1));
- confTime.ntpSyncInterval = NTP_SYNC_INTERVAL;
- // confLog
- confLog.logLevelSerial = DEFAULT_LOGLEVEL_SERIAL;
- confLog.logLevelWeb = DEFAULT_LOGLEVEL_WEB;
- confLog.logLevelMqtt = DEFAULT_LOGLEVEL_MQTT;
- confLog.logLevelSyslog = DEFAULT_LOGLEVEL_SYSLOG;
-
- }
- void loadConf_restoreDefaultWhenMissing()
- {
- if (strlen(confDevWiFi.deviceName) < 4)
- createDeviceName();
- 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
- if(strlen(confTime.ntpServer1) == 0) strlcpy(confTime.ntpServer1, NTP_SERVER, sizeof(confTime.ntpServer1));
- }
|