From e18be5f97c5841467b82708ebd483446d0832227 Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Wed, 19 Oct 2022 20:58:57 +0200 Subject: [PATCH] Better memory optimization --- src/AmsToMqttBridge.ino | 148 +++++++++++------------ src/web/AmsWebServer.cpp | 254 +++++++++++++++++++-------------------- 2 files changed, 201 insertions(+), 201 deletions(-) diff --git a/src/AmsToMqttBridge.ino b/src/AmsToMqttBridge.ino index 2074dbc6..3dda8f0b 100644 --- a/src/AmsToMqttBridge.ino +++ b/src/AmsToMqttBridge.ino @@ -307,7 +307,7 @@ void setup() { } debugI(" flashing"); - File firmwareFile = LittleFS.open(FILE_FIRMWARE, (char*) F("r")); + File firmwareFile = LittleFS.open(FILE_FIRMWARE, (char*) "r"); debugD(" firmware size: %d", firmwareFile.size()); uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; debugD(" available: %d", maxSketchSpace); @@ -1324,7 +1324,7 @@ void MQTT_connect() { if(LittleFS.exists(FILE_MQTT_CA)) { debugI("Found MQTT CA file (%dkb free heap)", ESP.getFreeHeap()); - file = LittleFS.open(FILE_MQTT_CA, (char*) F("r")); + file = LittleFS.open(FILE_MQTT_CA, (char*) "r"); #if defined(ESP8266) BearSSL::X509List *serverTrustedCA = new BearSSL::X509List(file); mqttSecureClient->setTrustAnchors(serverTrustedCA); @@ -1337,12 +1337,12 @@ void MQTT_connect() { if(LittleFS.exists(FILE_MQTT_CERT) && LittleFS.exists(FILE_MQTT_KEY)) { #if defined(ESP8266) debugI("Found MQTT certificate file (%dkb free heap)", ESP.getFreeHeap()); - file = LittleFS.open(FILE_MQTT_CERT, (char*) F("r")); + file = LittleFS.open(FILE_MQTT_CERT, (char*) "r"); BearSSL::X509List *serverCertList = new BearSSL::X509List(file); file.close(); debugI("Found MQTT key file (%dkb free heap)", ESP.getFreeHeap()); - file = LittleFS.open(FILE_MQTT_KEY, (char*) F("r")); + file = LittleFS.open(FILE_MQTT_KEY, (char*) "r"); BearSSL::PrivateKey *serverPrivKey = new BearSSL::PrivateKey(file); file.close(); @@ -1350,12 +1350,12 @@ void MQTT_connect() { mqttSecureClient->setClientRSACert(serverCertList, serverPrivKey); #elif defined(ESP32) debugI("Found MQTT certificate file (%dkb free heap)", ESP.getFreeHeap()); - file = LittleFS.open(FILE_MQTT_CERT, (char*) F("r")); + file = LittleFS.open(FILE_MQTT_CERT, (char*) "r"); mqttSecureClient->loadCertificate(file, file.size()); file.close(); debugI("Found MQTT key file (%dkb free heap)", ESP.getFreeHeap()); - file = LittleFS.open(FILE_MQTT_KEY, (char*) F("r")); + file = LittleFS.open(FILE_MQTT_KEY, (char*) "r"); mqttSecureClient->loadPrivateKey(file, file.size()); file.close(); #endif @@ -1421,7 +1421,7 @@ void configFileParse() { return; } - File file = LittleFS.open(FILE_CFG, "r"); + File file = LittleFS.open(FILE_CFG, (char*) "r"); bool lSys = false; bool lWiFi = false; @@ -1451,187 +1451,187 @@ void configFileParse() { char* buf = (char*) commonBuffer; memset(buf, 0, 1024); while((size = file.readBytesUntil('\n', buf, 1024)) > 0) { - if(strncmp(buf, "boardType ", 10) == 0) { + if(strncmp_P(buf, PSTR("boardType "), 10) == 0) { if(!lSys) { config.getSystemConfig(sys); lSys = true; }; sys.boardType = String(buf+10).toInt(); - } else if(strncmp(buf, "ssid ", 5) == 0) { + } else if(strncmp_P(buf, PSTR("ssid "), 5) == 0) { if(!lWiFi) { config.getWiFiConfig(wifi); lWiFi = true; }; memcpy(wifi.ssid, buf+5, size-5); - } else if(strncmp(buf, "psk ", 4) == 0) { + } else if(strncmp_P(buf, PSTR("psk "), 4) == 0) { if(!lWiFi) { config.getWiFiConfig(wifi); lWiFi = true; }; memcpy(wifi.psk, buf+4, size-4); - } else if(strncmp(buf, "ip ", 3) == 0) { + } else if(strncmp_P(buf, PSTR("ip "), 3) == 0) { if(!lWiFi) { config.getWiFiConfig(wifi); lWiFi = true; }; memcpy(wifi.ip, buf+3, size-3); - } else if(strncmp(buf, "gateway ", 8) == 0) { + } else if(strncmp_P(buf, PSTR("gateway "), 8) == 0) { if(!lWiFi) { config.getWiFiConfig(wifi); lWiFi = true; }; memcpy(wifi.gateway, buf+8, size-8); - } else if(strncmp(buf, "subnet ", 7) == 0) { + } else if(strncmp_P(buf, PSTR("subnet "), 7) == 0) { if(!lWiFi) { config.getWiFiConfig(wifi); lWiFi = true; }; memcpy(wifi.subnet, buf+7, size-7); - } else if(strncmp(buf, "dns1 ", 5) == 0) { + } else if(strncmp_P(buf, PSTR("dns1 "), 5) == 0) { if(!lWiFi) { config.getWiFiConfig(wifi); lWiFi = true; }; memcpy(wifi.dns1, buf+5, size-5); - } else if(strncmp(buf, "dns2 ", 5) == 0) { + } else if(strncmp_P(buf, PSTR("dns2 "), 5) == 0) { if(!lWiFi) { config.getWiFiConfig(wifi); lWiFi = true; }; memcpy(wifi.dns2, buf+5, size-5); - } else if(strncmp(buf, "hostname ", 9) == 0) { + } else if(strncmp_P(buf, PSTR("hostname "), 9) == 0) { if(!lWiFi) { config.getWiFiConfig(wifi); lWiFi = true; }; memcpy(wifi.hostname, buf+9, size-9); - } else if(strncmp(buf, "mdns ", 5) == 0) { + } else if(strncmp_P(buf, PSTR("mdns "), 5) == 0) { if(!lWiFi) { config.getWiFiConfig(wifi); lWiFi = true; }; wifi.mdns = String(buf+5).toInt() == 1;; - } else if(strncmp(buf, "mqttHost ", 9) == 0) { + } else if(strncmp_P(buf, PSTR("mqttHost "), 9) == 0) { if(!lMqtt) { config.getMqttConfig(mqtt); lMqtt = true; }; memcpy(mqtt.host, buf+9, size-9); - } else if(strncmp(buf, "mqttPort ", 9) == 0) { + } else if(strncmp_P(buf, PSTR("mqttPort "), 9) == 0) { if(!lMqtt) { config.getMqttConfig(mqtt); lMqtt = true; }; mqtt.port = String(buf+9).toInt(); - } else if(strncmp(buf, "mqttClientId ", 13) == 0) { + } else if(strncmp_P(buf, PSTR("mqttClientId "), 13) == 0) { if(!lMqtt) { config.getMqttConfig(mqtt); lMqtt = true; }; memcpy(mqtt.clientId, buf+13, size-13); - } else if(strncmp(buf, "mqttPublishTopic ", 17) == 0) { + } else if(strncmp_P(buf, PSTR("mqttPublishTopic "), 17) == 0) { if(!lMqtt) { config.getMqttConfig(mqtt); lMqtt = true; }; memcpy(mqtt.publishTopic, buf+17, size-17); - } else if(strncmp(buf, "mqttUsername ", 13) == 0) { + } else if(strncmp_P(buf, PSTR("mqttUsername "), 13) == 0) { if(!lMqtt) { config.getMqttConfig(mqtt); lMqtt = true; }; memcpy(mqtt.username, buf+13, size-13); - } else if(strncmp(buf, "mqttPassword ", 13) == 0) { + } else if(strncmp_P(buf, PSTR("mqttPassword "), 13) == 0) { if(!lMqtt) { config.getMqttConfig(mqtt); lMqtt = true; }; memcpy(mqtt.password, buf+13, size-13); - } else if(strncmp(buf, "mqttPayloadFormat ", 18) == 0) { + } else if(strncmp_P(buf, PSTR("mqttPayloadFormat "), 18) == 0) { if(!lMqtt) { config.getMqttConfig(mqtt); lMqtt = true; }; mqtt.payloadFormat = String(buf+18).toInt(); - } else if(strncmp(buf, "mqttSsl ", 8) == 0) { + } else if(strncmp_P(buf, PSTR("mqttSsl "), 8) == 0) { if(!lMqtt) { config.getMqttConfig(mqtt); lMqtt = true; }; mqtt.ssl = String(buf+8).toInt() == 1;; - } else if(strncmp(buf, "webSecurity ", 12) == 0) { + } else if(strncmp_P(buf, PSTR("webSecurity "), 12) == 0) { if(!lWeb) { config.getWebConfig(web); lWeb = true; }; web.security = String(buf+12).toInt(); - } else if(strncmp(buf, "webUsername ", 12) == 0) { + } else if(strncmp_P(buf, PSTR("webUsername "), 12) == 0) { if(!lWeb) { config.getWebConfig(web); lWeb = true; }; memcpy(web.username, buf+12, size-12); - } else if(strncmp(buf, "webPassword ", 12) == 0) { + } else if(strncmp_P(buf, PSTR("webPassword "), 12) == 0) { if(!lWeb) { config.getWebConfig(web); lWeb = true; }; memcpy(web.username, buf+12, size-12); - } else if(strncmp(buf, "meterBaud ", 10) == 0) { + } else if(strncmp_P(buf, PSTR("meterBaud "), 10) == 0) { if(!lMeter) { config.getMeterConfig(meter); lMeter = true; }; meter.baud = String(buf+10).toInt(); - } else if(strncmp(buf, "meterParity ", 12) == 0) { + } else if(strncmp_P(buf, PSTR("meterParity "), 12) == 0) { if(!lMeter) { config.getMeterConfig(meter); lMeter = true; }; - if(strncmp(buf+12, "7N1", 3) == 0) meter.parity = 2; - if(strncmp(buf+12, "8N1", 3) == 0) meter.parity = 3; - if(strncmp(buf+12, "7E1", 3) == 0) meter.parity = 10; - if(strncmp(buf+12, "8E1", 3) == 0) meter.parity = 11; - } else if(strncmp(buf, "meterInvert ", 12) == 0) { + if(strncmp_P(buf+12, PSTR("7N1"), 3) == 0) meter.parity = 2; + if(strncmp_P(buf+12, PSTR("8N1"), 3) == 0) meter.parity = 3; + if(strncmp_P(buf+12, PSTR("7E1"), 3) == 0) meter.parity = 10; + if(strncmp_P(buf+12, PSTR("8E1"), 3) == 0) meter.parity = 11; + } else if(strncmp_P(buf, PSTR("meterInvert "), 12) == 0) { if(!lMeter) { config.getMeterConfig(meter); lMeter = true; }; meter.invert = String(buf+12).toInt() == 1;; - } else if(strncmp(buf, "meterDistributionSystem ", 24) == 0) { + } else if(strncmp_P(buf, PSTR("meterDistributionSystem "), 24) == 0) { if(!lMeter) { config.getMeterConfig(meter); lMeter = true; }; meter.distributionSystem = String(buf+24).toInt(); - } else if(strncmp(buf, "meterMainFuse ", 14) == 0) { + } else if(strncmp_P(buf, PSTR("meterMainFuse "), 14) == 0) { if(!lMeter) { config.getMeterConfig(meter); lMeter = true; }; meter.mainFuse = String(buf+14).toInt(); - } else if(strncmp(buf, "meterProductionCapacity ", 24) == 0) { + } else if(strncmp_P(buf, PSTR("meterProductionCapacity "), 24) == 0) { if(!lMeter) { config.getMeterConfig(meter); lMeter = true; }; meter.productionCapacity = String(buf+24).toInt(); - } else if(strncmp(buf, "meterEncryptionKey ", 19) == 0) { + } else if(strncmp_P(buf, PSTR("meterEncryptionKey "), 19) == 0) { if(!lMeter) { config.getMeterConfig(meter); lMeter = true; }; fromHex(meter.encryptionKey, String(buf+19), 16); - } else if(strncmp(buf, "meterAuthenticationKey ", 23) == 0) { + } else if(strncmp_P(buf, PSTR("meterAuthenticationKey "), 23) == 0) { if(!lMeter) { config.getMeterConfig(meter); lMeter = true; }; fromHex(meter.authenticationKey, String(buf+19), 16); - } else if(strncmp(buf, "gpioHanPin ", 11) == 0) { + } else if(strncmp_P(buf, PSTR("gpioHanPin "), 11) == 0) { if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; }; gpio.hanPin = String(buf+11).toInt(); - } else if(strncmp(buf, "gpioApPin ", 10) == 0) { + } else if(strncmp_P(buf, PSTR("gpioApPin "), 10) == 0) { if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; }; gpio.apPin = String(buf+10).toInt(); - } else if(strncmp(buf, "gpioLedPin ", 11) == 0) { + } else if(strncmp_P(buf, PSTR("gpioLedPin "), 11) == 0) { if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; }; gpio.ledPin = String(buf+11).toInt(); - } else if(strncmp(buf, "gpioLedInverted ", 16) == 0) { + } else if(strncmp_P(buf, PSTR("gpioLedInverted "), 16) == 0) { if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; }; gpio.ledInverted = String(buf+16).toInt() == 1; - } else if(strncmp(buf, "gpioLedPinRed ", 14) == 0) { + } else if(strncmp_P(buf, PSTR("gpioLedPinRed "), 14) == 0) { if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; }; gpio.ledPinRed = String(buf+14).toInt(); - } else if(strncmp(buf, "gpioLedPinGreen ", 16) == 0) { + } else if(strncmp_P(buf, PSTR("gpioLedPinGreen "), 16) == 0) { if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; }; gpio.ledPinGreen = String(buf+16).toInt(); - } else if(strncmp(buf, "gpioLedPinBlue ", 15) == 0) { + } else if(strncmp_P(buf, PSTR("gpioLedPinBlue "), 15) == 0) { if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; }; gpio.ledPinBlue = String(buf+15).toInt(); - } else if(strncmp(buf, "gpioLedRgbInverted ", 19) == 0) { + } else if(strncmp_P(buf, PSTR("gpioLedRgbInverted "), 19) == 0) { if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; }; gpio.ledRgbInverted = String(buf+19).toInt() == 1; - } else if(strncmp(buf, "gpioTempSensorPin ", 18) == 0) { + } else if(strncmp_P(buf, PSTR("gpioTempSensorPin "), 18) == 0) { if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; }; gpio.tempSensorPin = String(buf+18).toInt(); - } else if(strncmp(buf, "gpioTempAnalogSensorPin ", 24) == 0) { + } else if(strncmp_P(buf, PSTR("gpioTempAnalogSensorPin "), 24) == 0) { if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; }; gpio.tempAnalogSensorPin = String(buf+24).toInt(); - } else if(strncmp(buf, "gpioVccPin ", 11) == 0) { + } else if(strncmp_P(buf, PSTR("gpioVccPin "), 11) == 0) { if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; }; gpio.vccPin = String(buf+11).toInt(); - } else if(strncmp(buf, "gpioVccOffset ", 14) == 0) { + } else if(strncmp_P(buf, PSTR("gpioVccOffset "), 14) == 0) { if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; }; gpio.vccOffset = String(buf+14).toDouble() * 100; - } else if(strncmp(buf, "gpioVccMultiplier ", 18) == 0) { + } else if(strncmp_P(buf, PSTR("gpioVccMultiplier "), 18) == 0) { if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; }; gpio.vccMultiplier = String(buf+18).toDouble() * 1000; - } else if(strncmp(buf, "gpioVccBootLimit ", 17) == 0) { + } else if(strncmp_P(buf, PSTR("gpioVccBootLimit "), 17) == 0) { if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; }; gpio.vccBootLimit = String(buf+17).toDouble() * 10; - } else if(strncmp(buf, "gpioVccResistorGnd ", 19) == 0) { + } else if(strncmp_P(buf, PSTR("gpioVccResistorGnd "), 19) == 0) { if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; }; gpio.vccResistorGnd = String(buf+19).toInt(); - } else if(strncmp(buf, "gpioVccResistorVcc ", 19) == 0) { + } else if(strncmp_P(buf, PSTR("gpioVccResistorVcc "), 19) == 0) { if(!lGpio) { config.getGpioConfig(gpio); lGpio = true; }; gpio.vccResistorVcc = String(buf+19).toInt(); - } else if(strncmp(buf, "domoticzElidx ", 14) == 0) { + } else if(strncmp_P(buf, PSTR("domoticzElidx "), 14) == 0) { if(!lDomo) { config.getDomoticzConfig(domo); lDomo = true; }; domo.elidx = String(buf+14).toInt(); - } else if(strncmp(buf, "domoticzVl1idx ", 15) == 0) { + } else if(strncmp_P(buf, PSTR("domoticzVl1idx "), 15) == 0) { if(!lDomo) { config.getDomoticzConfig(domo); lDomo = true; }; domo.vl1idx = String(buf+15).toInt(); - } else if(strncmp(buf, "domoticzVl2idx ", 15) == 0) { + } else if(strncmp_P(buf, PSTR("domoticzVl2idx "), 15) == 0) { if(!lDomo) { config.getDomoticzConfig(domo); lDomo = true; }; domo.vl2idx = String(buf+15).toInt(); - } else if(strncmp(buf, "domoticzVl3idx ", 15) == 0) { + } else if(strncmp_P(buf, PSTR("domoticzVl3idx "), 15) == 0) { if(!lDomo) { config.getDomoticzConfig(domo); lDomo = true; }; domo.vl3idx = String(buf+15).toInt(); - } else if(strncmp(buf, "domoticzCl1idx ", 15) == 0) { + } else if(strncmp_P(buf, PSTR("domoticzCl1idx "), 15) == 0) { if(!lDomo) { config.getDomoticzConfig(domo); lDomo = true; }; domo.cl1idx = String(buf+15).toInt(); - } else if(strncmp(buf, "ntpEnable ", 10) == 0) { + } else if(strncmp_P(buf, PSTR("ntpEnable "), 10) == 0) { if(!lNtp) { config.getNtpConfig(ntp); lNtp = true; }; ntp.enable = String(buf+10).toInt() == 1; - } else if(strncmp(buf, "ntpDhcp ", 8) == 0) { + } else if(strncmp_P(buf, PSTR("ntpDhcp "), 8) == 0) { if(!lNtp) { config.getNtpConfig(ntp); lNtp = true; }; ntp.dhcp = String(buf+8).toInt() == 1; - } else if(strncmp(buf, "ntpOffset ", 10) == 0) { + } else if(strncmp_P(buf, PSTR("ntpOffset "), 10) == 0) { if(!lNtp) { config.getNtpConfig(ntp); lNtp = true; }; ntp.offset = String(buf+10).toInt() / 10; - } else if(strncmp(buf, "ntpSummerOffset ", 16) == 0) { + } else if(strncmp_P(buf, PSTR("ntpSummerOffset "), 16) == 0) { if(!lNtp) { config.getNtpConfig(ntp); lNtp = true; }; ntp.summerOffset = String(buf+16).toInt() / 10; - } else if(strncmp(buf, "ntpServer ", 10) == 0) { + } else if(strncmp_P(buf, PSTR("ntpServer "), 10) == 0) { if(!lNtp) { config.getNtpConfig(ntp); lNtp = true; }; memcpy(ntp.server, buf+10, size-10); - } else if(strncmp(buf, "entsoeToken ", 12) == 0) { + } else if(strncmp_P(buf, PSTR("entsoeToken "), 12) == 0) { if(!lEntsoe) { config.getEntsoeConfig(entsoe); lEntsoe = true; }; memcpy(entsoe.token, buf+12, size-12); - } else if(strncmp(buf, "entsoeArea ", 11) == 0) { + } else if(strncmp_P(buf, PSTR("entsoeArea "), 11) == 0) { if(!lEntsoe) { config.getEntsoeConfig(entsoe); lEntsoe = true; }; memcpy(entsoe.area, buf+11, size-11); - } else if(strncmp(buf, "entsoeCurrency ", 15) == 0) { + } else if(strncmp_P(buf, PSTR("entsoeCurrency "), 15) == 0) { if(!lEntsoe) { config.getEntsoeConfig(entsoe); lEntsoe = true; }; memcpy(entsoe.currency, buf+15, size-15); - } else if(strncmp(buf, "entsoeMultiplier ", 17) == 0) { + } else if(strncmp_P(buf, PSTR("entsoeMultiplier "), 17) == 0) { if(!lEntsoe) { config.getEntsoeConfig(entsoe); lEntsoe = true; }; entsoe.multiplier = String(buf+17).toDouble() * 1000; - } else if(strncmp(buf, "thresholds ", 11) == 0) { + } else if(strncmp_P(buf, PSTR("thresholds "), 11) == 0) { if(!lEac) { config.getEnergyAccountingConfig(eac); lEac = true; }; int i = 0; char * pch = strtok (buf+11," "); @@ -1639,7 +1639,7 @@ void configFileParse() { eac.thresholds[i++] = String(pch).toInt(); pch = strtok (NULL, " "); } - } else if(strncmp(buf, "dayplot ", 8) == 0) { + } else if(strncmp_P(buf, PSTR("dayplot "), 8) == 0) { int i = 0; DayDataPoints day = { 4 }; // Use a version we know the multiplier of the data points char * pch = strtok (buf+8," "); @@ -1662,7 +1662,7 @@ void configFileParse() { } ds.setDayData(day); sDs = true; - } else if(strncmp(buf, "monthplot ", 10) == 0) { + } else if(strncmp_P(buf, PSTR("monthplot "), 10) == 0) { int i = 0; MonthDataPoints month = { 5 }; // Use a version we know the multiplier of the data points char * pch = strtok (buf+10," "); @@ -1685,7 +1685,7 @@ void configFileParse() { } ds.setMonthData(month); sDs = true; - } else if(strncmp(buf, "energyaccounting ", 17) == 0) { + } else if(strncmp_P(buf, PSTR("energyaccounting "), 17) == 0) { uint8_t i = 0; EnergyAccountingData ead = { 4, 0, 0, 0, 0, diff --git a/src/web/AmsWebServer.cpp b/src/web/AmsWebServer.cpp index 592305be..08803385 100644 --- a/src/web/AmsWebServer.cpp +++ b/src/web/AmsWebServer.cpp @@ -57,7 +57,7 @@ void AmsWebServer::setup(AmsConfiguration* config, GpioConfig* gpioConfig, Meter this->ds = ds; this->ea = ea; - snprintf(buf, 32, (char*) F("/application-%s.js"), VERSION); + snprintf_P(buf, 32, PSTR("/application-%s.js"), VERSION); server.on(F("/"), HTTP_GET, std::bind(&AmsWebServer::indexHtml, this)); server.on(F("/"), HTTP_POST, std::bind(&AmsWebServer::handleSetup, this)); @@ -162,8 +162,8 @@ bool AmsWebServer::checkSecurity(byte level) { String expectedBase64 = base64::encode(expectedAuth); #endif - debugger->printf((char*) F("Expected auth: %s\n"), expectedBase64.c_str()); - debugger->printf((char*) F("Provided auth: %s\n"), providedPwd.c_str()); + debugger->printf_P(PSTR("Expected auth: %s\n"), expectedBase64.c_str()); + debugger->printf_P(PSTR("Provided auth: %s\n"), providedPwd.c_str()); access = providedPwd.equals(expectedBase64); } @@ -229,7 +229,7 @@ void AmsWebServer::temperatureJson() { return; int count = hw->getTempSensorCount(); - snprintf(buf, 16, "{\"c\":%d,\"s\":[", count); + snprintf_P(buf, 16, PSTR("{\"c\":%d,\"s\":["), count); for(int i = 0; i < count; i++) { TempSensorData* data = hw->getTempSensorData(i); @@ -247,7 +247,7 @@ void AmsWebServer::temperatureJson() { delay(10); } char* pos = buf+strlen(buf); - snprintf(count == 0 ? pos : pos-1, 8, "]}"); + snprintf_P(count == 0 ? pos : pos-1, 8, PSTR("]}")); server.sendHeader(HEADER_CACHE_CONTROL, CACHE_CONTROL_NO_CACHE); server.sendHeader(HEADER_PRAGMA, PRAGMA_NO_CACHE); @@ -300,7 +300,7 @@ void AmsWebServer::applicationJs() { printD(F("Serving /application.js over http...")); server.sendHeader(HEADER_CACHE_CONTROL, CACHE_1HR); - server.send_P(200, (char*) F("application/javascript"), APPLICATION_JS); + server.send_P(200, PSTR("application/javascript"), APPLICATION_JS); } void AmsWebServer::configMeterHtml() { @@ -652,7 +652,7 @@ void AmsWebServer::githubSvg() { printD(F("Serving /github.svg over http...")); server.sendHeader(HEADER_CACHE_CONTROL, CACHE_1HR); - server.send_P(200, (char*) F("image/svg+xml"), GITHUB_SVG); + server.send_P(200, PSTR("image/svg+xml"), GITHUB_SVG); } void AmsWebServer::dataJson() { @@ -764,7 +764,7 @@ void AmsWebServer::dataJson() { wifiStatus, mqttStatus, mqtt == NULL ? 0 : (int) mqtt->lastError(), - price == ENTSOE_NO_VALUE ? (char*) F("null") : String(price, 2).c_str(), + price == ENTSOE_NO_VALUE ? PSTR("null") : String(price, 2).c_str(), meterState->getMeterType(), meterConfig->distributionSystem, ea->getMonthMax(), @@ -955,42 +955,42 @@ void AmsWebServer::energyPriceJson() { snprintf_P(buf, BufferSize, ENERGYPRICE_JSON, eapi == NULL ? "" : eapi->getCurrency(), - prices[0] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[0], 4).c_str(), - prices[1] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[1], 4).c_str(), - prices[2] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[2], 4).c_str(), - prices[3] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[3], 4).c_str(), - prices[4] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[4], 4).c_str(), - prices[5] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[5], 4).c_str(), - prices[6] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[6], 4).c_str(), - prices[7] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[7], 4).c_str(), - prices[8] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[8], 4).c_str(), - prices[9] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[9], 4).c_str(), - prices[10] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[10], 4).c_str(), - prices[11] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[11], 4).c_str(), - prices[12] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[12], 4).c_str(), - prices[13] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[13], 4).c_str(), - prices[14] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[14], 4).c_str(), - prices[15] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[15], 4).c_str(), - prices[16] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[16], 4).c_str(), - prices[17] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[17], 4).c_str(), - prices[18] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[18], 4).c_str(), - prices[19] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[19], 4).c_str(), - prices[20] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[20], 4).c_str(), - prices[21] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[21], 4).c_str(), - prices[22] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[22], 4).c_str(), - prices[23] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[23], 4).c_str(), - prices[24] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[24], 4).c_str(), - prices[25] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[25], 4).c_str(), - prices[26] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[26], 4).c_str(), - prices[27] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[27], 4).c_str(), - prices[28] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[28], 4).c_str(), - prices[29] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[29], 4).c_str(), - prices[30] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[30], 4).c_str(), - prices[31] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[31], 4).c_str(), - prices[32] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[32], 4).c_str(), - prices[33] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[33], 4).c_str(), - prices[34] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[34], 4).c_str(), - prices[35] == ENTSOE_NO_VALUE ? (char*) F("null") : String(prices[35], 4).c_str() + prices[0] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[0], 4).c_str(), + prices[1] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[1], 4).c_str(), + prices[2] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[2], 4).c_str(), + prices[3] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[3], 4).c_str(), + prices[4] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[4], 4).c_str(), + prices[5] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[5], 4).c_str(), + prices[6] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[6], 4).c_str(), + prices[7] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[7], 4).c_str(), + prices[8] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[8], 4).c_str(), + prices[9] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[9], 4).c_str(), + prices[10] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[10], 4).c_str(), + prices[11] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[11], 4).c_str(), + prices[12] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[12], 4).c_str(), + prices[13] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[13], 4).c_str(), + prices[14] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[14], 4).c_str(), + prices[15] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[15], 4).c_str(), + prices[16] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[16], 4).c_str(), + prices[17] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[17], 4).c_str(), + prices[18] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[18], 4).c_str(), + prices[19] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[19], 4).c_str(), + prices[20] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[20], 4).c_str(), + prices[21] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[21], 4).c_str(), + prices[22] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[22], 4).c_str(), + prices[23] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[23], 4).c_str(), + prices[24] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[24], 4).c_str(), + prices[25] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[25], 4).c_str(), + prices[26] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[26], 4).c_str(), + prices[27] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[27], 4).c_str(), + prices[28] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[28], 4).c_str(), + prices[29] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[29], 4).c_str(), + prices[30] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[30], 4).c_str(), + prices[31] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[31], 4).c_str(), + prices[32] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[32], 4).c_str(), + prices[33] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[33], 4).c_str(), + prices[34] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[34], 4).c_str(), + prices[35] == ENTSOE_NO_VALUE ? PSTR("null") : String(prices[35], 4).c_str() ); server.sendHeader(HEADER_CACHE_CONTROL, CACHE_CONTROL_NO_CACHE); @@ -1303,8 +1303,8 @@ void AmsWebServer::handleSave() { strcpy(webConfig.password, server.arg(F("ap")).c_str()); debugger->setPassword(webConfig.password); } else { - strcpy(webConfig.username, (char*) F("")); - strcpy(webConfig.password, (char*) F("")); + strcpy_P(webConfig.username, PSTR("")); + strcpy_P(webConfig.password, PSTR("")); debugger->setPassword(F("")); } config->setWebConfig(webConfig); @@ -1587,28 +1587,28 @@ HTTPUpload& AmsWebServer::uploadFile(const char* path) { } else { uploading = true; if(debugger->isActive(RemoteDebug::DEBUG)) { - debugger->printf((char*) F("handleFileUpload file: %s\n"), path); + debugger->printf_P(PSTR("handleFileUpload file: %s\n"), path); } if(LittleFS.exists(path)) { LittleFS.remove(path); } file = LittleFS.open(path, "w"); if(debugger->isActive(RemoteDebug::DEBUG)) { - debugger->printf((char*) F("handleFileUpload Open file and write: %u\n"), upload.currentSize); + debugger->printf_P(PSTR("handleFileUpload Open file and write: %u\n"), upload.currentSize); } size_t written = file.write(upload.buf, upload.currentSize); if(debugger->isActive(RemoteDebug::DEBUG)) { - debugger->printf((char*) F("handleFileUpload Written: %u\n"), written); + debugger->printf_P(PSTR("handleFileUpload Written: %u\n"), written); } } } else if(upload.status == UPLOAD_FILE_WRITE) { if(debugger->isActive(RemoteDebug::DEBUG)) { - debugger->printf((char*) F("handleFileUpload Writing: %u\n"), upload.currentSize); + debugger->printf_P(PSTR("handleFileUpload Writing: %u\n"), upload.currentSize); } if(file) { size_t written = file.write(upload.buf, upload.currentSize); if(debugger->isActive(RemoteDebug::DEBUG)) { - debugger->printf((char*) F("handleFileUpload Written: %u\n"), written); + debugger->printf_P(PSTR("handleFileUpload Written: %u\n"), written); } delay(1); if(written != upload.currentSize) { @@ -1882,9 +1882,9 @@ void AmsWebServer::mqttCa() { if(LittleFS.begin()) { if(LittleFS.exists(FILE_MQTT_CA)) { - deleteHtml((char*) F("CA file"), (char*) F("/mqtt-ca/delete"), (char*) F("mqtt")); + deleteHtml("CA file", "/mqtt-ca/delete", "mqtt"); } else { - uploadHtml((char*) F("CA file"), (char*) F("/mqtt-ca"), (char*) F("mqtt")); + uploadHtml("CA file", "/mqtt-ca", "mqtt"); } LittleFS.end(); } else { @@ -1936,9 +1936,9 @@ void AmsWebServer::mqttCert() { if(LittleFS.begin()) { if(LittleFS.exists(FILE_MQTT_CERT)) { - deleteHtml((char*) F("Certificate"), (char*) F("/mqtt-cert/delete"), (char*) F("mqtt")); + deleteHtml("Certificate", "/mqtt-cert/delete", "mqtt"); } else { - uploadHtml((char*) F("Certificate"), (char*) F("/mqtt-cert"), (char*) F("mqtt")); + uploadHtml("Certificate", "/mqtt-cert", "mqtt"); } LittleFS.end(); } else { @@ -1989,9 +1989,9 @@ void AmsWebServer::mqttKey() { if(LittleFS.begin()) { if(LittleFS.exists(FILE_MQTT_KEY)) { - deleteHtml((char*) F("Private key"), (char*) F("/mqtt-key/delete"), (char*) F("mqtt")); + deleteHtml("Private key", "/mqtt-key/delete", "mqtt"); } else { - uploadHtml((char*) F("Private key"), (char*) F("/mqtt-key"), (char*) F("mqtt")); + uploadHtml("Private key", "/mqtt-key", "mqtt"); } LittleFS.end(); } else { @@ -2148,135 +2148,135 @@ void AmsWebServer::configFileDownload() { server.setContentLength(CONTENT_LENGTH_UNKNOWN); server.send(200, MIME_PLAIN, F("amsconfig\n")); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("version %s\n"), VERSION)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("boardType %d\n"), sys.boardType)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("version %s\n"), VERSION)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("boardType %d\n"), sys.boardType)); if(includeWifi) { WiFiConfig wifi; config->getWiFiConfig(wifi); - if(includeSecrets) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("hostname %s\n"), wifi.hostname)); - if(includeSecrets) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("ssid %s\n"), wifi.ssid)); - if(includeSecrets) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("psk %s\n"), wifi.psk)); + if(includeSecrets) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("hostname %s\n"), wifi.hostname)); + if(includeSecrets) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("ssid %s\n"), wifi.ssid)); + if(includeSecrets) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("psk %s\n"), wifi.psk)); if(strlen(wifi.ip) > 0) { - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("ip %s\n"), wifi.ip)); - if(strlen(wifi.gateway) > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("gateway %s\n"), wifi.gateway)); - if(strlen(wifi.subnet) > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("subnet %s\n"), wifi.subnet)); - if(strlen(wifi.dns1) > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("dns1 %s\n"), wifi.dns1)); - if(strlen(wifi.dns2) > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("dns2 %s\n"), wifi.dns2)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("ip %s\n"), wifi.ip)); + if(strlen(wifi.gateway) > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("gateway %s\n"), wifi.gateway)); + if(strlen(wifi.subnet) > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("subnet %s\n"), wifi.subnet)); + if(strlen(wifi.dns1) > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("dns1 %s\n"), wifi.dns1)); + if(strlen(wifi.dns2) > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("dns2 %s\n"), wifi.dns2)); } - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("mdns %d\n"), wifi.mdns ? 1 : 0)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("mdns %d\n"), wifi.mdns ? 1 : 0)); } if(includeMqtt) { MqttConfig mqtt; config->getMqttConfig(mqtt); if(strlen(mqtt.host) > 0) { - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("mqttHost %s\n"), mqtt.host)); - if(mqtt.port > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("mqttPort %d\n"), mqtt.port)); - if(strlen(mqtt.clientId) > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("mqttClientId %s\n"), mqtt.clientId)); - if(strlen(mqtt.publishTopic) > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("mqttPublishTopic %s\n"), mqtt.publishTopic)); - if(includeSecrets) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("mqttUsername %s\n"), mqtt.username)); - if(includeSecrets) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("mqttPassword %s\n"), mqtt.password)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("mqttPayloadFormat %d\n"), mqtt.payloadFormat)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("mqttSsl %d\n"), mqtt.ssl ? 1 : 0)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("mqttHost %s\n"), mqtt.host)); + if(mqtt.port > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("mqttPort %d\n"), mqtt.port)); + if(strlen(mqtt.clientId) > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("mqttClientId %s\n"), mqtt.clientId)); + if(strlen(mqtt.publishTopic) > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("mqttPublishTopic %s\n"), mqtt.publishTopic)); + if(includeSecrets) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("mqttUsername %s\n"), mqtt.username)); + if(includeSecrets) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("mqttPassword %s\n"), mqtt.password)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("mqttPayloadFormat %d\n"), mqtt.payloadFormat)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("mqttSsl %d\n"), mqtt.ssl ? 1 : 0)); } } if(includeWeb && includeSecrets) { WebConfig web; config->getWebConfig(web); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("webSecurity %d\n"), web.security)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("webSecurity %d\n"), web.security)); if(web.security > 0) { - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("webUsername %s\n"), web.username)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("webPassword %s\n"), web.password)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("webUsername %s\n"), web.username)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("webPassword %s\n"), web.password)); } } if(includeMeter) { MeterConfig meter; config->getMeterConfig(meter); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("meterBaud %d\n"), meter.baud)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("meterBaud %d\n"), meter.baud)); char parity[4] = ""; switch(meter.parity) { case 2: - strcpy(parity, (char*) F("7N1")); + strcpy_P(parity, PSTR("7N1")); break; case 3: - strcpy(parity, (char*) F("8N1")); + strcpy_P(parity, PSTR("8N1")); break; case 10: - strcpy(parity, (char*) F("7E1")); + strcpy_P(parity, PSTR("7E1")); break; case 11: - strcpy(parity, (char*) F("8E1")); + strcpy_P(parity, PSTR("8E1")); break; } - if(strlen(parity) > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("meterParity %s\n"), parity)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("meterInvert %d\n"), meter.invert ? 1 : 0)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("meterDistributionSystem %d\n"), meter.distributionSystem)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("meterMainFuse %d\n"), meter.mainFuse)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("meterProductionCapacity %d\n"), meter.productionCapacity)); + if(strlen(parity) > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("meterParity %s\n"), parity)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("meterInvert %d\n"), meter.invert ? 1 : 0)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("meterDistributionSystem %d\n"), meter.distributionSystem)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("meterMainFuse %d\n"), meter.mainFuse)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("meterProductionCapacity %d\n"), meter.productionCapacity)); if(includeSecrets) { - if(meter.encryptionKey[0] != 0x00) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("meterEncryptionKey %s\n"), toHex(meter.encryptionKey, 16).c_str())); - if(meter.authenticationKey[0] != 0x00) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("meterAuthenticationKey %s\n"), toHex(meter.authenticationKey, 16).c_str())); + if(meter.encryptionKey[0] != 0x00) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("meterEncryptionKey %s\n"), toHex(meter.encryptionKey, 16).c_str())); + if(meter.authenticationKey[0] != 0x00) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("meterAuthenticationKey %s\n"), toHex(meter.authenticationKey, 16).c_str())); } } if(includeGpio) { GpioConfig gpio; config->getGpioConfig(gpio); - if(gpio.hanPin != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("gpioHanPin %d\n"), gpio.hanPin)); - if(gpio.apPin != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("gpioApPin %d\n"), gpio.apPin)); - if(gpio.ledPin != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("gpioLedPin %d\n"), gpio.ledPin)); - if(gpio.ledPin != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("gpioLedInverted %d\n"), gpio.ledInverted ? 1 : 0)); - if(gpio.ledPinRed != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("gpioLedPinRed %d\n"), gpio.ledPinRed)); - if(gpio.ledPinGreen != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("gpioLedPinGreen %d\n"), gpio.ledPinGreen)); - if(gpio.ledPinBlue != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("gpioLedPinBlue %d\n"), gpio.ledPinBlue)); - if(gpio.ledPinRed != 0xFF || gpio.ledPinGreen != 0xFF || gpio.ledPinBlue != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("gpioLedRgbInverted %d\n"), gpio.ledRgbInverted ? 1 : 0)); - if(gpio.tempSensorPin != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("gpioTempSensorPin %d\n"), gpio.tempSensorPin)); - if(gpio.tempAnalogSensorPin != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("gpioTempAnalogSensorPin %d\n"), gpio.tempAnalogSensorPin)); - if(gpio.vccPin != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("gpioVccPin %d\n"), gpio.vccPin)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("gpioVccOffset %.2f\n"), gpio.vccOffset / 100.0)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("gpioVccMultiplier %.3f\n"), gpio.vccMultiplier / 1000.0)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("gpioVccBootLimit %.1f\n"), gpio.vccBootLimit / 10.0)); - if(gpio.vccPin != 0xFF && gpio.vccResistorGnd != 0) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("gpioVccResistorGnd %d\n"), gpio.vccResistorGnd)); - if(gpio.vccPin != 0xFF && gpio.vccResistorVcc != 0) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("gpioVccResistorVcc %d\n"), gpio.vccResistorVcc)); + if(gpio.hanPin != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("gpioHanPin %d\n"), gpio.hanPin)); + if(gpio.apPin != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("gpioApPin %d\n"), gpio.apPin)); + if(gpio.ledPin != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("gpioLedPin %d\n"), gpio.ledPin)); + if(gpio.ledPin != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("gpioLedInverted %d\n"), gpio.ledInverted ? 1 : 0)); + if(gpio.ledPinRed != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("gpioLedPinRed %d\n"), gpio.ledPinRed)); + if(gpio.ledPinGreen != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("gpioLedPinGreen %d\n"), gpio.ledPinGreen)); + if(gpio.ledPinBlue != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("gpioLedPinBlue %d\n"), gpio.ledPinBlue)); + if(gpio.ledPinRed != 0xFF || gpio.ledPinGreen != 0xFF || gpio.ledPinBlue != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("gpioLedRgbInverted %d\n"), gpio.ledRgbInverted ? 1 : 0)); + if(gpio.tempSensorPin != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("gpioTempSensorPin %d\n"), gpio.tempSensorPin)); + if(gpio.tempAnalogSensorPin != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("gpioTempAnalogSensorPin %d\n"), gpio.tempAnalogSensorPin)); + if(gpio.vccPin != 0xFF) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("gpioVccPin %d\n"), gpio.vccPin)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("gpioVccOffset %.2f\n"), gpio.vccOffset / 100.0)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("gpioVccMultiplier %.3f\n"), gpio.vccMultiplier / 1000.0)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("gpioVccBootLimit %.1f\n"), gpio.vccBootLimit / 10.0)); + if(gpio.vccPin != 0xFF && gpio.vccResistorGnd != 0) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("gpioVccResistorGnd %d\n"), gpio.vccResistorGnd)); + if(gpio.vccPin != 0xFF && gpio.vccResistorVcc != 0) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("gpioVccResistorVcc %d\n"), gpio.vccResistorVcc)); } if(includeDomo) { DomoticzConfig domo; config->getDomoticzConfig(domo); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("domoticzElidx %d\n"), domo.elidx)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("domoticzVl1idx %d\n"), domo.vl1idx)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("domoticzVl2idx %d\n"), domo.vl2idx)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("domoticzVl3idx %d\n"), domo.vl3idx)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("domoticzCl1idx %d\n"), domo.cl1idx)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("domoticzElidx %d\n"), domo.elidx)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("domoticzVl1idx %d\n"), domo.vl1idx)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("domoticzVl2idx %d\n"), domo.vl2idx)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("domoticzVl3idx %d\n"), domo.vl3idx)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("domoticzCl1idx %d\n"), domo.cl1idx)); } if(includeNtp) { NtpConfig ntp; config->getNtpConfig(ntp); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("ntpEnable %d\n"), ntp.enable ? 1 : 0)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("ntpDhcp %d\n"), ntp.dhcp ? 1 : 0)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("ntpOffset %d\n"), ntp.offset * 10)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("ntpSummerOffset %d\n"), ntp.summerOffset * 10)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("ntpServer %s\n"), ntp.server)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("ntpEnable %d\n"), ntp.enable ? 1 : 0)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("ntpDhcp %d\n"), ntp.dhcp ? 1 : 0)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("ntpOffset %d\n"), ntp.offset * 10)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("ntpSummerOffset %d\n"), ntp.summerOffset * 10)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("ntpServer %s\n"), ntp.server)); } if(includeEntsoe) { EntsoeConfig entsoe; config->getEntsoeConfig(entsoe); - if(strlen(entsoe.token) == 36 && includeSecrets) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("entsoeToken %s\n"), entsoe.token)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("entsoeArea %s\n"), entsoe.area)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("entsoeCurrency %s\n"), entsoe.currency)); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("entsoeMultiplier %.3f\n"), entsoe.multiplier / 1000.0)); + if(strlen(entsoe.token) == 36 && includeSecrets) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("entsoeToken %s\n"), entsoe.token)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("entsoeArea %s\n"), entsoe.area)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("entsoeCurrency %s\n"), entsoe.currency)); + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("entsoeMultiplier %.3f\n"), entsoe.multiplier / 1000.0)); } if(includeThresholds) { EnergyAccountingConfig eac; config->getEnergyAccountingConfig(eac); - if(eac.thresholds[9] > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("thresholds %d %d %d %d %d %d %d %d %d %d %d\n"), + if(eac.thresholds[9] > 0) server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("thresholds %d %d %d %d %d %d %d %d %d %d %d\n"), eac.thresholds[0], eac.thresholds[1], eac.thresholds[2], @@ -2294,7 +2294,7 @@ void AmsWebServer::configFileDownload() { if(ds != NULL) { DayDataPoints day = ds->getDayData(); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("dayplot %d %lld %lu %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"), + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("dayplot %d %lld %lu %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"), day.version, (int64_t) day.lastMeterReadTime, day.activeImport, @@ -2324,7 +2324,7 @@ void AmsWebServer::configFileDownload() { ds->getHourImport(23) )); if(day.activeExport > 0) { - server.sendContent(buf, snprintf(buf, BufferSize, (char*) F(" %u %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n"), + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR(" %u %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n"), day.activeExport, ds->getHourExport(0), ds->getHourExport(1), @@ -2356,7 +2356,7 @@ void AmsWebServer::configFileDownload() { } MonthDataPoints month = ds->getMonthData(); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("monthplot %d %lld %lu %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"), + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("monthplot %d %lld %lu %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"), month.version, (int64_t) month.lastMeterReadTime, month.activeImport, @@ -2393,7 +2393,7 @@ void AmsWebServer::configFileDownload() { ds->getDayImport(31) )); if(month.activeExport > 0) { - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F(" %u %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n"), + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR(" %u %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n"), month.activeExport, ds->getDayExport(1), ds->getDayExport(2), @@ -2436,7 +2436,7 @@ void AmsWebServer::configFileDownload() { EnergyAccountingConfig eac; config->getEnergyAccountingConfig(eac); EnergyAccountingData ead = ea->getData(); - server.sendContent(buf, snprintf_P(buf, BufferSize, (char*) F("energyaccounting %d %d %.2f %.2f %.2f %.2f %d %.2f %d %.2f %d %.2f %d %.2f %d %.2f"), + server.sendContent(buf, snprintf_P(buf, BufferSize, PSTR("energyaccounting %d %d %.2f %.2f %.2f %.2f %d %.2f %d %.2f %d %.2f %d %.2f %d %.2f"), ead.version, ead.month, 0.0, // Old max