From 708a2b41dc98492a7c456eeab505590fd74a443f Mon Sep 17 00:00:00 2001 From: Francois BIOT Date: Sat, 3 Dec 2022 23:06:44 +0100 Subject: [PATCH] tinymqtt-test enhancements --- examples/tinymqtt-test/tinymqtt-test.ino | 61 ++++++++++++++++-------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/examples/tinymqtt-test/tinymqtt-test.ino b/examples/tinymqtt-test/tinymqtt-test.ino index 30a929d..75359aa 100644 --- a/examples/tinymqtt-test/tinymqtt-test.ino +++ b/examples/tinymqtt-test/tinymqtt-test.ino @@ -4,12 +4,12 @@ #include // https://github.com/hsaturn/TinyMqtt #include #if defined(ESP8266) -#include + #include #elif defined(ESP32) -#include -#include + #include + #include #else -#error Unsupported platform + #error Unsupported platform #endif #include @@ -21,21 +21,26 @@ auto red = TinyConsole::red; auto white = TinyConsole::white; auto cyan = TinyConsole::cyan; auto yellow = TinyConsole::yellow; - -/** Very complex example - * Console allowing to make any kind of test, - * even some stress tests. - * - * Upload the sketch, the use the terminal. - * Press H for mini help. - * - * tested with mqtt-spy-0.5.4 - * TODO examples of scripts - */ +auto magenta = TinyConsole::magenta; +auto save_cursor = TinyConsole::save_cursor; +auto restore_cursor = TinyConsole::restore_cursor; +auto erase_to_end = TinyConsole::erase_to_end; const char* ssid = ""; const char* password = ""; +/** Very complex example + * Console allowing to make any kind of test, + * even some stress tests. + * + * Upload the sketch, the use the terminal. + * Press H for mini help. + * + * tested with mqtt-spy-0.5.4 + * TODO examples of scripts + */ + + std::string topic="sensor/temperature"; void onPublish(const MqttClient* srce, const Topic& topic, const char* payload, size_t length) @@ -214,7 +219,7 @@ std::map vars; std::set commands = { "auto", "broker", "blink", "client", "connect", - "create", "delete", "help", "interval", + "create", "delete", "debug", "help", "interval", "ls", "ip", "off", "on", "set", "publish", "reset", "subscribe", "unsubscribe", "view", "echo", "every" }; @@ -484,6 +489,10 @@ void eval(std::string& cmd) if (s.length()) convertToCommand(s); if (s.length()==0) {} + else if (compare(s, "debug")) + { + TinyMqtt::debug = getint(cmd); + } else if (compare(s, "delete")) { if (client==nullptr && broker==nullptr) @@ -791,18 +800,29 @@ void eval(std::string& cmd) } else if (compare(s, "ls") or compare(s, "view")) { - Console << "--< " << clients.size() << " client/s. >--" << endl; + bool view = compare(s, "view"); + if (view) + { + Console << save_cursor << magenta; + Console.gotoxy(1,1); + } + Console << "--< " << '/' << clients.size() << " client/s. >--" << erase_to_end << endl; for(auto it: clients) { it.second->dump(" "); } - Console << "--< " << brokers.size() << " brokers/s. >--" << endl; + Console << "--< " << brokers.size() << " brokers/s. >--" << erase_to_end << endl; for(auto it: brokers) { - Console << " +-- '" << it.first.c_str() << "' " << it.second->clientsCount() << " client/s."<< endl; + Console << " +-- '" << it.first.c_str() << "' " << it.second->clientsCount() << " client/s."<< erase_to_end << endl; it.second->dump(" "); } + if (view) + { + Console.bg(white); + Console << erase_to_end << restore_cursor; + } } else if (compare(s, "reset")) ESP.restart(); @@ -872,7 +892,8 @@ void loop() every.next += every.ms; if (ms > every.next and ms > every.underrun) { - Console << "Underrun every #" << e << ", " << (ms - every.next) << "ms late" << endl; + every.next += every.ms; + Console << yellow << "Underrun every #" << e << ", " << (ms - every.next) << "ms late" << endl; every.underrun = ms+5000; } }