From 4c2822cdbc510b1bf99cd8e5390ca040e139369e Mon Sep 17 00:00:00 2001 From: Bernhard Kirchen Date: Fri, 12 Apr 2024 15:25:54 +0200 Subject: [PATCH] remove usage of F() macro frees 888 Bytes of flash. --- src/BatteryStats.cpp | 72 +++++++++++++++++++-------------------- src/WebApi_powermeter.cpp | 10 +++--- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/BatteryStats.cpp b/src/BatteryStats.cpp index 720695f34..5acffa370 100644 --- a/src/BatteryStats.cpp +++ b/src/BatteryStats.cpp @@ -61,8 +61,8 @@ bool BatteryStats::updateAvailable(uint32_t since) const void BatteryStats::getLiveViewData(JsonVariant& root) const { - root[F("manufacturer")] = _manufacturer; - root[F("data_age")] = getAgeSeconds(); + root["manufacturer"] = _manufacturer; + root["data_age"] = getAgeSeconds(); addLiveViewValue(root, "SoC", _soc, "%", _socPrecision); addLiveViewValue(root, "voltage", _voltage, "V", 2); @@ -218,39 +218,39 @@ uint32_t BatteryStats::getMqttFullPublishIntervalMs() const void BatteryStats::mqttPublish() const { - MqttSettings.publish(F("battery/manufacturer"), _manufacturer); - MqttSettings.publish(F("battery/dataAge"), String(getAgeSeconds())); - MqttSettings.publish(F("battery/stateOfCharge"), String(_soc)); - MqttSettings.publish(F("battery/voltage"), String(_voltage)); + MqttSettings.publish("battery/manufacturer", _manufacturer); + MqttSettings.publish("battery/dataAge", String(getAgeSeconds())); + MqttSettings.publish("battery/stateOfCharge", String(_soc)); + MqttSettings.publish("battery/voltage", String(_voltage)); } void PylontechBatteryStats::mqttPublish() const { BatteryStats::mqttPublish(); - MqttSettings.publish(F("battery/settings/chargeVoltage"), String(_chargeVoltage)); - MqttSettings.publish(F("battery/settings/chargeCurrentLimitation"), String(_chargeCurrentLimitation)); - MqttSettings.publish(F("battery/settings/dischargeCurrentLimitation"), String(_dischargeCurrentLimitation)); - MqttSettings.publish(F("battery/stateOfHealth"), String(_stateOfHealth)); - MqttSettings.publish(F("battery/current"), String(_current)); - MqttSettings.publish(F("battery/temperature"), String(_temperature)); - MqttSettings.publish(F("battery/alarm/overCurrentDischarge"), String(_alarmOverCurrentDischarge)); - MqttSettings.publish(F("battery/alarm/overCurrentCharge"), String(_alarmOverCurrentCharge)); - MqttSettings.publish(F("battery/alarm/underTemperature"), String(_alarmUnderTemperature)); - MqttSettings.publish(F("battery/alarm/overTemperature"), String(_alarmOverTemperature)); - MqttSettings.publish(F("battery/alarm/underVoltage"), String(_alarmUnderVoltage)); - MqttSettings.publish(F("battery/alarm/overVoltage"), String(_alarmOverVoltage)); - MqttSettings.publish(F("battery/alarm/bmsInternal"), String(_alarmBmsInternal)); - MqttSettings.publish(F("battery/warning/highCurrentDischarge"), String(_warningHighCurrentDischarge)); - MqttSettings.publish(F("battery/warning/highCurrentCharge"), String(_warningHighCurrentCharge)); - MqttSettings.publish(F("battery/warning/lowTemperature"), String(_warningLowTemperature)); - MqttSettings.publish(F("battery/warning/highTemperature"), String(_warningHighTemperature)); - MqttSettings.publish(F("battery/warning/lowVoltage"), String(_warningLowVoltage)); - MqttSettings.publish(F("battery/warning/highVoltage"), String(_warningHighVoltage)); - MqttSettings.publish(F("battery/warning/bmsInternal"), String(_warningBmsInternal)); - MqttSettings.publish(F("battery/charging/chargeEnabled"), String(_chargeEnabled)); - MqttSettings.publish(F("battery/charging/dischargeEnabled"), String(_dischargeEnabled)); - MqttSettings.publish(F("battery/charging/chargeImmediately"), String(_chargeImmediately)); + MqttSettings.publish("battery/settings/chargeVoltage", String(_chargeVoltage)); + MqttSettings.publish("battery/settings/chargeCurrentLimitation", String(_chargeCurrentLimitation)); + MqttSettings.publish("battery/settings/dischargeCurrentLimitation", String(_dischargeCurrentLimitation)); + MqttSettings.publish("battery/stateOfHealth", String(_stateOfHealth)); + MqttSettings.publish("battery/current", String(_current)); + MqttSettings.publish("battery/temperature", String(_temperature)); + MqttSettings.publish("battery/alarm/overCurrentDischarge", String(_alarmOverCurrentDischarge)); + MqttSettings.publish("battery/alarm/overCurrentCharge", String(_alarmOverCurrentCharge)); + MqttSettings.publish("battery/alarm/underTemperature", String(_alarmUnderTemperature)); + MqttSettings.publish("battery/alarm/overTemperature", String(_alarmOverTemperature)); + MqttSettings.publish("battery/alarm/underVoltage", String(_alarmUnderVoltage)); + MqttSettings.publish("battery/alarm/overVoltage", String(_alarmOverVoltage)); + MqttSettings.publish("battery/alarm/bmsInternal", String(_alarmBmsInternal)); + MqttSettings.publish("battery/warning/highCurrentDischarge", String(_warningHighCurrentDischarge)); + MqttSettings.publish("battery/warning/highCurrentCharge", String(_warningHighCurrentCharge)); + MqttSettings.publish("battery/warning/lowTemperature", String(_warningLowTemperature)); + MqttSettings.publish("battery/warning/highTemperature", String(_warningHighTemperature)); + MqttSettings.publish("battery/warning/lowVoltage", String(_warningLowVoltage)); + MqttSettings.publish("battery/warning/highVoltage", String(_warningHighVoltage)); + MqttSettings.publish("battery/warning/bmsInternal", String(_warningBmsInternal)); + MqttSettings.publish("battery/charging/chargeEnabled", String(_chargeEnabled)); + MqttSettings.publish("battery/charging/dischargeEnabled", String(_dischargeEnabled)); + MqttSettings.publish("battery/charging/chargeImmediately", String(_chargeImmediately)); } void JkBmsBatteryStats::mqttPublish() const @@ -424,11 +424,11 @@ void VictronSmartShuntStats::getLiveViewData(JsonVariant& root) const { void VictronSmartShuntStats::mqttPublish() const { BatteryStats::mqttPublish(); - MqttSettings.publish(F("battery/current"), String(_current)); - MqttSettings.publish(F("battery/chargeCycles"), String(_chargeCycles)); - MqttSettings.publish(F("battery/chargedEnergy"), String(_chargedEnergy)); - MqttSettings.publish(F("battery/dischargedEnergy"), String(_dischargedEnergy)); - MqttSettings.publish(F("battery/instantaneousPower"), String(_instantaneousPower)); - MqttSettings.publish(F("battery/consumedAmpHours"), String(_consumedAmpHours)); - MqttSettings.publish(F("battery/lastFullCharge"), String(_lastFullCharge)); + MqttSettings.publish("battery/current", String(_current)); + MqttSettings.publish("battery/chargeCycles", String(_chargeCycles)); + MqttSettings.publish("battery/chargedEnergy", String(_chargedEnergy)); + MqttSettings.publish("battery/dischargedEnergy", String(_dischargedEnergy)); + MqttSettings.publish("battery/instantaneousPower", String(_instantaneousPower)); + MqttSettings.publish("battery/consumedAmpHours", String(_consumedAmpHours)); + MqttSettings.publish("battery/lastFullCharge", String(_lastFullCharge)); } diff --git a/src/WebApi_powermeter.cpp b/src/WebApi_powermeter.cpp index 137168baf..5a7e9bf22 100644 --- a/src/WebApi_powermeter.cpp +++ b/src/WebApi_powermeter.cpp @@ -252,11 +252,11 @@ void WebApiPowerMeterClass::onTestHttpRequest(AsyncWebServerRequest* request) char response[256]; int phase = 0;//"absuing" index 0 of the float power[3] in HttpPowerMeter to store the result - if (HttpPowerMeter.queryPhase(phase, root[F("url")].as().c_str(), - root[F("auth_type")].as(), root[F("username")].as().c_str(), root[F("password")].as().c_str(), - root[F("header_key")].as().c_str(), root[F("header_value")].as().c_str(), root[F("timeout")].as(), - root[F("json_path")].as().c_str())) { - retMsg[F("type")] = F("success"); + if (HttpPowerMeter.queryPhase(phase, root["url"].as().c_str(), + root["auth_type"].as(), root["username"].as().c_str(), root["password"].as().c_str(), + root["header_key"].as().c_str(), root["header_value"].as().c_str(), root["timeout"].as(), + root["json_path"].as().c_str())) { + retMsg["type"] = "success"; snprintf_P(response, sizeof(response), "Success! Power: %5.2fW", HttpPowerMeter.getPower(phase + 1)); } else { snprintf_P(response, sizeof(response), "%s", HttpPowerMeter.httpPowerMeterError);