Skip to content

Commit

Permalink
Merge pull request #2390 from proddy/dev
Browse files Browse the repository at this point in the history
fix system command read from crashing
  • Loading branch information
proddy authored Feb 2, 2025
2 parents 02a3dee + 7a044a1 commit 5b07309
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ CPPFLAGS += -Wall -Wextra -Werror
CPPFLAGS += -Wswitch-enum
CPPFLAGS += -Wno-unused-parameter
CPPFLAGS += -Wno-missing-braces
CPPFLAGS += -Wno-tautological-constant-out-of-range-compare
# CPPFLAGS += -Wno-tautological-constant-out-of-range-compare

CFLAGS += $(CPPFLAGS)
CXXFLAGS += $(CPPFLAGS)
Expand Down
16 changes: 7 additions & 9 deletions src/core/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ std::string Mqtt::lastresponse_ = "";
// icons from https://materialdesignicons.com used with the UOMs (unit of measurements)
MAKE_WORD(measurement)
MAKE_WORD(total_increasing)
MAKE_WORD_CUSTOM(icondegrees, "mdi:coolant-temperature") // DeviceValueUOM::DEGREES
MAKE_WORD_CUSTOM(iconpercent, "mdi:percent-outline") // DeviceValueUOM::PERCENT
MAKE_WORD_CUSTOM(iconkb, "mdi:memory") // DeviceValueUOM::KB
MAKE_WORD_CUSTOM(iconlmin, "mdi:water-boiler") // DeviceValueUOM::LMIN
MAKE_WORD_CUSTOM(iconua, "mdi:lightning-bolt-circle") // DeviceValueUOM::UA
MAKE_WORD_CUSTOM(iconnum, "mdi:counter") // DeviceValueUOM::NONE
// MAKE_WORD_CUSTOM(icondegrees, "mdi:coolant-temperature") // DeviceValueUOM::DEGREES
MAKE_WORD_CUSTOM(iconpercent, "mdi:percent-outline") // DeviceValueUOM::PERCENT
MAKE_WORD_CUSTOM(iconkb, "mdi:memory") // DeviceValueUOM::KB
MAKE_WORD_CUSTOM(iconlmin, "mdi:water-boiler") // DeviceValueUOM::LMIN
MAKE_WORD_CUSTOM(iconua, "mdi:lightning-bolt-circle") // DeviceValueUOM::UA
MAKE_WORD_CUSTOM(iconnum, "mdi:counter") // DeviceValueUOM::NONE

uuid::log::Logger Mqtt::logger_{F_(mqtt), uuid::log::Facility::DAEMON};

Expand Down Expand Up @@ -1149,16 +1149,14 @@ void Mqtt::add_ha_uom(JsonObject doc, const uint8_t type, const uint8_t uom, con
case DeviceValueUOM::K:
doc[sc_ha] = F_(measurement);
doc[dc_ha] = "temperature";
if (is_discovery)
doc["ic"] = F_(icondegrees); // icon // TODO check if still needed
// override uom if fahrenheit
doc[uom_ha] = EMSESP::system_.fahrenheit() ? DeviceValue::DeviceValueUOM_s[DeviceValueUOM::FAHRENHEIT] : DeviceValue::DeviceValueUOM_s[uom];
break;
case DeviceValueUOM::PERCENT:
doc[sc_ha] = F_(measurement);
doc[dc_ha] = "power_factor";
if (is_discovery)
doc["ic"] = F_(iconpercent); // icon // TODO check if still needed
doc["ic"] = F_(iconpercent); // icon
break;
case DeviceValueUOM::SECONDS:
case DeviceValueUOM::MINUTES:
Expand Down
14 changes: 11 additions & 3 deletions src/core/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ bool System::command_send(const char * value, const int8_t id) {
return EMSESP::txservice_.send_raw(value); // ignore id
}

// returns last response from MQTT
bool System::command_response(const char * value, const int8_t id, JsonObject output) {
JsonDocument doc;
if (DeserializationError::Ok == deserializeJson(doc, Mqtt::get_response())) {
Expand Down Expand Up @@ -1159,7 +1160,7 @@ bool System::check_restore() {
// returns true if we need a reboot
bool System::check_upgrade(bool factory_settings) {
bool missing_version = true;
std::string settingsVersion{EMSESP_APP_VERSION}; // default setting version
std::string settingsVersion;

if (!factory_settings) {
// fetch current version from settings file
Expand All @@ -1171,6 +1172,8 @@ bool System::check_upgrade(bool factory_settings) {
LOG_WARNING("No version information found");
settingsVersion = "3.5.0"; // this was the last stable version without version info
}
} else {
settingsVersion = EMSESP_APP_VERSION; // use the current version
}

version::Semver200_version settings_version(settingsVersion);
Expand Down Expand Up @@ -2083,11 +2086,16 @@ bool System::uploadFirmwareURL(const char * url) {
}

// read command, e.g. read <deviceID> <type ID> [offset] [length] from console or API
// from Console use quotes so: call system read "<deviceID> <type ID> [offset] [length]"
bool System::readCommand(const char * data) {
if (!data) {
return false;
}

// extract <deviceID> <type ID> [offset] [length] from string
char * p;
char value[11];

// make a copy so we can iterate, max 15 chars (XX XXXX XX XX)
char data_args[15];
strlcpy(data_args, data, sizeof(data_args));
Expand All @@ -2102,7 +2110,7 @@ bool System::readCommand(const char * data) {
strlcpy(value, p, 10); // get string
device_id = (uint8_t)Helpers::hextoint(value); // convert hex to int
if (!EMSESP::valid_device(device_id)) {
LOG_ERROR("Invalid device ID (%d) for read command", device_id);
LOG_ERROR("Invalid device ID (%d) in read command", device_id);
return false; // invalid device
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define EMSESP_APP_VERSION "3.7.2-dev.17"
#define EMSESP_APP_VERSION "3.7.2-dev.18"

0 comments on commit 5b07309

Please sign in to comment.