mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 00:39:50 +03:00
mqttlog [all] function
This commit is contained in:
@@ -725,8 +725,8 @@ void MyESP::_consoleShowHelp() {
|
|||||||
|
|
||||||
myDebug_P(PSTR("*"));
|
myDebug_P(PSTR("*"));
|
||||||
myDebug_P(PSTR("* Commands:"));
|
myDebug_P(PSTR("* Commands:"));
|
||||||
myDebug_P(PSTR("* ?/help=show commands, CTRL-D/quit=close telnet session"));
|
myDebug_P(PSTR("* ?/help=show commands, CTRL-D/quit=end telnet session"));
|
||||||
myDebug_P(PSTR("* set, system, restart, mqttlog, kick, save"));
|
myDebug_P(PSTR("* set, system, restart, mqttlog [all], kick, save"));
|
||||||
|
|
||||||
#ifdef CRASH
|
#ifdef CRASH
|
||||||
myDebug_P(PSTR("* crash <dump | clear | test [n]>"));
|
myDebug_P(PSTR("* crash <dump | clear | test [n]>"));
|
||||||
@@ -1052,12 +1052,12 @@ void MyESP::_telnetCommand(char * commandLine) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// print mqtt log command
|
// print mqtt log command
|
||||||
if ((strcmp(ptrToCommandName, "mqttlog") == 0) && (wc == 1)) {
|
if (strcmp(ptrToCommandName, "mqttlog") == 0) {
|
||||||
_printMQTTLog();
|
_printMQTTLog(wc != 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// show system stats
|
// show system status
|
||||||
if ((strcmp(ptrToCommandName, "system") == 0) && (wc == 1)) {
|
if ((strcmp(ptrToCommandName, "system") == 0) && (wc == 1)) {
|
||||||
showSystemStats();
|
showSystemStats();
|
||||||
return;
|
return;
|
||||||
@@ -1070,7 +1070,7 @@ void MyESP::_telnetCommand(char * commandLine) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// show system stats
|
// quit
|
||||||
if ((strcmp(ptrToCommandName, "quit") == 0) && (wc == 1)) {
|
if ((strcmp(ptrToCommandName, "quit") == 0) && (wc == 1)) {
|
||||||
myDebug_P(PSTR("[TELNET] exiting telnet session"));
|
myDebug_P(PSTR("[TELNET] exiting telnet session"));
|
||||||
SerialAndTelnet.disconnectClient();
|
SerialAndTelnet.disconnectClient();
|
||||||
@@ -1333,13 +1333,13 @@ void MyESP::_systemCheckLoop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// print out ESP system stats
|
// print out ESP system status
|
||||||
// for battery power is ESP.getVcc()
|
// for battery power is ESP.getVcc()
|
||||||
void MyESP::showSystemStats() {
|
void MyESP::showSystemStats() {
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
myDebug_P(PSTR("%sESP8266 System stats:%s"), COLOR_BOLD_ON, COLOR_BOLD_OFF);
|
myDebug_P(PSTR("%sESP8266 System status:%s"), COLOR_BOLD_ON, COLOR_BOLD_OFF);
|
||||||
#else
|
#else
|
||||||
myDebug_P(PSTR("ESP32 System stats:"));
|
myDebug_P(PSTR("ESP32 System status:"));
|
||||||
#endif
|
#endif
|
||||||
myDebug_P(PSTR(""));
|
myDebug_P(PSTR(""));
|
||||||
|
|
||||||
@@ -2688,13 +2688,13 @@ void MyESP::_printHeap(const char * prefix) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// print MQTT log - everything that was published last per topic
|
// print MQTT log - everything that was published last per topic
|
||||||
void MyESP::_printMQTTLog() {
|
void MyESP::_printMQTTLog(bool show_sub = false) {
|
||||||
myDebug_P(PSTR("MQTT publish log:"));
|
myDebug_P(PSTR("MQTT publish log:"));
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
for (i = 0; i < MYESP_MQTTLOG_MAX; i++) {
|
for (i = 0; i < MYESP_MQTTLOG_MAX; i++) {
|
||||||
if ((MQTT_log[i].topic != nullptr) && (MQTT_log[i].type == MYESP_MQTTLOGTYPE_PUBLISH)) {
|
if ((MQTT_log[i].topic != nullptr) && (MQTT_log[i].type == MYESP_MQTTLOGTYPE_PUBLISH)) {
|
||||||
myDebug_P(PSTR(" Timestamp:%02d:%02d:%02d Topic:%s Payload:%s"),
|
myDebug_P(PSTR(" (%02d:%02d:%02d) Topic:%s Payload:%s"),
|
||||||
to_hour(MQTT_log[i].timestamp),
|
to_hour(MQTT_log[i].timestamp),
|
||||||
to_minute(MQTT_log[i].timestamp),
|
to_minute(MQTT_log[i].timestamp),
|
||||||
to_second(MQTT_log[i].timestamp),
|
to_second(MQTT_log[i].timestamp),
|
||||||
@@ -2703,12 +2703,15 @@ void MyESP::_printMQTTLog() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
myDebug_P(PSTR("")); // newline
|
// show subscriptions
|
||||||
myDebug_P(PSTR("MQTT subscriptions:"));
|
if (show_sub) {
|
||||||
|
myDebug_P(PSTR("")); // newline
|
||||||
|
myDebug_P(PSTR("MQTT subscriptions:"));
|
||||||
|
|
||||||
for (i = 0; i < MYESP_MQTTLOG_MAX; i++) {
|
for (i = 0; i < MYESP_MQTTLOG_MAX; i++) {
|
||||||
if ((MQTT_log[i].topic != nullptr) && (MQTT_log[i].type == MYESP_MQTTLOGTYPE_SUBSCRIBE)) {
|
if ((MQTT_log[i].topic != nullptr) && (MQTT_log[i].type == MYESP_MQTTLOGTYPE_SUBSCRIBE)) {
|
||||||
myDebug_P(PSTR(" Topic:%s"), MQTT_log[i].topic);
|
myDebug_P(PSTR(" Topic:%s"), MQTT_log[i].topic);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
src/MyESP.h
16
src/MyESP.h
@@ -9,7 +9,7 @@
|
|||||||
#ifndef MyESP_h
|
#ifndef MyESP_h
|
||||||
#define MyESP_h
|
#define MyESP_h
|
||||||
|
|
||||||
#define MYESP_VERSION "1.2.24"
|
#define MYESP_VERSION "1.2.25"
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
@@ -335,17 +335,17 @@ class MyESP {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// mqtt
|
// mqtt
|
||||||
void _mqttOnMessage(char * topic, char * payload, size_t len);
|
void _mqttOnMessage(char * topic, char * payload, size_t len);
|
||||||
void _mqttConnect();
|
void _mqttConnect();
|
||||||
void _mqtt_setup();
|
void _mqtt_setup();
|
||||||
void _mqttOnConnect();
|
void _mqttOnConnect();
|
||||||
void _sendStart();
|
void _sendStart();
|
||||||
char * _mqttTopic(const char * topic);
|
char * _mqttTopic(const char * topic);
|
||||||
|
|
||||||
// mqtt log
|
// mqtt log
|
||||||
_MQTT_Log_t MQTT_log[MYESP_MQTTLOG_MAX]; // log for publish and subscribe messages
|
_MQTT_Log_t MQTT_log[MYESP_MQTTLOG_MAX]; // log for publish and subscribe messages
|
||||||
|
|
||||||
void _printMQTTLog();
|
void _printMQTTLog(bool show_sub);
|
||||||
void _addMQTTLog(const char * topic, const char * payload, const MYESP_MQTTLOGTYPE_t type);
|
void _addMQTTLog(const char * topic, const char * payload, const MYESP_MQTTLOGTYPE_t type);
|
||||||
|
|
||||||
AsyncMqttClient mqttClient; // the MQTT class
|
AsyncMqttClient mqttClient; // the MQTT class
|
||||||
|
|||||||
Reference in New Issue
Block a user