Skip to content

Commit

Permalink
Merge branch 'dev' into dev2
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Feb 27, 2024
2 parents a359618 + 8257986 commit d8b77fc
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 24 deletions.
3 changes: 3 additions & 0 deletions lib/AsyncTCP/src/AsyncTCP.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ extern "C" {
#define CONFIG_ASYNC_TCP_TASK_PRIORITY 5
#endif

// stack usage measured: ESP32: ~2.3K, ESP32S3: ~3.5k
#ifndef CONFIG_ASYNC_TCP_STACK_SIZE
#define CONFIG_ASYNC_TCP_STACK_SIZE 5120
#endif


// maybe enlarge queue to 64 or 128 see https://github.com/emsesp/EMS-ESP32/issues/177
#ifndef CONFIG_ASYNC_TCP_QUEUE
#define CONFIG_ASYNC_TCP_QUEUE 32
#endif
Expand Down
7 changes: 3 additions & 4 deletions src/analogsensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,9 @@ bool AnalogSensor::get_value_info(JsonObject output, const char * cmd, const int

// this is for a specific sensor
// make a copy of the string command for parsing, and lowercase it
char sensor_name[30] = {'\0'};
char sensor_name[COMMAND_MAX_LENGTH] = {'\0'};
char * attribute_s = nullptr;
strlcpy(sensor_name, cmd, sizeof(sensor_name));
auto sensor_lowercase = Helpers::toLower(sensor_name);
strlcpy(sensor_name, Helpers::toLower(cmd).c_str(), sizeof(sensor_name));

// check specific attribute to fetch instead of the complete record
char * breakp = strchr(sensor_name, '/');
Expand All @@ -673,7 +672,7 @@ bool AnalogSensor::get_value_info(JsonObject output, const char * cmd, const int
}

for (const auto & sensor : sensors_) {
if (sensor_lowercase == Helpers::toLower(sensor.name().c_str()) || Helpers::atoint(sensor_name) == sensor.gpio()) {
if (sensor_name == Helpers::toLower(sensor.name()) || Helpers::atoint(sensor_name) == sensor.gpio()) {
// add the details
addSensorJson(output, sensor);

Expand Down
8 changes: 4 additions & 4 deletions src/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
command_p = p.paths()[1].c_str();
} else if (num_paths == 3) {
// concatenate the path into one string as it could be in the format 'hc/XXX'
char command[50];
char command[COMMAND_MAX_LENGTH];
snprintf(command, sizeof(command), "%s/%s", p.paths()[1].c_str(), p.paths()[2].c_str());
command_p = command;
} else if (num_paths > 3) {
// concatenate the path into one string as it could be in the format 'hc/XXX/attribute'
char command[50];
char command[COMMAND_MAX_LENGTH];
snprintf(command, sizeof(command), "%s/%s/%s", p.paths()[1].c_str(), p.paths()[2].c_str(), p.paths()[3].c_str());
command_p = command;
} else {
Expand Down Expand Up @@ -151,7 +151,7 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
if (strlen(d)) {
char * device_end = (char *)strchr(d, '/');
if (device_end != nullptr) {
char device_s[15] = {'\0'};
char device_s[20] = {'\0'};
const char * device_p = device_s;
const char * data_p = nullptr;
strlcpy(device_s, d, device_end - d + 1);
Expand All @@ -161,7 +161,7 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
if (data_p == nullptr) {
return CommandRet::INVALID;
}
char data_s[40];
char data_s[COMMAND_MAX_LENGTH];
strlcpy(data_s, Helpers::toLower(data_p).c_str(), 30);
if (strstr(data_s, "/value") == nullptr) {
strcat(data_s, "/value");
Expand Down
2 changes: 2 additions & 0 deletions src/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ using uuid::console::Shell;

namespace emsesp {

#define COMMAND_MAX_LENGTH 50

// mqtt flags for command subscriptions
enum CommandFlag : uint8_t {
MQTT_SUB_FLAG_DEFAULT = 0, // 0 no flags set, always subscribe to MQTT
Expand Down
12 changes: 6 additions & 6 deletions src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1328,13 +1328,13 @@ void Mqtt::add_ha_sections_to_doc(const char * name,

const char * tpl_draft = "{{'online' if %s else 'offline'}}";

// EMS-ESP status check
char tpl[150];
snprintf(tpl, sizeof(tpl), "%s/status", Mqtt::base().c_str());
avty_json["t"] = tpl;
snprintf(tpl, sizeof(tpl), tpl_draft, "value == 'online'");
avty_json["val_tpl"] = tpl;
avty.add(avty_json); // returns 0 if no mem
// EMS-ESP status check
// snprintf(tpl, sizeof(tpl), "%s/status", Mqtt::base().c_str());
// avty_json["t"] = tpl;
// snprintf(tpl, sizeof(tpl), tpl_draft, "value == 'online'");
// avty_json["val_tpl"] = tpl;
// avty.add(avty_json); // returns 0 if no mem

// skip conditional Jinja2 templates if not home assistant
if (discovery_type() == discoveryType::HOMEASSISTANT) {
Expand Down
7 changes: 3 additions & 4 deletions src/temperaturesensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,9 @@ bool TemperatureSensor::get_value_info(JsonObject output, const char * cmd, cons

// this is for a specific sensor
// make a copy of the string command for parsing, and lowercase it
char sensor_name[30] = {'\0'};
char sensor_name[COMMAND_MAX_LENGTH] = {'\0'};
char * attribute_s = nullptr;
strlcpy(sensor_name, cmd, sizeof(sensor_name));
auto sensor_lowercase = Helpers::toLower(sensor_name);
strlcpy(sensor_name, Helpers::toLower(cmd).c_str(), sizeof(sensor_name));

// check for a specific attribute to fetch instead of the complete record
char * breakp = strchr(sensor_name, '/');
Expand All @@ -391,7 +390,7 @@ bool TemperatureSensor::get_value_info(JsonObject output, const char * cmd, cons

for (const auto & sensor : sensors_) {
// match custom name or sensor ID
if (sensor_lowercase == Helpers::toLower(sensor.name().c_str()) || sensor_lowercase == Helpers::toLower(sensor.id().c_str())) {
if (sensor_name == Helpers::toLower(sensor.name()) || sensor_name == Helpers::toLower(sensor.id())) {
// add values
addSensorJson(output, sensor);
// if we're filtering on an attribute, go find it
Expand Down
6 changes: 3 additions & 3 deletions src/web/WebCustomEntityService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ bool WebCustomEntityService::get_value_info(JsonObject output, const char * cmd)
return true;
}

char command_s[30];
strlcpy(command_s, cmd, sizeof(command_s));
char command_s[COMMAND_MAX_LENGTH];
strlcpy(command_s, Helpers::toLower(cmd).c_str(), sizeof(command_s));
char * attribute_s = nullptr;
// check specific attribute to fetch instead of the complete record
char * breakp = strchr(command_s, '/');
Expand All @@ -289,7 +289,7 @@ bool WebCustomEntityService::get_value_info(JsonObject output, const char * cmd)
}

for (const auto & entity : *customEntityItems) {
if (Helpers::toLower(entity.name) == Helpers::toLower(command_s)) {
if (Helpers::toLower(entity.name) == command_s) {
output["name"] = entity.name;
output["ram"] = entity.ram;
output["type"] = entity.value_type == DeviceValueType::BOOL ? "boolean" : entity.value_type == DeviceValueType::STRING ? "string" : F_(number);
Expand Down
6 changes: 3 additions & 3 deletions src/web/WebSchedulerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ bool WebSchedulerService::get_value_info(JsonObject output, const char * cmd) {
return (output.size() > 0);
}

char command_s[30];
strlcpy(command_s, cmd, sizeof(command_s));
char command_s[COMMAND_MAX_LENGTH];
strlcpy(command_s, Helpers::toLower(cmd).c_str(), sizeof(command_s));
char * attribute_s = nullptr;

// check specific attribute to fetch instead of the complete record
Expand All @@ -180,7 +180,7 @@ bool WebSchedulerService::get_value_info(JsonObject output, const char * cmd) {
}

for (const ScheduleItem & scheduleItem : *scheduleItems_) {
if (Helpers::toLower(scheduleItem.name) == Helpers::toLower(command_s)) {
if (Helpers::toLower(scheduleItem.name) == command_s) {
output["name"] = scheduleItem.name;
output["type"] = "boolean";
if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) {
Expand Down

0 comments on commit d8b77fc

Please sign in to comment.