Skip to content

Commit

Permalink
remove usage of F() macro
Browse files Browse the repository at this point in the history
frees 888 Bytes of flash.
  • Loading branch information
schlimmchen committed Apr 12, 2024
1 parent 8b3a1be commit 4c2822c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
72 changes: 36 additions & 36 deletions src/BatteryStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
10 changes: 5 additions & 5 deletions src/WebApi_powermeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>().c_str(),
root[F("auth_type")].as<Auth>(), root[F("username")].as<String>().c_str(), root[F("password")].as<String>().c_str(),
root[F("header_key")].as<String>().c_str(), root[F("header_value")].as<String>().c_str(), root[F("timeout")].as<uint16_t>(),
root[F("json_path")].as<String>().c_str())) {
retMsg[F("type")] = F("success");
if (HttpPowerMeter.queryPhase(phase, root["url"].as<String>().c_str(),
root["auth_type"].as<Auth>(), root["username"].as<String>().c_str(), root["password"].as<String>().c_str(),
root["header_key"].as<String>().c_str(), root["header_value"].as<String>().c_str(), root["timeout"].as<uint16_t>(),
root["json_path"].as<String>().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);
Expand Down

0 comments on commit 4c2822c

Please sign in to comment.