tinymqtt-test enhancements

This commit is contained in:
Francois BIOT
2022-12-03 23:06:44 +01:00
parent c4edfb6e40
commit 708a2b41dc

View File

@@ -4,12 +4,12 @@
#include <TinyMqtt.h> // https://github.com/hsaturn/TinyMqtt #include <TinyMqtt.h> // https://github.com/hsaturn/TinyMqtt
#include <MqttStreaming.h> #include <MqttStreaming.h>
#if defined(ESP8266) #if defined(ESP8266)
#include <ESP8266mDNS.h> #include <ESP8266mDNS.h>
#elif defined(ESP32) #elif defined(ESP32)
#include <WiFi.h> #include <WiFi.h>
#include <ESPmDNS.h> #include <ESPmDNS.h>
#else #else
#error Unsupported platform #error Unsupported platform
#endif #endif
#include <sstream> #include <sstream>
@@ -21,21 +21,26 @@ auto red = TinyConsole::red;
auto white = TinyConsole::white; auto white = TinyConsole::white;
auto cyan = TinyConsole::cyan; auto cyan = TinyConsole::cyan;
auto yellow = TinyConsole::yellow; auto yellow = TinyConsole::yellow;
auto magenta = TinyConsole::magenta;
/** Very complex example auto save_cursor = TinyConsole::save_cursor;
* Console allowing to make any kind of test, auto restore_cursor = TinyConsole::restore_cursor;
* even some stress tests. auto erase_to_end = TinyConsole::erase_to_end;
*
* Upload the sketch, the use the terminal.
* Press H for mini help.
*
* tested with mqtt-spy-0.5.4
* TODO examples of scripts
*/
const char* ssid = ""; const char* ssid = "";
const char* password = ""; 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"; std::string topic="sensor/temperature";
void onPublish(const MqttClient* srce, const Topic& topic, const char* payload, size_t length) void onPublish(const MqttClient* srce, const Topic& topic, const char* payload, size_t length)
@@ -214,7 +219,7 @@ std::map<std::string, std::string> vars;
std::set<std::string> commands = { std::set<std::string> commands = {
"auto", "broker", "blink", "client", "connect", "auto", "broker", "blink", "client", "connect",
"create", "delete", "help", "interval", "create", "delete", "debug", "help", "interval",
"ls", "ip", "off", "on", "set", "ls", "ip", "off", "on", "set",
"publish", "reset", "subscribe", "unsubscribe", "view", "echo", "every" "publish", "reset", "subscribe", "unsubscribe", "view", "echo", "every"
}; };
@@ -484,6 +489,10 @@ void eval(std::string& cmd)
if (s.length()) convertToCommand(s); if (s.length()) convertToCommand(s);
if (s.length()==0) if (s.length()==0)
{} {}
else if (compare(s, "debug"))
{
TinyMqtt::debug = getint(cmd);
}
else if (compare(s, "delete")) else if (compare(s, "delete"))
{ {
if (client==nullptr && broker==nullptr) if (client==nullptr && broker==nullptr)
@@ -791,18 +800,29 @@ void eval(std::string& cmd)
} }
else if (compare(s, "ls") or compare(s, "view")) 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) for(auto it: clients)
{ {
it.second->dump(" "); it.second->dump(" ");
} }
Console << "--< " << brokers.size() << " brokers/s. >--" << endl; Console << "--< " << brokers.size() << " brokers/s. >--" << erase_to_end << endl;
for(auto it: brokers) 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(" "); it.second->dump(" ");
} }
if (view)
{
Console.bg(white);
Console << erase_to_end << restore_cursor;
}
} }
else if (compare(s, "reset")) else if (compare(s, "reset"))
ESP.restart(); ESP.restart();
@@ -872,7 +892,8 @@ void loop()
every.next += every.ms; every.next += every.ms;
if (ms > every.next and ms > every.underrun) 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; every.underrun = ms+5000;
} }
} }