From e00e31de338ee23da8960115b3564a64c120054b Mon Sep 17 00:00:00 2001 From: hsaturn Date: Wed, 28 Apr 2021 18:51:01 +0200 Subject: [PATCH] Fix build in Esp8266 mode Modify dump() functions --- examples/tinymqtt-test/tinymqtt-test.ino | 7 +++-- src/TinyMqtt.h | 34 +++++++++++------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/examples/tinymqtt-test/tinymqtt-test.ino b/examples/tinymqtt-test/tinymqtt-test.ino index d4f25b7..814004f 100644 --- a/examples/tinymqtt-test/tinymqtt-test.ino +++ b/examples/tinymqtt-test/tinymqtt-test.ino @@ -7,7 +7,6 @@ #else #error Unsupported platform #endif -#include #include #include @@ -630,14 +629,14 @@ void eval(std::string& cmd) Serial << "--< " << clients.size() << " client/s. >--" << endl; for(auto it: clients) { - Serial << " "; it.second->dump(); + it.second->dump(" "); } Serial << "--< " << brokers.size() << " brokers/s. >--" << endl; for(auto it: brokers) { - Serial << " ==[ Broker: " << it.first.c_str() << " ]== "; - it.second->dump(); + Serial << " +-- '" << it.first.c_str() << "' " << it.second->clientsCount() << " client/s."<< endl; + it.second->dump(" "); } } else if (compare(s, "reset")) diff --git a/src/TinyMqtt.h b/src/TinyMqtt.h index 37bedf1..e826fdf 100644 --- a/src/TinyMqtt.h +++ b/src/TinyMqtt.h @@ -189,23 +189,25 @@ class MqttClient // TODO seems to be useless bool isLocal() const { return client == nullptr; } - void dump() + void dump(std::string indent="") { uint32_t ms=millis(); - Serial << "MqttClient (" << clientId.c_str() << ") " << (connected() ? " ON " : " OFF"); - Serial << ", alive=" << alive << '/' << ms << ", ka=" << keep_alive; + Serial << indent << "+-- " << '\'' << clientId.c_str() << "' " << (connected() ? " ON " : " OFF"); + Serial << ", alive=" << alive << '/' << ms << ", ka=" << keep_alive << ' '; Serial << (client && client->connected() ? "" : "dis") << "connected"; - message.hexdump("entrant msg"); - bool c=false; - Serial << " ["; - for(auto s: subscriptions) + if (subscriptions.size()) { - Serial << (c?", ": "")<< s.str().c_str(); - c=true; + bool c = false; + Serial << " ["; + for(auto s: subscriptions) + { + if (c) Serial << ", "; + Serial << s.str().c_str(); + c=true; + } + Serial << ']'; } - - - Serial << "]" << endl; + Serial << endl; } /** Count the number of messages that have been sent **/ @@ -265,14 +267,10 @@ class MqttBroker size_t clientsCount() const { return clients.size(); } - void dump() + void dump(std::string indent="") { - Serial << clients.size() << " client/s" << endl; for(auto client: clients) - { - Serial << " "; - client->dump(); - } + client->dump(indent); } private: