From 7521ce6ad36cc5a96dda456569dffdcd666a5f9f Mon Sep 17 00:00:00 2001 From: proddy Date: Sun, 28 Feb 2021 13:54:27 +0100 Subject: [PATCH] added test for large MQTT packages --- src/test/test.cpp | 23 +++++++++++++++++++++++ src/test/test.h | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/test/test.cpp b/src/test/test.cpp index 968b1c879..283c6ad9c 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -711,6 +711,29 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) { shell.invoke_command("call system pin 1 true"); } + if (command == "mqtt2") { + shell.printfln(F("Testing MQTT large payloads...")); + + DynamicJsonDocument doc(EMSESP_JSON_SIZE_XXLARGE_DYN); + + char key[6]; + char value[6]; + + // fit it up, to its limit of the Json buffer (which is about 169 records) + for (uint8_t i = 0; i < 200; i++) { + snprintf_P(key, 7, PSTR("key%03d"), i); + snprintf_P(value, 7, PSTR("val%03d"), i); + doc[key] = value; + } + doc.shrinkToFit(); + JsonObject jo = doc.as(); + shell.printfln(F("Size of JSON payload = %d"), jo.memoryUsage()); + shell.printfln(F("Length of JSON payload = %d"), measureJson(jo)); + + Mqtt::publish("test", jo); + Mqtt::show_mqtt(shell); // show queue + } + if (command == "mqtt") { shell.printfln(F("Testing MQTT...")); diff --git a/src/test/test.h b/src/test/test.h index 6abad1c1a..f2a7f12b6 100644 --- a/src/test/test.h +++ b/src/test/test.h @@ -30,7 +30,8 @@ namespace emsesp { // #define EMSESP_TEST_DEFAULT "mixer" // #define EMSESP_TEST_DEFAULT "web" // #define EMSESP_TEST_DEFAULT "general" -#define EMSESP_TEST_DEFAULT "boiler" +// #define EMSESP_TEST_DEFAULT "boiler" +#define EMSESP_TEST_DEFAULT "mqtt2" class Test { public: