mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
fix for HA topics with invalid command formats - #728
This commit is contained in:
@@ -414,6 +414,7 @@ void Thermostat::register_mqtt_ha_config_hc(uint8_t hc_num) {
|
||||
}
|
||||
|
||||
// for HA specifically when receiving over MQTT in the thermostat topic
|
||||
// e.g. thermostat_hc1
|
||||
// it could be either a 'mode' or a float value for a temperature. we try brute force both and see which one works.
|
||||
// return true if it parses the message correctly
|
||||
bool Thermostat::thermostat_ha_cmd(const char * message, uint8_t hc_num) {
|
||||
|
||||
11
src/mqtt.cpp
11
src/mqtt.cpp
@@ -249,14 +249,17 @@ void Mqtt::on_message(const char * fulltopic, const char * payload, size_t len)
|
||||
// see if we have this topic in our subscription list, then call its callback handler
|
||||
for (const auto & mf : mqtt_subfunctions_) {
|
||||
if (strcmp(topic, mf.topic_.c_str()) == 0) {
|
||||
// if we have call back function then call it
|
||||
// otherwise proceed as process as a command
|
||||
if (mf.mqtt_subfunction_) {
|
||||
// matching function, call it. If it returns true keep quit
|
||||
if ((mf.mqtt_subfunction_)(message)) {
|
||||
return; // function executed successfully
|
||||
if (!(mf.mqtt_subfunction_)(message)) {
|
||||
LOG_ERROR(F("MQTT error: invalid payload %s for this topic %s"), message, topic);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// empty function. It's a command then. Find the command from the json and call it directly.
|
||||
// It's a command then with the payload being JSON like {"cmd":"<cmd>", "data":<data>, "id":<n>}
|
||||
// Find the command from the json and call it directly
|
||||
StaticJsonDocument<EMSESP_JSON_SIZE_SMALL> doc;
|
||||
DeserializationError error = deserializeJson(doc, message);
|
||||
if (error) {
|
||||
|
||||
@@ -421,6 +421,9 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) {
|
||||
EMSESP::mqtt_.incoming("ems-esp/thermostat_hc1", "heat");
|
||||
EMSESP::mqtt_.incoming("ems-esp/thermostat_hc2", "28.8");
|
||||
EMSESP::mqtt_.incoming("ems-esp/thermostat", "{\"cmd\":\"temp\",\"id\":2,\"data\":22}");
|
||||
|
||||
EMSESP::mqtt_.incoming("ems-esp/thermostat_hc3", "{\"cmd\":\"offsettemp\",\"data\":-3}");
|
||||
EMSESP::mqtt_.incoming("ems-esp/thermostat_hc3", "{\"cmd\":\"temp\",\"data\":-3}");
|
||||
}
|
||||
|
||||
if (command == "tc100") {
|
||||
|
||||
@@ -25,13 +25,13 @@
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
// #define EMSESP_TEST_DEFAULT "thermostat"
|
||||
#define EMSESP_TEST_DEFAULT "thermostat"
|
||||
// #define EMSESP_TEST_DEFAULT "solar"
|
||||
// #define EMSESP_TEST_DEFAULT "mixer"
|
||||
// #define EMSESP_TEST_DEFAULT "web"
|
||||
// #define EMSESP_TEST_DEFAULT "general"
|
||||
// #define EMSESP_TEST_DEFAULT "boiler"
|
||||
#define EMSESP_TEST_DEFAULT "mqtt2"
|
||||
// #define EMSESP_TEST_DEFAULT "mqtt2"
|
||||
|
||||
class Test {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user