mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
fixes #207 - allow both data and value as MQTT keys
This commit is contained in:
@@ -260,11 +260,11 @@ void Mqtt::on_message(const char * topic, const char * payload, size_t len) {
|
||||
StaticJsonDocument<EMSESP_JSON_SIZE_LARGE_DYN> output_doc;
|
||||
JsonObject input, output;
|
||||
|
||||
// convert payload into a json doc, if it's not empty
|
||||
// if the payload is a single parameter (not JSON) create a JSON with the key 'value'
|
||||
// convert payload into a json doc
|
||||
// if the payload doesn't not contain the key 'value' or 'data', treat the whole payload as the 'value'
|
||||
if (len != 0) {
|
||||
DeserializationError error = deserializeJson(input_doc, message);
|
||||
if (!input_doc.containsKey("value") || error) {
|
||||
if ((!input_doc.containsKey("value") && !input_doc.containsKey("data")) || error) {
|
||||
input_doc.clear();
|
||||
input_doc["value"] = (const char *)message; // always a string
|
||||
}
|
||||
|
||||
@@ -671,6 +671,8 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) {
|
||||
EMSESP::mqtt_.incoming("ems-esp/boiler/wwseltemp", "59");
|
||||
EMSESP::mqtt_.incoming("ems-esp/boiler/wwseltemp");
|
||||
|
||||
EMSESP::mqtt_.incoming("ems-esp/thermostat", "{\"cmd\":\"mode\",\"data\":\"heat\",\"id\":1}");
|
||||
|
||||
// MQTT bad tests
|
||||
EMSESP::mqtt_.incoming("ems-esp/thermostate/mode", "auto"); // unknown device
|
||||
EMSESP::mqtt_.incoming("ems-esp/thermostat/modee", "auto"); // unknown command
|
||||
@@ -757,7 +759,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) {
|
||||
request.url("/rest/writeValue");
|
||||
EMSESP::webDataService.write_value(&request, json);
|
||||
|
||||
emsesp::EMSESP::logger().notice("*");
|
||||
// emsesp::EMSESP::logger().notice("*");
|
||||
|
||||
// should fail
|
||||
char data8[] = "{}";
|
||||
|
||||
@@ -39,10 +39,9 @@ namespace emsesp {
|
||||
// #define EMSESP_DEBUG_DEFAULT "shower_alert"
|
||||
// #define EMSESP_DEBUG_DEFAULT "310"
|
||||
// #define EMSESP_DEBUG_DEFAULT "render"
|
||||
// #define EMSESP_DEBUG_DEFAULT "api"
|
||||
#define EMSESP_DEBUG_DEFAULT "api"
|
||||
// #define EMSESP_DEBUG_DEFAULT "crash"
|
||||
#define EMSESP_DEBUG_DEFAULT "dv"
|
||||
|
||||
// #define EMSESP_DEBUG_DEFAULT "dv"
|
||||
|
||||
class Test {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user