Browse Source

* reduced heap size (>50%) by using 'F()' for (nearly) all static strings (mentioned by @stefan123t)

pull/59/head
lumapu 3 years ago
parent
commit
69f8f0b806
  1. 224
      tools/esp8266/app.cpp
  2. 2
      tools/esp8266/defines.h
  3. 36
      tools/esp8266/hmRadio.h
  4. 8
      tools/esp8266/hmSystem.h
  5. 66
      tools/esp8266/main.cpp
  6. 2
      tools/esp8266/main.h

224
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 += "<p class=\"subdes\">Inverter "+ String(i) + "</p>";
inv += F("<p class=\"subdes\">Inverter ") + String(i) + "</p>";
inv += "<label for=\"inv" + String(i) + "Addr\">Address</label>";
inv += "<input type=\"text\" class=\"text\" name=\"inv" + String(i) + "Addr\" value=\"";
inv += F("<label for=\"inv") + String(i) + F("Addr\">Address</label>");
inv += F("<input type=\"text\" class=\"text\" name=\"inv") + String(i) + F("Addr\" value=\"");
if(0ULL != invSerial)
inv += String(invSerial, HEX);
inv += "\"/ maxlength=\"12\">";
inv += F("\"/ maxlength=\"12\">");
inv += "<label for=\"inv" + String(i) + "Name\">Name</label>";
inv += "<input type=\"text\" class=\"text\" name=\"inv" + String(i) + "Name\" value=\"";
inv += F("<label for=\"inv") + String(i) + F("Name\">Name</label>");
inv += F("<input type=\"text\" class=\"text\" name=\"inv") + String(i) + F("Name\" value=\"");
inv += String(invName);
inv += "\"/ maxlength=\"" + String(MAX_NAME_LENGTH) + "\">";
inv += F("\"/ maxlength=\"") + String(MAX_NAME_LENGTH) + "\">";
inv += "<label for=\"inv" + String(i) + "ModPwr0\">Max Module Power (Wp)</label>";
inv += F("<label for=\"inv") + String(i) + F("ModPwr0\">Max Module Power (Wp)</label>");
for(uint8_t j = 0; j < 4; j++) {
inv += "<input type=\"text\" class=\"text sh\" name=\"inv" + String(i) + "ModPwr" + String(j) + "\" value=\"";
inv += F("<input type=\"text\" class=\"text sh\" name=\"inv") + String(i) + F("ModPwr") + String(j) + F("\" value=\"");
inv += String(modPwr[j]);
inv += "\"/ maxlength=\"4\">";
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 += "<label for=\"" + String(pinArgNames[i]) + "\">" + String(pinNames[i]) + "</label>";
pinout += "<select name=\"" + String(pinArgNames[i]) + "\">";
pinout += F("<label for=\"") + String(pinArgNames[i]) + "\">" + String(pinNames[i]) + F("</label>");
pinout += F("<select name=\"") + String(pinArgNames[i]) + "\">";
for(uint8_t j = 0; j <= 16; j++) {
pinout += "<option value=\"" + String(j) + "\"";
pinout += F("<option value=\"") + String(j) + "\"";
switch(i) {
default: if(j == mSys->Radio.pinCs) pinout += " selected"; break;
case 1: if(j == mSys->Radio.pinCe) pinout += " selected"; break;
case 2: if(j == mSys->Radio.pinIrq) pinout += " selected"; break;
default: if(j == mSys->Radio.pinCs) pinout += F(" selected"); break;
case 1: if(j == mSys->Radio.pinCe) pinout += F(" selected"); break;
case 2: if(j == mSys->Radio.pinIrq) pinout += F(" selected"); break;
}
pinout += ">" + String(wemosPins[j]) + "</option>";
pinout += ">" + String(wemosPins[j]) + F("</option>");
}
pinout += "</select>";
pinout += F("</select>");
}
html.replace("{PINOUT}", String(pinout));
html.replace(F("{PINOUT}"), String(pinout));
// nrf24l01+
String rf24;
for(uint8_t i = 0; i <= 3; i++) {
rf24 += "<option value=\"" + String(i) + "\"";
rf24 += F("<option value=\"") + String(i) + "\"";
if(i == mSys->Radio.AmplifierPower)
rf24 += " selected";
rf24 += ">" + String(rf24AmpPower[i]) + "</option>";
rf24 += F(" selected");
rf24 += ">" + String(rf24AmpPower[i]) + F("</option>");
}
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 (<a href=\"/setup\">setup</a>)\n";
content += F("WARNING! your NRF24 module can't be reached, check the wiring and pinout (<a href=\"/setup\">setup</a>)\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 <a href=\"/setup\">setup</a> to correct this.\n";
content += F("INFO: your settings are invalid, please switch to <a href=\"/setup\">setup</a> 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 += "<div class=\"iv\">";
modHtml += "<div class=\"ch-iv\"><span class=\"head\">" + String(iv->name) + "</span>";
modHtml += F("<div class=\"iv\">"
"<div class=\"ch-iv\"><span class=\"head\">") + String(iv->name) + F("</span>");
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 += "<div class=\"subgrp\">";
modHtml += "<span class=\"value\">" + String(iv->getValue(pos));
modHtml += "<span class=\"unit\">" + String(iv->getUnit(pos)) + "</span></span>";
modHtml += "<span class=\"info\">" + String(iv->getFieldName(pos)) + "</span>";
modHtml += "</div>";
modHtml += F("<div class=\"subgrp\">");
modHtml += F("<span class=\"value\">") + String(iv->getValue(pos));
modHtml += F("<span class=\"unit\">") + String(iv->getUnit(pos)) + F("</span></span>");
modHtml += F("<span class=\"info\">") + String(iv->getFieldName(pos)) + F("</span>");
modHtml += F("</div>");
}
}
modHtml += "</div>";
for(uint8_t ch = 1; ch <= modNum; ch ++) {
modHtml += "<div class=\"ch\"><span class=\"head\">CHANNEL " + String(ch) + "</span>";
modHtml += F("<div class=\"ch\"><span class=\"head\">CHANNEL ") + String(ch) + F("</span>");
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 += "<span class=\"value\">" + String(iv->getValue(pos));
modHtml += "<span class=\"unit\">" + String(iv->getUnit(pos)) + "</span></span>";
modHtml += "<span class=\"info\">" + String(iv->getFieldName(pos)) + "</span>";
modHtml += F("<span class=\"value\">") + String(iv->getValue(pos));
modHtml += F("<span class=\"unit\">") + String(iv->getUnit(pos)) + F("</span></span>");
modHtml += F("<span class=\"info\">") + String(iv->getFieldName(pos)) + F("</span>");
}
}
modHtml += "</div>";
}
modHtml += "<div class=\"ts\">Last received data requested at: " + getDateTimeStr(iv->ts) + "</div>";
modHtml += "</div>";
modHtml += F("<div class=\"ts\">Last received data requested at: ") + getDateTimeStr(iv->ts) + F("</div>");
modHtml += F("</div>");
#else
// dump all data to web frontend
modHtml = "<pre>";
modHtml = F("<pre>");
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 += "</pre>";
modHtml += F("</pre>");
#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", "<!doctype html><html><head><title>Setup saved</title><meta http-equiv=\"refresh\" content=\"1; URL=/setup\"></head><body>"
"<p>saved</p></body></html>");
mWeb->send(200, F("text/html"), F("<!doctype html><html><head><title>Setup saved</title><meta http-equiv=\"refresh\" content=\"1; URL=/setup\"></head><body>"
"<p>saved</p></body></html>"));
}
}
else {
mWeb->send(200, "text/html", "<!doctype html><html><head><title>Error</title><meta http-equiv=\"refresh\" content=\"3; URL=/setup\"></head><body>"
"<p>Error while saving</p></body></html>");
mWeb->send(200, F("text/html"), F("<!doctype html><html><head><title>Error</title><meta http-equiv=\"refresh\" content=\"3; URL=/setup\"></head><body>"
"<p>Error while saving</p></body></html>"));
}
}

2
tools/esp8266/defines.h

@ -16,7 +16,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 4
#define VERSION_PATCH 9
#define VERSION_PATCH 10
//-------------------------------------

36
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;

8
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 {

66
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", "<!doctype html><html><head><title>Setup saved</title><meta http-equiv=\"refresh\" content=\"0; URL=/setup\"></head><body>"
"<p>saved</p></body></html>");
mWeb->send(200, F("text/html"), F("<!doctype html><html><head><title>Setup saved</title><meta http-equiv=\"refresh\" content=\"0; URL=/setup\"></head><body>"
"<p>saved</p></body></html>"));
}
}
}
@ -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", "<!doctype html><html><head><title>Rebooting ...</title><meta http-equiv=\"refresh\" content=\"10; URL=/\"></head><body>rebooting ... auto reload after 10s</body></html>");
mWeb->send(200, F("text/html"), F("<!doctype html><html><head><title>Rebooting ...</title><meta http-equiv=\"refresh\" content=\"10; URL=/\"></head><body>rebooting ... auto reload after 10s</body></html>"));
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 = "<h1>Factory Reset</h1>";
content += "<p><a href=\"/factory?reset=1\">RESET</a><br/><br/><a href=\"/factory?reset=0\">CANCEL</a><br/></p>";
content = F("<h1>Factory Reset</h1>"
"<p><a href=\"/factory?reset=1\">RESET</a><br/><br/><a href=\"/factory?reset=0\">CANCEL</a><br/></p>");
refresh = 120;
}
mWeb->send(200, "text/html", "<!doctype html><html><head><title>Factory Reset</title><meta http-equiv=\"refresh\" content=\"" + String(refresh) + "; URL=/\"></head><body>" + content + "</body></html>");
mWeb->send(200, F("text/html"), F("<!doctype html><html><head><title>Factory Reset</title><meta http-equiv=\"refresh\" content=\"") + String(refresh) + F("; URL=/\"></head><body>") + content + F("</body></html>"));
if(refresh == 10) {
delay(1000);
ESP.restart();

2
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));

Loading…
Cancel
Save