Better debugging code
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
// vim: ts=2 sw=2 expandtab smartindent
|
||||
#define TINY_MQTT_DEBUG
|
||||
#include <TinyConsole.h>
|
||||
#include <TinyMqtt.h> // https://github.com/hsaturn/TinyMqtt
|
||||
#include <TinyStreaming.h>
|
||||
@@ -410,7 +409,11 @@ void eval(std::string& cmd)
|
||||
{}
|
||||
else if (compare(s, "debug"))
|
||||
{
|
||||
#if TINY_MQTT_DEBUG
|
||||
TinyMqtt::debug = getint(cmd);
|
||||
#else
|
||||
Console << red << "TinyMqtt not compiled in debug" << endl;
|
||||
#endif
|
||||
}
|
||||
else if (compare(s, "list"))
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "TinyMqtt.h"
|
||||
#include <sstream>
|
||||
|
||||
#ifdef TINY_MQTT_DEBUG
|
||||
#if TINY_MQTT_DEBUG
|
||||
static auto cyan = TinyConsole::cyan;
|
||||
static auto white = TinyConsole::white;
|
||||
static auto red = TinyConsole::red;
|
||||
@@ -221,7 +221,7 @@ MqttError MqttBroker::publish(const MqttClient* source, const Topic& topic, Mqtt
|
||||
for(auto client: clients)
|
||||
{
|
||||
i++;
|
||||
#ifdef TINY_MQTT_DEBUG
|
||||
#if TINY_MQTT_DEBUG
|
||||
Console << __LINE__ << " broker:" << (broker && broker->connected() ? "linked" : "alone") <<
|
||||
" srce=" << (source->isLocal() ? "loc" : "rem") << " clt#" << i << ", local=" << client->isLocal() << ", con=" << client->connected() << endl;
|
||||
#endif
|
||||
@@ -242,7 +242,7 @@ MqttError MqttBroker::publish(const MqttClient* source, const Topic& topic, Mqtt
|
||||
{
|
||||
doit = true;
|
||||
}
|
||||
#ifdef TINY_MQTT_DEBUG
|
||||
#if TINY_MQTT_DEBUG
|
||||
Console << ", doit=" << doit << ' ';
|
||||
#endif
|
||||
|
||||
@@ -426,7 +426,7 @@ MqttError MqttClient::sendTopic(const Topic& topic, MqttMessage::Type type, uint
|
||||
|
||||
void MqttClient::processMessage(MqttMessage* mesg)
|
||||
{
|
||||
#ifdef TINY_MQTT_DEBUG
|
||||
#if TINY_MQTT_DEBUG
|
||||
mesg->hexdump("Incoming");
|
||||
#endif
|
||||
auto header = mesg->getVHeader();
|
||||
@@ -487,7 +487,7 @@ void MqttClient::processMessage(MqttMessage* mesg)
|
||||
payload += len;
|
||||
}
|
||||
|
||||
#ifdef TINY_MQTT_DEBUG
|
||||
#if TINY_MQTT_DEBUG
|
||||
Console << yellow << "Client " << clientId << " connected : keep alive=" << keep_alive << '.' << white << endl;
|
||||
#endif
|
||||
bclose = false;
|
||||
@@ -585,7 +585,7 @@ void MqttClient::processMessage(MqttMessage* mesg)
|
||||
break;
|
||||
|
||||
case MqttMessage::Type::Publish:
|
||||
#ifdef TINY_MQTT_DEBUG
|
||||
#if TINY_MQTT_DEBUG
|
||||
Console << "publish " << mqtt_connected << '/' << (long) client << endl;
|
||||
#endif
|
||||
if (mqtt_connected or client == nullptr)
|
||||
@@ -595,7 +595,7 @@ void MqttClient::processMessage(MqttMessage* mesg)
|
||||
mesg->getString(payload, len);
|
||||
Topic published(payload, len);
|
||||
payload += len;
|
||||
#ifdef TINY_MQTT_DEBUG
|
||||
#if TINY_MQTT_DEBUG
|
||||
Console << "Received Publish (" << published.str().c_str() << ") size=" << (int)len << endl;
|
||||
#endif
|
||||
// << '(' << std::string(payload, len).c_str() << ')' << " msglen=" << mesg->length() << endl;
|
||||
@@ -606,7 +606,7 @@ void MqttClient::processMessage(MqttMessage* mesg)
|
||||
|
||||
if (local_broker==nullptr or client==nullptr) // internal MqttClient receives publish
|
||||
{
|
||||
#ifdef TINY_MQTT_DEBUG
|
||||
#if TINY_MQTT_DEBUG
|
||||
if (TinyMqtt::debug >= 2)
|
||||
{
|
||||
Console << (isSubscribedTo(published) ? "not" : "") << " subscribed.\n";
|
||||
@@ -641,7 +641,7 @@ void MqttClient::processMessage(MqttMessage* mesg)
|
||||
};
|
||||
if (bclose)
|
||||
{
|
||||
#ifdef TINY_MQTT_DEBUG
|
||||
#if TINY_MQTT_DEBUG
|
||||
Console << red << "*************** Error msg 0x" << _HEX(mesg->type());
|
||||
mesg->hexdump("-------ERROR ------");
|
||||
dump();
|
||||
@@ -750,7 +750,7 @@ MqttError MqttClient::publishIfSubscribed(const Topic& topic, MqttMessage& msg)
|
||||
{
|
||||
processMessage(&msg);
|
||||
|
||||
#ifdef TINY_MQTT_DEBUG
|
||||
#if TINY_MQTT_DEBUG
|
||||
Console << "Should call the callback ?\n";
|
||||
#endif
|
||||
// callback(this, topic, nullptr, 0); // TODO Payload
|
||||
@@ -819,7 +819,7 @@ void MqttMessage::incoming(char in_byte)
|
||||
break;
|
||||
case Complete:
|
||||
default:
|
||||
#ifdef TINY_MQTT_DEBUG
|
||||
#if TINY_MQTT_DEBUG
|
||||
Console << red << "Spurious " << _HEX(in_byte) << white << endl;
|
||||
hexdump("spurious");
|
||||
#endif
|
||||
@@ -888,7 +888,7 @@ MqttError MqttMessage::sendTo(MqttClient* client)
|
||||
void MqttMessage::hexdump(const char* prefix) const
|
||||
{
|
||||
(void)prefix;
|
||||
#ifdef TINY_MQTT_DEBUG
|
||||
#if TINY_MQTT_DEBUG
|
||||
if (TinyMqtt::debug<2) return;
|
||||
static std::map<Type, std::string> tts={
|
||||
{ Connect, "Connect" },
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// vim: ts=2 sw=2 expandtab
|
||||
#pragma once
|
||||
#define TINY_MQTT_DEBUG 0
|
||||
|
||||
// TODO Should add a AUnit with both TINY_MQTT_ASYNC and not TINY_MQTT_ASYNC
|
||||
// #define TINY_MQTT_ASYNC // Uncomment this to use ESPAsyncTCP instead of normal cnx
|
||||
@@ -34,7 +35,7 @@
|
||||
#include <string>
|
||||
#include "StringIndexer.h"
|
||||
|
||||
#ifdef TINY_MQTT_DEBUG
|
||||
#if TINY_MQTT_DEBUG
|
||||
#include <TinyStreaming.h>
|
||||
#include <TinyConsole.h> // https://github.com/hsaturn/TinyConsole
|
||||
struct TinyMqtt
|
||||
@@ -202,7 +203,7 @@ class MqttClient
|
||||
void setCallback(CallBack fun)
|
||||
{
|
||||
callback=fun;
|
||||
#ifdef TINY_MQTT_DEBUG
|
||||
#if TINY_MQTT_DEBUG
|
||||
Console << TinyConsole::magenta << "Callback set to " << (long)fun << TinyConsole::white << endl;
|
||||
if (callback) callback(this, "test/topic", "value", 5);
|
||||
#endif
|
||||
@@ -226,7 +227,7 @@ class MqttClient
|
||||
void dump(std::string indent="")
|
||||
{
|
||||
(void)indent;
|
||||
#ifdef TINY_MQTT_DEBUG
|
||||
#if TINY_MQTT_DEBUG
|
||||
uint32_t ms=millis();
|
||||
Console << indent << "+-- " << '\'' << clientId.c_str() << "' " << (connected() ? " ON " : " OFF");
|
||||
Console << ", alive=" << alive << '/' << ms << ", ka=" << keep_alive << ' ';
|
||||
|
||||
Reference in New Issue
Block a user