mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
Merge branch 'dev' into dev2
This commit is contained in:
@@ -53,10 +53,13 @@ extern "C" {
|
|||||||
#define CONFIG_ASYNC_TCP_TASK_PRIORITY 5
|
#define CONFIG_ASYNC_TCP_TASK_PRIORITY 5
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// stack usage measured: ESP32: ~2.3K, ESP32S3: ~3.5k
|
||||||
#ifndef CONFIG_ASYNC_TCP_STACK_SIZE
|
#ifndef CONFIG_ASYNC_TCP_STACK_SIZE
|
||||||
#define CONFIG_ASYNC_TCP_STACK_SIZE 5120
|
#define CONFIG_ASYNC_TCP_STACK_SIZE 5120
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// maybe enlarge queue to 64 or 128 see https://github.com/emsesp/EMS-ESP32/issues/177
|
||||||
#ifndef CONFIG_ASYNC_TCP_QUEUE
|
#ifndef CONFIG_ASYNC_TCP_QUEUE
|
||||||
#define CONFIG_ASYNC_TCP_QUEUE 32
|
#define CONFIG_ASYNC_TCP_QUEUE 32
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -660,10 +660,9 @@ bool AnalogSensor::get_value_info(JsonObject output, const char * cmd, const int
|
|||||||
|
|
||||||
// this is for a specific sensor
|
// this is for a specific sensor
|
||||||
// make a copy of the string command for parsing, and lowercase it
|
// 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;
|
char * attribute_s = nullptr;
|
||||||
strlcpy(sensor_name, cmd, sizeof(sensor_name));
|
strlcpy(sensor_name, Helpers::toLower(cmd).c_str(), sizeof(sensor_name));
|
||||||
auto sensor_lowercase = Helpers::toLower(sensor_name);
|
|
||||||
|
|
||||||
// check specific attribute to fetch instead of the complete record
|
// check specific attribute to fetch instead of the complete record
|
||||||
char * breakp = strchr(sensor_name, '/');
|
char * breakp = strchr(sensor_name, '/');
|
||||||
@@ -673,7 +672,7 @@ bool AnalogSensor::get_value_info(JsonObject output, const char * cmd, const int
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const auto & sensor : sensors_) {
|
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
|
// add the details
|
||||||
addSensorJson(output, sensor);
|
addSensorJson(output, sensor);
|
||||||
|
|
||||||
|
|||||||
@@ -88,12 +88,12 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
|
|||||||
command_p = p.paths()[1].c_str();
|
command_p = p.paths()[1].c_str();
|
||||||
} else if (num_paths == 3) {
|
} else if (num_paths == 3) {
|
||||||
// concatenate the path into one string as it could be in the format 'hc/XXX'
|
// 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());
|
snprintf(command, sizeof(command), "%s/%s", p.paths()[1].c_str(), p.paths()[2].c_str());
|
||||||
command_p = command;
|
command_p = command;
|
||||||
} else if (num_paths > 3) {
|
} else if (num_paths > 3) {
|
||||||
// concatenate the path into one string as it could be in the format 'hc/XXX/attribute'
|
// 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());
|
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;
|
command_p = command;
|
||||||
} else {
|
} else {
|
||||||
@@ -151,7 +151,7 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
|
|||||||
if (strlen(d)) {
|
if (strlen(d)) {
|
||||||
char * device_end = (char *)strchr(d, '/');
|
char * device_end = (char *)strchr(d, '/');
|
||||||
if (device_end != nullptr) {
|
if (device_end != nullptr) {
|
||||||
char device_s[15] = {'\0'};
|
char device_s[20] = {'\0'};
|
||||||
const char * device_p = device_s;
|
const char * device_p = device_s;
|
||||||
const char * data_p = nullptr;
|
const char * data_p = nullptr;
|
||||||
strlcpy(device_s, d, device_end - d + 1);
|
strlcpy(device_s, d, device_end - d + 1);
|
||||||
@@ -161,7 +161,7 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
|
|||||||
if (data_p == nullptr) {
|
if (data_p == nullptr) {
|
||||||
return CommandRet::INVALID;
|
return CommandRet::INVALID;
|
||||||
}
|
}
|
||||||
char data_s[40];
|
char data_s[COMMAND_MAX_LENGTH];
|
||||||
strlcpy(data_s, Helpers::toLower(data_p).c_str(), 30);
|
strlcpy(data_s, Helpers::toLower(data_p).c_str(), 30);
|
||||||
if (strstr(data_s, "/value") == nullptr) {
|
if (strstr(data_s, "/value") == nullptr) {
|
||||||
strcat(data_s, "/value");
|
strcat(data_s, "/value");
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ using uuid::console::Shell;
|
|||||||
|
|
||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
|
#define COMMAND_MAX_LENGTH 50
|
||||||
|
|
||||||
// mqtt flags for command subscriptions
|
// mqtt flags for command subscriptions
|
||||||
enum CommandFlag : uint8_t {
|
enum CommandFlag : uint8_t {
|
||||||
MQTT_SUB_FLAG_DEFAULT = 0, // 0 no flags set, always subscribe to MQTT
|
MQTT_SUB_FLAG_DEFAULT = 0, // 0 no flags set, always subscribe to MQTT
|
||||||
|
|||||||
12
src/mqtt.cpp
12
src/mqtt.cpp
@@ -1328,13 +1328,13 @@ void Mqtt::add_ha_sections_to_doc(const char * name,
|
|||||||
|
|
||||||
const char * tpl_draft = "{{'online' if %s else 'offline'}}";
|
const char * tpl_draft = "{{'online' if %s else 'offline'}}";
|
||||||
|
|
||||||
// EMS-ESP status check
|
|
||||||
char tpl[150];
|
char tpl[150];
|
||||||
snprintf(tpl, sizeof(tpl), "%s/status", Mqtt::base().c_str());
|
// EMS-ESP status check
|
||||||
avty_json["t"] = tpl;
|
// snprintf(tpl, sizeof(tpl), "%s/status", Mqtt::base().c_str());
|
||||||
snprintf(tpl, sizeof(tpl), tpl_draft, "value == 'online'");
|
// avty_json["t"] = tpl;
|
||||||
avty_json["val_tpl"] = tpl;
|
// snprintf(tpl, sizeof(tpl), tpl_draft, "value == 'online'");
|
||||||
avty.add(avty_json); // returns 0 if no mem
|
// avty_json["val_tpl"] = tpl;
|
||||||
|
// avty.add(avty_json); // returns 0 if no mem
|
||||||
|
|
||||||
// skip conditional Jinja2 templates if not home assistant
|
// skip conditional Jinja2 templates if not home assistant
|
||||||
if (discovery_type() == discoveryType::HOMEASSISTANT) {
|
if (discovery_type() == discoveryType::HOMEASSISTANT) {
|
||||||
|
|||||||
@@ -377,10 +377,9 @@ bool TemperatureSensor::get_value_info(JsonObject output, const char * cmd, cons
|
|||||||
|
|
||||||
// this is for a specific sensor
|
// this is for a specific sensor
|
||||||
// make a copy of the string command for parsing, and lowercase it
|
// 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;
|
char * attribute_s = nullptr;
|
||||||
strlcpy(sensor_name, cmd, sizeof(sensor_name));
|
strlcpy(sensor_name, Helpers::toLower(cmd).c_str(), sizeof(sensor_name));
|
||||||
auto sensor_lowercase = Helpers::toLower(sensor_name);
|
|
||||||
|
|
||||||
// check for a specific attribute to fetch instead of the complete record
|
// check for a specific attribute to fetch instead of the complete record
|
||||||
char * breakp = strchr(sensor_name, '/');
|
char * breakp = strchr(sensor_name, '/');
|
||||||
@@ -391,7 +390,7 @@ bool TemperatureSensor::get_value_info(JsonObject output, const char * cmd, cons
|
|||||||
|
|
||||||
for (const auto & sensor : sensors_) {
|
for (const auto & sensor : sensors_) {
|
||||||
// match custom name or sensor ID
|
// 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
|
// add values
|
||||||
addSensorJson(output, sensor);
|
addSensorJson(output, sensor);
|
||||||
// if we're filtering on an attribute, go find it
|
// if we're filtering on an attribute, go find it
|
||||||
|
|||||||
@@ -278,8 +278,8 @@ bool WebCustomEntityService::get_value_info(JsonObject output, const char * cmd)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
char command_s[30];
|
char command_s[COMMAND_MAX_LENGTH];
|
||||||
strlcpy(command_s, cmd, sizeof(command_s));
|
strlcpy(command_s, Helpers::toLower(cmd).c_str(), sizeof(command_s));
|
||||||
char * attribute_s = nullptr;
|
char * attribute_s = nullptr;
|
||||||
// check specific attribute to fetch instead of the complete record
|
// check specific attribute to fetch instead of the complete record
|
||||||
char * breakp = strchr(command_s, '/');
|
char * breakp = strchr(command_s, '/');
|
||||||
@@ -289,7 +289,7 @@ bool WebCustomEntityService::get_value_info(JsonObject output, const char * cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const auto & entity : *customEntityItems) {
|
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["name"] = entity.name;
|
||||||
output["ram"] = entity.ram;
|
output["ram"] = entity.ram;
|
||||||
output["type"] = entity.value_type == DeviceValueType::BOOL ? "boolean" : entity.value_type == DeviceValueType::STRING ? "string" : F_(number);
|
output["type"] = entity.value_type == DeviceValueType::BOOL ? "boolean" : entity.value_type == DeviceValueType::STRING ? "string" : F_(number);
|
||||||
|
|||||||
@@ -168,8 +168,8 @@ bool WebSchedulerService::get_value_info(JsonObject output, const char * cmd) {
|
|||||||
return (output.size() > 0);
|
return (output.size() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
char command_s[30];
|
char command_s[COMMAND_MAX_LENGTH];
|
||||||
strlcpy(command_s, cmd, sizeof(command_s));
|
strlcpy(command_s, Helpers::toLower(cmd).c_str(), sizeof(command_s));
|
||||||
char * attribute_s = nullptr;
|
char * attribute_s = nullptr;
|
||||||
|
|
||||||
// check specific attribute to fetch instead of the complete record
|
// check specific attribute to fetch instead of the complete record
|
||||||
@@ -180,7 +180,7 @@ bool WebSchedulerService::get_value_info(JsonObject output, const char * cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const ScheduleItem & scheduleItem : *scheduleItems_) {
|
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["name"] = scheduleItem.name;
|
||||||
output["type"] = "boolean";
|
output["type"] = "boolean";
|
||||||
if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) {
|
if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) {
|
||||||
|
|||||||
Reference in New Issue
Block a user