Skip to content

Commit

Permalink
remove PSTR()
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Sep 15, 2021
1 parent 442202d commit d0346e4
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 94 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG_LATEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

## Added

- add system commands for syslog level and watch [#98](https://github.com/emsesp/EMS-ESP32/issues/98)
- Add system commands for syslog level and watch [#98](https://github.com/emsesp/EMS-ESP32/issues/98)
- Added pool data to telegrams 0x494 & 0x495 #102 [#102](https://github.com/emsesp/EMS-ESP32/issues/102) (@Sunbuzz)
- Add RC300 second summermode telegram [#108](https://github.com/emsesp/EMS-ESP32/issues/108)

## Fixed

- MQTT reconnecting after WiFi reconnect [#99](https://github.com/emsesp/EMS-ESP32/issues/99)
- Manually Controlling Solar Circuit [#107](https://github.com/emsesp/EMS-ESP32/issues/107)

## Changed

Expand Down
4 changes: 2 additions & 2 deletions src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void EMSESPShell::display_banner() {

if (console_hostname_.empty()) {
console_hostname_.resize(16, '\0');
snprintf_P(&console_hostname_[0], console_hostname_.capacity() + 1, PSTR("ems-esp"));
snprintf_P(&console_hostname_[0], console_hostname_.capacity() + 1, "ems-esp");
}

// load the list of commands
Expand Down Expand Up @@ -841,7 +841,7 @@ EMSESPStreamConsole::EMSESPStreamConsole(Stream & stream, const IPAddress & addr
ptys_[pty_] = true;
}

snprintf_P(text.data(), text.size(), PSTR("pty%u"), pty_);
snprintf_P(text.data(), text.size(), "pty%u", pty_);
name_ = text.data();
#ifndef EMSESP_STANDALONE
logger().info(F("Allocated console %s for connection from [%s]:%u"), name_.c_str(), uuid::printable_to_string(addr_).c_str(), port_);
Expand Down
24 changes: 12 additions & 12 deletions src/dallassensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ std::string DallasSensor::Sensor::id_string() const {
std::string str(20, '\0');
snprintf_P(&str[0],
str.capacity() + 1,
PSTR("%02X-%04X-%04X-%04X"),
"%02X-%04X-%04X-%04X",
(unsigned int)(id_ >> 48) & 0xFF,
(unsigned int)(id_ >> 32) & 0xFFFF,
(unsigned int)(id_ >> 16) & 0xFFFF,
Expand Down Expand Up @@ -347,7 +347,7 @@ void DallasSensor::delete_ha_config(uint8_t index, const char * name) {
std::string topicname = name;
std::replace(topicname.begin(), topicname.end(), '-', '_');

snprintf_P(topic, sizeof(topic), PSTR("homeassistant/sensor/%s/dallassensor_%s/config"), Mqtt::base().c_str(), topicname.c_str());
snprintf_P(topic, sizeof(topic), "homeassistant/sensor/%s/dallassensor_%s/config", Mqtt::base().c_str(), topicname.c_str());
Mqtt::publish(topic);
registered_ha_[index] = false; // forces a recreate of the HA config topic
}
Expand Down Expand Up @@ -461,7 +461,7 @@ bool DallasSensor::command_info(const char * value, const int8_t id, JsonObject
uint8_t i = 1; // sensor count
for (const auto & sensor : sensors_) {
char sensorID[10]; // sensor{1-n}
snprintf_P(sensorID, 10, PSTR("sensor%d"), i++);
snprintf_P(sensorID, 10, "sensor%d", i++);
if (id == -1) { // show number and id
JsonObject dataSensor = json.createNestedObject(sensorID);
dataSensor["id"] = sensor.to_string();
Expand Down Expand Up @@ -493,7 +493,7 @@ void DallasSensor::publish_values(const bool force) {

for (const auto & sensor : sensors_) {
char sensorID[10]; // sensor{1-n}
snprintf_P(sensorID, 10, PSTR("sensor%d"), sensor_no);
snprintf_P(sensorID, 10, "sensor%d", sensor_no);
if (dallas_format_ == Dallas_Format::NUMBER) {
// e.g. dallassensor_data = {"sensor1":{"id":"28-EA41-9497-0E03","temp":23.3},"sensor2":{"id":"28-233D-9497-0C03","temp":24.0}}
JsonObject dataSensor = doc.createNestedObject(sensorID);
Expand All @@ -513,28 +513,28 @@ void DallasSensor::publish_values(const bool force) {
config["dev_cla"] = FJSON("temperature");

char stat_t[50];
snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/dallassensor_data"), Mqtt::base().c_str());
snprintf_P(stat_t, sizeof(stat_t), "%s/dallassensor_data", Mqtt::base().c_str());
config["stat_t"] = stat_t;

config["unit_of_meas"] = FJSON("°C");

char str[50];
if (dallas_format_ != Dallas_Format::NUMBER) {
snprintf_P(str, sizeof(str), PSTR("{{value_json['%s']}}"), sensor.to_string().c_str());
snprintf_P(str, sizeof(str), "{{value_json['%s']}}", sensor.to_string().c_str());
} else {
snprintf_P(str, sizeof(str), PSTR("{{value_json.sensor%d.temp}}"), sensor_no);
snprintf_P(str, sizeof(str), "{{value_json.sensor%d.temp}}", sensor_no);
}
config["val_tpl"] = str;

// name as sensor number not the long unique ID
if (dallas_format_ != Dallas_Format::NUMBER) {
snprintf_P(str, sizeof(str), PSTR("Dallas Sensor %s"), sensor.to_string().c_str());
snprintf_P(str, sizeof(str), "Dallas Sensor %s", sensor.to_string().c_str());
} else {
snprintf_P(str, sizeof(str), PSTR("Dallas Sensor %d"), sensor_no);
snprintf_P(str, sizeof(str), "Dallas Sensor %d", sensor_no);
}
config["name"] = str;

snprintf_P(str, sizeof(str), PSTR("dallasensor_%s"), sensor.to_string().c_str());
snprintf_P(str, sizeof(str), "dallasensor_%s", sensor.to_string().c_str());
config["uniq_id"] = str;

JsonObject dev = config.createNestedObject("dev");
Expand All @@ -543,12 +543,12 @@ void DallasSensor::publish_values(const bool force) {

char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
if (dallas_format_ == Dallas_Format::NUMBER) {
snprintf_P(topic, sizeof(topic), PSTR("sensor/%s/dallassensor_%d/config"), Mqtt::base().c_str(), sensor_no);
snprintf_P(topic, sizeof(topic), "sensor/%s/dallassensor_%d/config", Mqtt::base().c_str(), sensor_no);
} else {
// use '_' as HA doesn't like '-' in the topic name
std::string topicname = sensor.to_string();
std::replace(topicname.begin(), topicname.end(), '-', '_');
snprintf_P(topic, sizeof(topic), PSTR("sensor/%s/dallassensor_%s/config"), Mqtt::base().c_str(), topicname.c_str());
snprintf_P(topic, sizeof(topic), "sensor/%s/dallassensor_%s/config", Mqtt::base().c_str(), topicname.c_str());
}
Mqtt::publish_ha(topic, config.as<JsonObject>());

Expand Down
10 changes: 5 additions & 5 deletions src/devices/boiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ bool Boiler::publish_ha_config() {
doc["ic"] = F_(icondevice);

char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/%s"), Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
snprintf_P(stat_t, sizeof(stat_t), "%s/%s", Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
doc["stat_t"] = stat_t;

char name_s[40];
Expand All @@ -304,7 +304,7 @@ bool Boiler::publish_ha_config() {
ids.add("ems-esp-boiler");

char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), PSTR("sensor/%s/boiler/config"), Mqtt::base().c_str());
snprintf_P(topic, sizeof(topic), "sensor/%s/boiler/config", Mqtt::base().c_str());
Mqtt::publish_ha(topic,
doc.as<JsonObject>()); // publish the config payload with retain flag

Expand Down Expand Up @@ -791,7 +791,7 @@ void Boiler::process_UBAMaintenanceStatus(std::shared_ptr<const Telegram> telegr

// ignore if 0, which means all is ok
if (Helpers::hasValue(message_code) && message_code > 0) {
snprintf_P(maintenanceMessage_, sizeof(maintenanceMessage_), PSTR("H%02d"), message_code);
snprintf_P(maintenanceMessage_, sizeof(maintenanceMessage_), "H%02d", message_code);
}
}

Expand All @@ -818,7 +818,7 @@ void Boiler::process_UBAErrorMessage(std::shared_ptr<const Telegram> telegram) {
uint32_t date = (year - 2000) * 535680UL + month * 44640UL + day * 1440UL + hour * 60 + min;
// store only the newest code from telegrams 10 and 11
if (date > lastCodeDate_) {
snprintf_P(lastCode_, sizeof(lastCode_), PSTR("%s(%d) %02d.%02d.%d %02d:%02d"), code, codeNo, day, month, year, hour, min);
snprintf_P(lastCode_, sizeof(lastCode_), "%s(%d) %02d.%02d.%d %02d:%02d", code, codeNo, day, month, year, hour, min);
lastCodeDate_ = date;
}
}
Expand All @@ -844,7 +844,7 @@ void Boiler::process_UBAMaintenanceData(std::shared_ptr<const Telegram> telegram
uint8_t month = telegram->message_data[3];
uint8_t year = telegram->message_data[4];
if (day > 0 && month > 0) {
snprintf_P(maintenanceDate_, sizeof(maintenanceDate_), PSTR("%02d.%02d.%04d"), day, month, year + 2000);
snprintf_P(maintenanceDate_, sizeof(maintenanceDate_), "%02d.%02d.%04d", day, month, year + 2000);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/devices/heatpump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ bool Heatpump::publish_ha_config() {
doc["ic"] = F_(icondevice);

char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/%s"), Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
snprintf_P(stat_t, sizeof(stat_t), "%s/%s", Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
doc["stat_t"] = stat_t;

char name_s[40];
Expand All @@ -64,7 +64,7 @@ bool Heatpump::publish_ha_config() {
ids.add("ems-esp-heatpump");

char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), PSTR("sensor/%s/heatpump/config"), Mqtt::base().c_str());
snprintf_P(topic, sizeof(topic), "sensor/%s/heatpump/config", Mqtt::base().c_str());
Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag

return true;
Expand Down
21 changes: 10 additions & 11 deletions src/devices/mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ uuid::log::Logger Mixer::logger_{F_(mixer), uuid::log::Facility::CONSOLE};

Mixer::Mixer(uint8_t device_type, uint8_t device_id, uint8_t product_id, const std::string & version, const std::string & name, uint8_t flags, uint8_t brand)
: EMSdevice(device_type, device_id, product_id, version, name, flags, brand) {

LOG_DEBUG(F("Adding new Mixer with device ID 0x%02X"), device_id);

// Pool module
Expand Down Expand Up @@ -111,23 +110,23 @@ bool Mixer::publish_ha_config() {

char uniq_id[20];
if (type_ == Type::MP) {
snprintf_P(uniq_id, sizeof(uniq_id), PSTR("MixerMP"));
snprintf_P(uniq_id, sizeof(uniq_id), "MixerMP");
} else {
snprintf_P(uniq_id, sizeof(uniq_id), PSTR("Mixer%02X"), device_id() - 0x20 + 1);
snprintf_P(uniq_id, sizeof(uniq_id), "Mixer%02X", device_id() - 0x20 + 1);
}
doc["uniq_id"] = uniq_id;

doc["ic"] = F_(icondevice);

char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/%s"), Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
snprintf_P(stat_t, sizeof(stat_t), "%s/%s", Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
doc["stat_t"] = stat_t;

char name[20];
if (type_ == Type::MP) {
snprintf_P(name, sizeof(name), PSTR("Mixer MP"));
snprintf_P(name, sizeof(name), "Mixer MP");
} else {
snprintf_P(name, sizeof(name), PSTR("Mixer %02X"), device_id() - 0x20 + 1);
snprintf_P(name, sizeof(name), "Mixer %02X", device_id() - 0x20 + 1);
}
doc["name"] = name;

Expand All @@ -152,11 +151,11 @@ bool Mixer::publish_ha_config() {
// determine the topic, if its HC and WWC. This is determined by the incoming telegram types.
std::string topic(Mqtt::MQTT_TOPIC_MAX_SIZE, '\0');
if (type_ == Type::HC) {
snprintf_P(&topic[0], topic.capacity() + 1, PSTR("sensor/%s/mixer_hc%d/config"), Mqtt::base().c_str(), hc_);
snprintf_P(&topic[0], topic.capacity() + 1, "sensor/%s/mixer_hc%d/config", Mqtt::base().c_str(), hc_);
} else if (type_ == Type::WWC) {
snprintf_P(&topic[0], topic.capacity() + 1, PSTR("sensor/%s/mixer_wwc%d/config"), Mqtt::base().c_str(), hc_); // WWC
snprintf_P(&topic[0], topic.capacity() + 1, "sensor/%s/mixer_wwc%d/config", Mqtt::base().c_str(), hc_); // WWC
} else if (type_ == Type::MP) {
snprintf_P(&topic[0], topic.capacity() + 1, PSTR("sensor/%s/mixer_mp/config"), Mqtt::base().c_str());
snprintf_P(&topic[0], topic.capacity() + 1, "sensor/%s/mixer_mp/config", Mqtt::base().c_str());
}

Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
Expand Down Expand Up @@ -228,7 +227,7 @@ void Mixer::process_MMStatusMessage(std::shared_ptr<const Telegram> telegram) {
void Mixer::process_HpPoolStatus(std::shared_ptr<const Telegram> telegram) {
has_update(telegram->read_value(poolTemp_, 0));
has_update(telegram->read_value(poolShuntStatus__, 2));
has_update(telegram->read_value(poolShunt_, 3)); // 0-100% how much is the shunt open?
has_update(telegram->read_value(poolShunt_, 3)); // 0-100% how much is the shunt open?
poolShuntStatus_ = poolShunt_ == 100 ? 3 : (poolShunt_ == 0 ? 4 : poolShuntStatus__);
}

Expand Down Expand Up @@ -272,7 +271,7 @@ bool Mixer::set_flowSetTemp(const char * value, const int8_t id) {
return true;
}
if (flags() == EMSdevice::EMS_DEVICE_FLAG_MMPLUS) {
uint8_t hc = device_id() -0x20;
uint8_t hc = device_id() - 0x20;
write_command(0x2E1 + hc, 1, v, 0x2D7 + hc);
return true;
}
Expand Down
13 changes: 9 additions & 4 deletions src/devices/solar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,13 @@ Solar::Solar(uint8_t device_type, uint8_t device_id, uint8_t product_id, const s
register_device_value(TAG_NONE, &solarPumpMinMod_, DeviceValueType::UINT, nullptr, FL_(pumpMinMod), DeviceValueUOM::PERCENT, MAKE_CF_CB(set_PumpMinMod));
register_device_value(
TAG_NONE, &solarPumpTurnonDiff_, DeviceValueType::UINT, FL_(div10), FL_(solarPumpTurnonDiff), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_TurnonDiff));
register_device_value(
TAG_NONE, &solarPumpTurnoffDiff_, DeviceValueType::UINT, FL_(div10), FL_(solarPumpTurnoffDiff), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_TurnoffDiff));
register_device_value(TAG_NONE,
&solarPumpTurnoffDiff_,
DeviceValueType::UINT,
FL_(div10),
FL_(solarPumpTurnoffDiff),
DeviceValueUOM::DEGREES,
MAKE_CF_CB(set_TurnoffDiff));
register_device_value(TAG_NONE, &tankBottomTemp2_, DeviceValueType::SHORT, FL_(div10), FL_(tank2BottomTemp), DeviceValueUOM::DEGREES);
register_device_value(TAG_NONE, &heatExchangerTemp_, DeviceValueType::SHORT, FL_(div10), FL_(heatExchangerTemp), DeviceValueUOM::DEGREES);
register_device_value(TAG_NONE, &cylinderPumpModulation_, DeviceValueType::UINT, nullptr, FL_(cylinderPumpModulation), DeviceValueUOM::PERCENT);
Expand Down Expand Up @@ -189,7 +194,7 @@ bool Solar::publish_ha_config() {
doc["ic"] = F_(icondevice);

char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/%s"), Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
snprintf_P(stat_t, sizeof(stat_t), "%s/%s", Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
doc["stat_t"] = stat_t;

char name_s[40];
Expand All @@ -206,7 +211,7 @@ bool Solar::publish_ha_config() {
ids.add("ems-esp-solar");

char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), PSTR("sensor/%s/solar/config"), Mqtt::base().c_str());
snprintf_P(topic, sizeof(topic), "sensor/%s/solar/config", Mqtt::base().c_str());
Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/devices/switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool Switch::publish_ha_config() {
doc["ic"] = F_(icondevice);

char stat_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/%s"), Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
snprintf_P(stat_t, sizeof(stat_t), "%s/%s", Mqtt::base().c_str(), Mqtt::tag_to_topic(device_type(), DeviceValueTAG::TAG_NONE).c_str());
doc["stat_t"] = stat_t;

char name_s[40];
Expand All @@ -70,7 +70,7 @@ bool Switch::publish_ha_config() {
ids.add("ems-esp-switch");

char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf_P(topic, sizeof(topic), PSTR("sensor/%s/switch/config"), Mqtt::base().c_str());
snprintf_P(topic, sizeof(topic), "sensor/%s/switch/config", Mqtt::base().c_str());
Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag

return true;
Expand Down

0 comments on commit d0346e4

Please sign in to comment.