From 69f8f0b8063242f480007934c98c2da760c0e806 Mon Sep 17 00:00:00 2001 From: lumapu Date: Tue, 24 May 2022 21:52:27 +0200 Subject: [PATCH] * reduced heap size (>50%) by using 'F()' for (nearly) all static strings (mentioned by @stefan123t) --- tools/esp8266/app.cpp | 224 ++++++++++++++++++++------------------- tools/esp8266/defines.h | 2 +- tools/esp8266/hmRadio.h | 36 +------ tools/esp8266/hmSystem.h | 8 +- tools/esp8266/main.cpp | 66 +++++++----- tools/esp8266/main.h | 2 +- 6 files changed, 159 insertions(+), 179 deletions(-) diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index 51aa2ff1..a40bcc3d 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -62,7 +62,7 @@ void app::setup(uint32_t timeout) { mEep->read(ADDR_INV_MOD_PWR + (i * 2 * 4), modPwr, 4); if(0ULL != invSerial) { mSys->addInverter(invName, invSerial, modPwr); - DPRINTLN("add inverter: " + String(invName) + ", SN: " + String(invSerial, HEX)); + DPRINTLN(F("add inverter: ") + String(invName) + ", SN: " + String(invSerial, HEX)); } } mEep->read(ADDR_INV_INTERVAL, &mSendInterval); @@ -122,14 +122,14 @@ void app::setup(uint32_t timeout) { mSys->setup(); if(!mWifiSettingsValid) - DPRINTLN("Warn: your settings are not valid! check [IP]/setup"); + DPRINTLN(F("Warn: your settings are not valid! check [IP]/setup")); else { - DPRINTLN("\n\n----------------------------------------"); - DPRINTLN("Welcome to AHOY!"); - DPRINT("\npoint your browser to http://"); + DPRINTLN(F("\n\n----------------------------------------")); + DPRINTLN(F("Welcome to AHOY!")); + DPRINT(F("\npoint your browser to http://")); DPRINTLN(WiFi.localIP()); - DPRINTLN("to configure your device"); - DPRINTLN("----------------------------------------\n"); + DPRINTLN(F("to configure your device")); + DPRINTLN(F("----------------------------------------\n")); } } @@ -229,11 +229,11 @@ void app::loop(void) { mSendTicker = 0; if(mSerialDebug) - DPRINTLN("Free heap: 0x" + String(ESP.getFreeHeap(), HEX)); + DPRINTLN(F("Free heap: 0x") + String(ESP.getFreeHeap(), HEX)); if(!mSys->BufCtrl.empty()) { if(mSerialDebug) - DPRINTLN("recbuf not empty! #" + String(mSys->BufCtrl.getFill())); + DPRINTLN(F("recbuf not empty! #") + String(mSys->BufCtrl.getFill())); } Inverter<> *iv; for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) { @@ -248,8 +248,8 @@ void app::loop(void) { if(!mPayload[iv->id].complete) { mRxFailed++; if(mSerialDebug) { - DPRINT("Inverter #" + String(iv->id) + " "); - DPRINTLN("no Payload received!"); + DPRINT(F("Inverter #") + String(iv->id) + " "); + DPRINTLN(F("no Payload received!")); } } @@ -258,7 +258,7 @@ void app::loop(void) { yield(); if(mSerialDebug) - DPRINTLN("Requesting Inverter SN " + String(iv->serial.u64, HEX)); + DPRINTLN(F("Requesting Inverter SN ") + String(iv->serial.u64, HEX)); mSys->Radio.sendTimePacket(iv->radioId.u64, mPayload[iv->id].ts); mRxTicker = 0; } @@ -310,14 +310,14 @@ void app::processPayload(bool retransmit) { for(uint8_t i = 0; i < (mPayload[iv->id].maxPackId-1); i ++) { if(mPayload[iv->id].len[i] == 0) { if(mSerialDebug) - DPRINTLN("Error while retrieving data: Frame " + String(i+1) + " missing: Request Retransmit"); + DPRINTLN(F("Error while retrieving data: Frame ") + String(i+1) + F(" missing: Request Retransmit")); mSys->Radio.sendCmdPacket(iv->radioId.u64, 0x15, (0x81+i), true); } } } else { if(mSerialDebug) - DPRINTLN("Error while retrieving data: last frame missing: Request Retransmit"); + DPRINTLN(F("Error while retrieving data: last frame missing: Request Retransmit")); mSys->Radio.sendTimePacket(iv->radioId.u64, mPayload[iv->id].ts); } mSys->Radio.switchRxCh(100); @@ -334,7 +334,7 @@ void app::processPayload(bool retransmit) { } offs-=2; if(mSerialDebug) { - DPRINT("Payload (" + String(offs) + "): "); + DPRINT(F("Payload (") + String(offs) + "): "); mSys->Radio.dumpBuf(NULL, payload, offs); } mRxSuccess++; @@ -354,8 +354,8 @@ void app::processPayload(bool retransmit) { //----------------------------------------------------------------------------- void app::showIndex(void) { String html = FPSTR(index_html); - html.replace("{DEVICE}", mDeviceName); - html.replace("{VERSION}", mVersion); + html.replace(F("{DEVICE}"), mDeviceName); + html.replace(F("{VERSION}"), mVersion); mWeb->send(200, "text/html", html); } @@ -367,16 +367,16 @@ void app::showSetup(void) { uint16_t interval; String html = FPSTR(setup_html); - html.replace("{SSID}", mStationSsid); + html.replace(F("{SSID}"), mStationSsid); // PWD will be left at the default value (for protection) // -> the PWD will only be changed if it does not match the placeholder "{PWD}" - html.replace("{DEVICE}", String(mDeviceName)); - html.replace("{VERSION}", String(mVersion)); + html.replace(F("{DEVICE}"), String(mDeviceName)); + html.replace(F("{VERSION}"), String(mVersion)); if(mApActive) - html.replace("{IP}", String("http://192.168.1.1")); + html.replace(F("{IP}"), String(F("http://192.168.1.1"))); else - html.replace("{IP}", ("http://" + String(WiFi.localIP().toString()))); + html.replace(F("{IP}"), ("http://" + String(WiFi.localIP().toString()))); String inv; uint64_t invSerial; @@ -387,70 +387,70 @@ void app::showSetup(void) { mEep->read(ADDR_INV_ADDR + (i * 8), &invSerial); mEep->read(ADDR_INV_NAME + (i * MAX_NAME_LENGTH), invName, MAX_NAME_LENGTH); mEep->read(ADDR_INV_MOD_PWR + (i * 2 * 4), modPwr, 4); - inv += "

Inverter "+ String(i) + "

"; + inv += F("

Inverter ") + String(i) + "

"; - inv += ""; - inv += "Address"); + inv += F(""; + inv += F("\"/ maxlength=\"12\">"); - inv += ""; - inv += "Name"); + inv += F(""; + inv += F("\"/ maxlength=\"") + String(MAX_NAME_LENGTH) + "\">"; - inv += ""; + inv += F(""); for(uint8_t j = 0; j < 4; j++) { - inv += ""; + inv += F("\"/ maxlength=\"4\">"); } } - html.replace("{INVERTERS}", String(inv)); + html.replace(F("{INVERTERS}"), String(inv)); // pinout String pinout; for(uint8_t i = 0; i < 3; i++) { - pinout += ""; - pinout += ""; for(uint8_t j = 0; j <= 16; j++) { - pinout += ""; + pinout += ">" + String(wemosPins[j]) + F(""); } - pinout += ""; + pinout += F(""); } - html.replace("{PINOUT}", String(pinout)); + html.replace(F("{PINOUT}"), String(pinout)); // nrf24l01+ String rf24; for(uint8_t i = 0; i <= 3; i++) { - rf24 += ""; + rf24 += F(" selected"); + rf24 += ">" + String(rf24AmpPower[i]) + F(""); } - html.replace("{RF24}", String(rf24)); + html.replace(F("{RF24}"), String(rf24)); if(mSettingsValid) { mEep->read(ADDR_INV_INTERVAL, &interval); - html.replace("{INV_INTVL}", String(interval)); + html.replace(F("{INV_INTVL}"), String(interval)); uint8_t tmp; mEep->read(ADDR_SER_INTERVAL, &interval); mEep->read(ADDR_SER_ENABLE, &tmp); - html.replace("{SER_INTVL}", String(interval)); - html.replace("{SER_VAL_CB}", (tmp == 0x01) ? "checked" : ""); + html.replace(F("{SER_INTVL}"), String(interval)); + html.replace(F("{SER_VAL_CB}"), (tmp == 0x01) ? "checked" : ""); mEep->read(ADDR_SER_DEBUG, &tmp); - html.replace("{SER_DBG_CB}", (tmp == 0x01) ? "checked" : ""); + html.replace(F("{SER_DBG_CB}"), (tmp == 0x01) ? "checked" : ""); uint8_t mqttAddr[MQTT_ADDR_LEN] = {0}; uint16_t mqttPort; @@ -460,31 +460,31 @@ void app::showSetup(void) { char addr[16] = {0}; sprintf(addr, "%d.%d.%d.%d", mqttAddr[0], mqttAddr[1], mqttAddr[2], mqttAddr[3]); - html.replace("{MQTT_ADDR}", String(addr)); - html.replace("{MQTT_PORT}", String(mqttPort)); - html.replace("{MQTT_USER}", String(mMqtt.getUser())); - html.replace("{MQTT_PWD}", String(mMqtt.getPwd())); - html.replace("{MQTT_TOPIC}", String(mMqtt.getTopic())); - html.replace("{MQTT_INTVL}", String(interval)); + html.replace(F("{MQTT_ADDR}"), String(addr)); + html.replace(F("{MQTT_PORT}"), String(mqttPort)); + html.replace(F("{MQTT_USER}"), String(mMqtt.getUser())); + html.replace(F("{MQTT_PWD}"), String(mMqtt.getPwd())); + html.replace(F("{MQTT_TOPIC}"), String(mMqtt.getTopic())); + html.replace(F("{MQTT_INTVL}"), String(interval)); } else { - html.replace("{INV_INTVL}", "5"); + html.replace(F("{INV_INTVL}"), "5"); - html.replace("{SER_VAL_CB}", "checked"); - html.replace("{SER_DBG_CB}", ""); - html.replace("{SER_INTVL}", "10"); + html.replace(F("{SER_VAL_CB}"), "checked"); + html.replace(F("{SER_DBG_CB}"), ""); + html.replace(F("{SER_INTVL}"), "10"); - html.replace("{MQTT_ADDR}", ""); - html.replace("{MQTT_PORT}", "1883"); - html.replace("{MQTT_USER}", ""); - html.replace("{MQTT_PWD}", ""); - html.replace("{MQTT_TOPIC}", "inverter"); - html.replace("{MQTT_INTVL}", "10"); + html.replace(F("{MQTT_ADDR}"), ""); + html.replace(F("{MQTT_PORT}"), "1883"); + html.replace(F("{MQTT_USER}"), ""); + html.replace(F("{MQTT_PWD}"), ""); + html.replace(F("{MQTT_TOPIC}"), "inverter"); + html.replace(F("{MQTT_INTVL}"), "10"); - html.replace("{SER_INTVL}", "10"); + html.replace(F("{SER_INTVL}"), "10"); } - mWeb->send(200, "text/html", html); + mWeb->send(200, F("text/html"), html); } @@ -503,58 +503,60 @@ void app::showErase() { //----------------------------------------------------------------------------- void app::showStatistics(void) { - String content = "Receive success: " + String(mRxSuccess) + "\n"; - content += "Receive fail: " + String(mRxFailed) + "\n"; - content += "Send Cnt: " + String(mSys->Radio.mSendCnt) + String("\n\n"); + String content = F("Receive success: ") + String(mRxSuccess) + "\n"; + content += F("Receive fail: ") + String(mRxFailed) + "\n"; + content += F("Send Cnt: ") + String(mSys->Radio.mSendCnt) + String("\n\n"); - content += "Free Heap: 0x" + String(ESP.getFreeHeap(), HEX) + "\n\n"; + content += F("Free Heap: 0x") + String(ESP.getFreeHeap(), HEX) + "\n\n"; Inverter<> *iv; for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) { iv = mSys->getInverterByPos(i); if(NULL != iv) { bool avail = true; - content += "Inverter '"+ String(iv->name) + "' is "; + content += F("Inverter '") + String(iv->name) + F("' is "); if(!iv->isAvailable(mTimestamp)) { - content += "not "; + content += F("not "); avail = false; } - content += "available and is "; + content += F("available and is "); if(!iv->isProducing(mTimestamp)) - content += "not "; - content += "producing\n"; + content += F("not "); + content += F("producing\n"); - if(!avail) - content += "-> last successful transmission: " + getDateTimeStr(iv->getLastTs()); + if(!avail) { + if(iv->getLastTs() > 0) + content += F("-> last successful transmission: ") + getDateTimeStr(iv->getLastTs()) + "\n"; + } } } if(!mSys->Radio.isChipConnected()) - content += "WARNING! your NRF24 module can't be reached, check the wiring and pinout (setup)\n"; + content += F("WARNING! your NRF24 module can't be reached, check the wiring and pinout (setup)\n"); if(mShowRebootRequest) - content += "INFO: reboot your ESP to apply all your configuration changes!\n"; + content += F("INFO: reboot your ESP to apply all your configuration changes!\n"); if(!mSettingsValid) - content += "INFO: your settings are invalid, please switch to setup to correct this.\n"; + content += F("INFO: your settings are invalid, please switch to setup to correct this.\n"); - content += "MQTT: "; + content += F("MQTT: "); if(!mMqtt.isConnected()) - content += "not "; - content += "connected\n"; + content += F("not "); + content += F("connected\n"); - mWeb->send(200, "text/plain", content); + mWeb->send(200, F("text/plain"), content); } //----------------------------------------------------------------------------- void app::showHoymiles(void) { String html = FPSTR(hoymiles_html); - html.replace("{DEVICE}", mDeviceName); - html.replace("{VERSION}", mVersion); - html.replace("{TS}", String(mSendInterval) + " "); - html.replace("{JS_TS}", String(mSendInterval * 1000)); - mWeb->send(200, "text/html", html); + html.replace(F("{DEVICE}"), mDeviceName); + html.replace(F("{VERSION}"), mVersion); + html.replace(F("{TS}"), String(mSendInterval) + " "); + html.replace(F("{JS_TS}"), String(mSendInterval * 1000)); + mWeb->send(200, F("text/html"), html); } @@ -573,24 +575,24 @@ void app::showLiveData(void) { case INV_TYPE_4CH: modNum = 4; break; } - modHtml += "
"; - modHtml += "
" + String(iv->name) + ""; + modHtml += F("
" + "
") + String(iv->name) + F(""); uint8_t list[] = {FLD_UAC, FLD_IAC, FLD_PAC, FLD_F, FLD_PCT, FLD_T, FLD_YT, FLD_YD, FLD_PDC, FLD_EFF}; for(uint8_t fld = 0; fld < 10; fld++) { pos = (iv->getPosByChFld(CH0, list[fld])); if(0xff != pos) { - modHtml += "
"; - modHtml += "" + String(iv->getValue(pos)); - modHtml += "" + String(iv->getUnit(pos)) + ""; - modHtml += "" + String(iv->getFieldName(pos)) + ""; - modHtml += "
"; + modHtml += F("
"); + modHtml += F("") + String(iv->getValue(pos)); + modHtml += F("") + String(iv->getUnit(pos)) + F(""); + modHtml += F("") + String(iv->getFieldName(pos)) + F(""); + modHtml += F("
"); } } modHtml += "
"; for(uint8_t ch = 1; ch <= modNum; ch ++) { - modHtml += "
CHANNEL " + String(ch) + ""; + modHtml += F("
CHANNEL ") + String(ch) + F(""); for(uint8_t j = 0; j < 6; j++) { switch(j) { default: pos = (iv->getPosByChFld(ch, FLD_UDC)); break; @@ -601,31 +603,31 @@ void app::showLiveData(void) { case 5: pos = (iv->getPosByChFld(ch, FLD_IRR)); break; } if(0xff != pos) { - modHtml += "" + String(iv->getValue(pos)); - modHtml += "" + String(iv->getUnit(pos)) + ""; - modHtml += "" + String(iv->getFieldName(pos)) + ""; + modHtml += F("") + String(iv->getValue(pos)); + modHtml += F("") + String(iv->getUnit(pos)) + F(""); + modHtml += F("") + String(iv->getFieldName(pos)) + F(""); } } modHtml += "
"; } - modHtml += "
Last received data requested at: " + getDateTimeStr(iv->ts) + "
"; - modHtml += "
"; + modHtml += F("
Last received data requested at: ") + getDateTimeStr(iv->ts) + F("
"); + modHtml += F("
"); #else // dump all data to web frontend - modHtml = "
";
+            modHtml = F("
");
             char topic[30], val[10];
             for(uint8_t i = 0; i < iv->listLen; i++) {
                 snprintf(topic, 30, "%s/ch%d/%s", iv->name, iv->assign[i].ch, iv->getFieldName(i));
                 snprintf(val, 10, "%.3f %s", iv->getValue(i), iv->getUnit(i));
                 modHtml += String(topic) + ": " + String(val) + "\n";
             }
-            modHtml += "
"; + modHtml += F("
"); #endif } } - mWeb->send(200, "text/html", modHtml); + mWeb->send(200, F("text/html"), modHtml); } @@ -718,13 +720,13 @@ void app::saveValues(bool webSend = true) { showReboot(); else { mShowRebootRequest = true; - mWeb->send(200, "text/html", "Setup saved" - "

saved

"); + mWeb->send(200, F("text/html"), F("Setup saved" + "

saved

")); } } else { - mWeb->send(200, "text/html", "Error" - "

Error while saving

"); + mWeb->send(200, F("text/html"), F("Error" + "

Error while saving

")); } } diff --git a/tools/esp8266/defines.h b/tools/esp8266/defines.h index ceae67fa..5608e51e 100644 --- a/tools/esp8266/defines.h +++ b/tools/esp8266/defines.h @@ -16,7 +16,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 4 -#define VERSION_PATCH 9 +#define VERSION_PATCH 10 //------------------------------------- diff --git a/tools/esp8266/hmRadio.h b/tools/esp8266/hmRadio.h index 492b93d7..3864d508 100644 --- a/tools/esp8266/hmRadio.h +++ b/tools/esp8266/hmRadio.h @@ -88,17 +88,17 @@ class HmRadio { // enable only receiving interrupts mNrf24.maskIRQ(true, true, false); - DPRINTLN("RF24 Amp Pwr: RF24_PA_" + String(rf24AmpPower[AmplifierPower])); + DPRINTLN(F("RF24 Amp Pwr: RF24_PA_") + String(rf24AmpPower[AmplifierPower])); mNrf24.setPALevel(AmplifierPower & 0x03); mNrf24.startListening(); - DPRINTLN("Radio Config:"); + DPRINTLN(F("Radio Config:")); mNrf24.printPrettyDetails(); mTxCh = getDefaultChannel(); if(!mNrf24.isChipConnected()) { - DPRINTLN("WARNING! your NRF24 module can't be reached, check the wiring"); + DPRINTLN(F("WARNING! your NRF24 module can't be reached, check the wiring")); } } @@ -179,18 +179,6 @@ class HmRadio { uint8_t crc = crc8(buf, *len-1); bool valid = (crc == buf[*len-1]); - //if(valid) { - //mRxStat[(buf[9] & 0x7F)-1]++; - //mRxChStat[(buf[9] & 0x7F)-1][rxCh & 0x7]++; - //} - /*else { - DPRINT("CRC wrong: "); - DHEX(crc); - DPRINT(" != "); - DHEX(buf[*len-1]); - DPRINTLN(""); - }*/ - return valid; } @@ -243,22 +231,6 @@ class HmRadio { mNrf24.stopListening(); if(clear) { - /*uint8_t cnt = 4; - for(uint8_t i = 0; i < 4; i ++) { - DPRINT(String(mRxStat[i]) + " ("); - for(uint8_t j = 0; j < 4; j++) { - DPRINT(String(mRxChStat[i][j])); - } - DPRINT(") "); - if(0 != mRxStat[i]) - cnt--; - } - if(cnt == 0) - DPRINTLN(" -> all"); - else - DPRINTLN(" -> missing: " + String(cnt)); - memset(mRxStat, 0, 4); - memset(mRxChStat, 0, 4*8);*/ mRxLoopCnt = RX_LOOP_CNT; } @@ -301,8 +273,6 @@ class HmRadio { uint8_t mRxChLst[4]; uint8_t mRxChIdx; - //uint8_t mRxStat[4]; - //uint8_t mRxChStat[4][8]; uint16_t mRxLoopCnt; RF24 mNrf24; diff --git a/tools/esp8266/hmSystem.h b/tools/esp8266/hmSystem.h index 39d7602e..9565b16c 100644 --- a/tools/esp8266/hmSystem.h +++ b/tools/esp8266/hmSystem.h @@ -29,7 +29,7 @@ class HmSystem { INVERTERTYPE *addInverter(const char *name, uint64_t serial, uint16_t chMaxPwr[]) { if(MAX_INVERTER <= mNumInv) { - DPRINT("max number of inverters reached!"); + DPRINT(F("max number of inverters reached!")); return NULL; } INVERTERTYPE *p = &mInverter[mNumInv]; @@ -43,18 +43,18 @@ class HmSystem { case 0x21: p->type = INV_TYPE_1CH; break; case 0x41: p->type = INV_TYPE_2CH; break; case 0x61: p->type = INV_TYPE_4CH; break; - default: DPRINTLN("unknown inverter type: 11" + String(p->serial.b[4], HEX)); break; + default: DPRINTLN(F("unknown inverter type: 11") + String(p->serial.b[4], HEX)); break; } } else - DPRINTLN("inverter type can't be detected!"); + DPRINTLN(F("inverter type can't be detected!")); p->init(); uint8_t len = (uint8_t)strlen(name); strncpy(p->name, name, (len > MAX_NAME_LENGTH) ? MAX_NAME_LENGTH : len); if(NULL == p->assign) { - DPRINT("no assignment for type found!"); + DPRINT(F("no assignment for type found!")); return NULL; } else { diff --git a/tools/esp8266/main.cpp b/tools/esp8266/main.cpp index 38cb5d3d..e332209c 100644 --- a/tools/esp8266/main.cpp +++ b/tools/esp8266/main.cpp @@ -73,7 +73,7 @@ void Main::loop(void) { mApActive = setupStation(mLimit); if(mApActive) { if(strlen(WIFI_AP_PWD) < 8) - DPRINTLN("ERROR: password must be at least 8 characters long"); + DPRINTLN(F("ERROR: password must be at least 8 characters long")); setupAp(WIFI_AP_SSID, WIFI_AP_PWD); } } @@ -81,11 +81,11 @@ void Main::loop(void) { if(millis() - mApLastTick > 10000) { uint8_t cnt = WiFi.softAPgetStationNum(); if(cnt > 0) { - DPRINTLN(String(cnt) + " clients connected, resetting AP timeout"); + DPRINTLN(String(cnt) + F(" clients connected, resetting AP timeout")); mNextTryTs = (millis() + (WIFI_AP_ACTIVE_TIME * 1000)); } mApLastTick = millis(); - DPRINTLN("AP will be closed in " + String((mNextTryTs - mApLastTick) / 1000) + " seconds"); + DPRINTLN(F("AP will be closed in ") + String((mNextTryTs - mApLastTick) / 1000) + F(" seconds")); } } #endif @@ -99,7 +99,7 @@ void Main::loop(void) { else { if(!mApActive) { mTimestamp = getNtpTime(); - DPRINTLN("[NTP]: " + getDateTimeStr(getNtpTime())); + DPRINTLN("[NTP]: " + getDateTimeStr(mTimestamp)); } } } @@ -131,6 +131,15 @@ bool Main::getConfig(void) { snprintf(mDeviceName, DEVNAME_LEN, "%s", DEF_DEVICE_NAME); } + if(!mSettingsValid) { + DPRINTLN(F("Settings not valid, erasing ...")); + eraseSettings(); + delay(100); + DPRINTLN(F("... restarting ...")); + delay(100); + ESP.restart(); + } + return mApActive; } @@ -139,11 +148,11 @@ bool Main::getConfig(void) { void Main::setupAp(const char *ssid, const char *pwd) { IPAddress apIp(192, 168, 1, 1); - DPRINTLN("\n---------\nAP MODE\nSSDI: " - + String(ssid) + "\nPWD: " - + String(pwd) + "\nActive for: " - + String(WIFI_AP_ACTIVE_TIME) + " seconds" - + "\n---------\n"); + DPRINTLN(F("\n---------\nAP MODE\nSSDI: ") + + String(ssid) + F("\nPWD: ") + + String(pwd) + F("\nActive for: ") + + String(WIFI_AP_ACTIVE_TIME) + F(" seconds") + + F("\n---------\n")); DPRINTLN("DBG: " + String(mNextTryTs)); WiFi.mode(WIFI_AP); @@ -179,7 +188,7 @@ bool Main::setupStation(uint32_t timeout) { WiFi.hostname(mDeviceName); delay(2000); - DPRINTLN("connect to network '" + String(mStationSsid) + "' ..."); + DPRINTLN(F("connect to network '") + String(mStationSsid) + F("' ...")); while (WiFi.status() != WL_CONNECTED) { delay(100); if(cnt % 100 == 0) @@ -213,17 +222,17 @@ bool Main::setupStation(uint32_t timeout) { //----------------------------------------------------------------------------- void Main::showSetup(void) { String html = FPSTR(setup_html); - html.replace("{SSID}", mStationSsid); + html.replace(F("{SSID}"), mStationSsid); // PWD will be left at the default value (for protection) // -> the PWD will only be changed if it does not match the default "{PWD}" - html.replace("{DEVICE}", String(mDeviceName)); - html.replace("{VERSION}", String(mVersion)); + html.replace(F("{DEVICE}"), String(mDeviceName)); + html.replace(F("{VERSION}"), String(mVersion)); if(mApActive) - html.replace("{IP}", String("http://192.168.1.1")); + html.replace("{IP}", String(F("http://192.168.1.1"))); else - html.replace("{IP}", ("http://" + String(WiFi.localIP().toString()))); + html.replace("{IP}", (F("http://") + String(WiFi.localIP().toString()))); - mWeb->send(200, "text/html", html); + mWeb->send(200, F("text/html"), html); } @@ -264,8 +273,8 @@ void Main::saveValues(bool webSend = true) { if(mWeb->arg("reboot") == "on") showReboot(); else // TODO: add device name as redirect in AP-mode - mWeb->send(200, "text/html", "Setup saved" - "

saved

"); + mWeb->send(200, F("text/html"), F("Setup saved" + "

saved

")); } } } @@ -303,12 +312,11 @@ void Main::showTime(void) { //----------------------------------------------------------------------------- void Main::showNotFound(void) { - String msg = "File Not Found\n\n"; - msg += "URI: "; + String msg = F("File Not Found\n\nURI: "); msg += mWeb->uri(); - msg += "\nMethod: "; + msg += F("\nMethod: "); msg += ( mWeb->method() == HTTP_GET ) ? "GET" : "POST"; - msg += "\nArguments: "; + msg += F("\nArguments: "); msg += mWeb->args(); msg += "\n"; @@ -316,13 +324,13 @@ void Main::showNotFound(void) { msg += " " + mWeb->argName(i) + ": " + mWeb->arg(i) + "\n"; } - mWeb->send(404, "text/plain", msg); + mWeb->send(404, F("text/plain"), msg); } //----------------------------------------------------------------------------- void Main::showReboot(void) { - mWeb->send(200, "text/html", "Rebooting ...rebooting ... auto reload after 10s"); + mWeb->send(200, F("text/html"), F("Rebooting ...rebooting ... auto reload after 10s")); delay(1000); ESP.restart(); } @@ -336,20 +344,20 @@ void Main::showFactoryRst(void) { if(mWeb->args() > 0) { if(mWeb->arg("reset").toInt() == 1) { eraseSettings(true); - content = "factory reset: success\n\nrebooting ... "; + content = F("factory reset: success\n\nrebooting ... "); refresh = 10; } else { - content = "factory reset: aborted"; + content = F("factory reset: aborted"); refresh = 3; } } else { - content = "

Factory Reset

"; - content += "

RESET

CANCEL

"; + content = F("

Factory Reset

" + "

RESET

CANCEL

"); refresh = 120; } - mWeb->send(200, "text/html", "Factory Reset" + content + ""); + mWeb->send(200, F("text/html"), F("Factory Reset") + content + F("")); if(refresh == 10) { delay(1000); ESP.restart(); diff --git a/tools/esp8266/main.h b/tools/esp8266/main.h index 835a94dd..9656c017 100644 --- a/tools/esp8266/main.h +++ b/tools/esp8266/main.h @@ -61,7 +61,7 @@ class Main { end = addr + 64; if(end > (ADDR_SETTINGS_CRC + 2)) end = (ADDR_SETTINGS_CRC + 2); - DPRINTLN("erase: 0x" + String(addr, HEX) + " - 0x" + String(end, HEX)); + DPRINTLN(F("erase: 0x") + String(addr, HEX) + " - 0x" + String(end, HEX)); mEep->write(addr, buf, (end-addr)); addr = end; } while(addr < (ADDR_SETTINGS_CRC + 2));