From 5a3e9bd90e605beb39b0e7a34e9a4e4c2db8cf78 Mon Sep 17 00:00:00 2001 From: Francois BIOT Date: Sat, 3 Dec 2022 20:34:59 +0100 Subject: [PATCH] Fix reboot bugs due to TinyConsole --- examples/simple-broker/simple-broker.ino | 16 ++++++++-------- examples/tinymqtt-test/tinymqtt-test.ino | 9 +++++---- library.properties | 2 +- src/TinyMqtt.cpp | 11 ++++++----- src/TinyMqtt.h | 1 + 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/examples/simple-broker/simple-broker.ino b/examples/simple-broker/simple-broker.ino index 80b0721..bf88923 100644 --- a/examples/simple-broker/simple-broker.ino +++ b/examples/simple-broker/simple-broker.ino @@ -7,7 +7,7 @@ MqttBroker broker(PORT); * * +-----------------------------+ * | ESP | - * | +--------+ | + * | +--------+ | * | | broker | | 1883 <--- External client/s * | +--------+ | * | | @@ -15,30 +15,30 @@ MqttBroker broker(PORT); * * Your ESP will become a MqttBroker. * You can test it with any client such as mqtt-spy for example - * + * */ const char* ssid = ""; const char* password = ""; -void setup() +void setup() { Serial.begin(115200); if (strlen(ssid)==0) - Serial << "****** PLEASE MODIFY ssid/password *************" << endl; + Console << TinyConsole::red << "****** PLEASE MODIFY ssid/password *************" << endl; WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); - - while (WiFi.status() != WL_CONNECTED) { + + while (WiFi.status() != WL_CONNECTED) { Serial << '.'; delay(500); } - Serial << "Connected to " << ssid << "IP address: " << WiFi.localIP() << endl; + Connect << TinyConsole::green << "Connected to " << ssid << "IP address: " << WiFi.localIP() << endl; broker.begin(); - Serial << "Broker ready : " << WiFi.localIP() << " on port " << PORT << endl; + Console << "Broker ready : " << WiFi.localIP() << " on port " << PORT << endl; } void loop() diff --git a/examples/tinymqtt-test/tinymqtt-test.ino b/examples/tinymqtt-test/tinymqtt-test.ino index 64c1993..c9ed61c 100644 --- a/examples/tinymqtt-test/tinymqtt-test.ino +++ b/examples/tinymqtt-test/tinymqtt-test.ino @@ -20,6 +20,7 @@ auto green = TinyConsole::green; 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, @@ -420,9 +421,8 @@ struct Every else Console << red << "disabled"; - Console << white << auto mill=millis(); - Console << ms << "ms [" << cmd << "] next in "; + Console << white << ms << "ms [" << cmd << "] next in "; if (mill > next) Console << "now"; else @@ -440,6 +440,7 @@ std::vector everies; void onCommand(const std::string& command) { + Console << endl; std::string cmd=command; if (cmd.substr(0,3)!="set") replaceVars(cmd); eval(cmd); @@ -497,7 +498,7 @@ void eval(std::string& cmd) broker = brokers[s]; } else - Console << red << "Unable to find (" << s.c_str() << ")" << << white << endl; + Console << red << "Unable to find (" << s.c_str() << ")" << white << endl; } if (client) { @@ -910,5 +911,5 @@ void loop() it.second->loop(); Automatic::loop(); - Console::loop(); + Console.loop(); } diff --git a/library.properties b/library.properties index 4b5164c..b817cb7 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TinyMqtt -version=0.9.5 +version=0.9.6 author=Francois BIOT, HSaturn, maintainer=Francois BIOT, HSaturn, sentence=A tiny broker and client library for MQTT messaging. diff --git a/src/TinyMqtt.cpp b/src/TinyMqtt.cpp index 739202e..6cae29c 100644 --- a/src/TinyMqtt.cpp +++ b/src/TinyMqtt.cpp @@ -1,3 +1,4 @@ +// vim: ts=2 sw=2 expandtab #include "TinyMqtt.h" #include @@ -589,9 +590,9 @@ void MqttClient::processMessage(MqttMessage* mesg) mesg->getString(payload, len); Topic published(payload, len); payload += len; - #ifdef TINY_MQTT_DEBUG - Console << "Received Publish (" << published.str().c_str() << ") size=" << (int)len << endl; - #endif + #ifdef 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; if (qos) payload+=2; // ignore packet identifier if any len=mesg->end()-payload; @@ -898,13 +899,13 @@ void MqttMessage::hexdump(const char* prefix) const Type typ=static_cast(buffer[0] & 0xF0); if (tts.find(typ) != tts.end()) t=tts[typ]; - Console.fg(cyan); + Console.fg(cyan); #ifdef NOT_ESP_CORE Console << "---> MESSAGE " << t << ' ' << _HEX(typ) << ' ' << " mem=???" << endl; #else Console << "---> MESSAGE " << t << ' ' << _HEX(typ) << ' ' << " mem=" << ESP.getFreeHeap() << endl; #endif - Console.fg(white); + Console.fg(white); uint16_t addr=0; const int bytes_per_row = 8; diff --git a/src/TinyMqtt.h b/src/TinyMqtt.h index f96f9fc..5383dd0 100644 --- a/src/TinyMqtt.h +++ b/src/TinyMqtt.h @@ -1,3 +1,4 @@ +// vim: ts=2 sw=2 expandtab #pragma once // TODO Should add a AUnit with both TINY_MQTT_ASYNC and not TINY_MQTT_ASYNC