removed 'module' from log

This commit is contained in:
Patrick Haßel 2024-04-10 13:18:23 +02:00
parent d8eb6c87d8
commit 0fa32d9b97
7 changed files with 51 additions and 51 deletions

View File

@ -9,7 +9,7 @@
void setup() {
delay(500);
Serial.begin(115200);
info("MAIN", "Startup...");
info("Startup...");
mqttSetup();
wifiSetup();
patrixSetup();

View File

@ -17,7 +17,7 @@ void consoleLoop() {
if (symbol == '\n' || symbol == '\r') {
if (*consoleBuffer != 0) {
Serial.print('\n');
info("CONSOLE", "> %s", consoleBuffer);
info("CONSOLE > %s", consoleBuffer);
consoleHandle(consoleBuffer);
consoleBufferW = consoleBuffer;
*consoleBufferW = 0;
@ -45,34 +45,34 @@ void consoleLoop() {
void consoleHandle(const char *cmd) {
if (strcmp(cmd, "help") == 0) {
info("CONSOLE", "help : print this help");
info("CONSOLE", "net : print network info");
info("CONSOLE", "reboot : reboot system");
info("CONSOLE", "wifi : reconnect wifi");
info("CONSOLE", "mqtt : reconnect mqtt");
info("CONSOLE", "debug : toggle debug log");
info("help : print this help");
info("net : print network info");
info("reboot : reboot system");
info("wifi : reconnect wifi");
info("mqtt : reconnect mqtt");
info("debug : toggle debug log");
} else if (strcmp(cmd, "net") == 0) {
info("CONSOLE", "MAC: %17s", WiFi.macAddress().c_str());
info("CONSOLE", "IP: %17s", WiFi.localIP().toString().c_str());
info("CONSOLE", "Gateway: %17s", WiFi.gatewayIP().toString().c_str());
info("CONSOLE", "SSID: %17s", WiFi.SSID().c_str());
info("CONSOLE", "BSSID: %17s", WiFi.BSSIDstr().c_str());
info("CONSOLE", "RSSI: %17d", WiFi.RSSI());
info("MAC: %17s", WiFi.macAddress().c_str());
info("IP: %17s", WiFi.localIP().toString().c_str());
info("Gateway: %17s", WiFi.gatewayIP().toString().c_str());
info("SSID: %17s", WiFi.SSID().c_str());
info("BSSID: %17s", WiFi.BSSIDstr().c_str());
info("RSSI: %17d", WiFi.RSSI());
} else if (strcmp(cmd, "reboot") == 0) {
info("CONSOLE", "Rebooting...");
info("Rebooting...");
delay(500);
yield();
ESP.restart();
} else if (strcmp(cmd, "wifi") == 0) {
info("CONSOLE", "Reconnecting WiFi...");
info("Reconnecting WiFi...");
wifiConnect();
} else if (strcmp(cmd, "mqtt") == 0) {
info("CONSOLE", "Reconnecting MQTT...");
info("Reconnecting MQTT...");
mqttDisconnect();
} else if (strcmp(cmd, "debug") == 0) {
setDebugEnabled(!isDebugEnabled());
info("CONSOLE", "DEBUG: %s", isDebugEnabled() ? "ON" : "OFF");
info("DEBUG: %s", isDebugEnabled() ? "ON" : "OFF");
} else {
info("CONSOLE", "Unknown command: %s", cmd);
info("Unknown command: %s", cmd);
}
}

View File

@ -12,12 +12,12 @@ void getDateTime(char *buffer, size_t size) {
strftime(buffer, size, "%Y-%m-%d %H:%M:%S %z", &time);
}
void log(const char *level, const char *module, const char *format, va_list vl) {
void log(const char *level, const char *format, va_list vl) {
char datetime[26];
getDateTime(datetime, sizeof datetime);
char header[45];
snprintf(header, sizeof header, " | %-5s | %-10s | ", level, module);
char header[20];
snprintf(header, sizeof header, " | %-5s | ", level);
char message[500];
vsnprintf(message, sizeof message, format, vl);
@ -30,27 +30,27 @@ void log(const char *level, const char *module, const char *format, va_list vl)
mqttPublishLog(datetime, header, message);
}
void debug(const char *module, const char *format, ...) {
void debug(const char *format, ...) {
if (!debugEnabled) {
return;
}
va_list vl;
va_start(vl, format);
log("DEBUG", module, format, vl);
log("DEBUG", format, vl);
va_end(vl);
}
void info(const char *module, const char *format, ...) {
void info(const char *format, ...) {
va_list vl;
va_start(vl, format);
log("INFO", module, format, vl);
log("INFO", format, vl);
va_end(vl);
}
void error(const char *module, const char *format, ...) {
void error(const char *format, ...) {
va_list vl;
va_start(vl, format);
log("ERROR", module, format, vl);
log("ERROR", format, vl);
va_end(vl);
}

View File

@ -1,11 +1,11 @@
#ifndef SENSOR3_LOG_H
#define SENSOR3_LOG_H
void debug(const char *module, const char *format, ...);
void debug(const char *format, ...);
void info(const char *module, const char *format, ...);
void info(const char *format, ...);
void error(const char *module, const char *format, ...);
void error(const char *format, ...);
void setDebugEnabled(bool enabled);

View File

@ -32,7 +32,7 @@ void mqttSetup() {
void mqttDisconnect() {
if (mqttConnected) {
info("MQTT", "Disconnecting");
info("MQTT disconnecting");
mqtt.disconnect();
mqttConnected = false;
}
@ -42,34 +42,34 @@ void mqttLoop() {
const bool connected = mqtt.loop();
if (mqttConnected != connected) {
if (!connected) {
error("MQTT", "DISCONNECTED");
error("MQTT DISCONNECTED");
}
mqttConnected = connected;
}
if (isWiFiConnected() && isTimeSet() && !connected && (mqttLastConnectTry == 0 || millis() - mqttLastConnectTry > CONNECT_TIMEOUT_MILLISECONDS)) {
error("MQTT", "Connecting MQTT host: %s", MQTT_HOST);
error("MQTT connecting MQTT host: %s", MQTT_HOST);
mqttLastConnectTry = millis();
mqtt.setServer(MQTT_HOST, 1883);
if (!mqtt.connect(HOSTNAME, logTopic, 0, false, "MQTT disconnected")) {
error("MQTT", "FAILED TO CONNECT");
error("MQTT FAILED TO CONNECT");
return;
}
info("MQTT", "CONNECTED");
info("MQTT CONNECTED");
mqtt.setKeepAlive(10);
mqtt.setBufferSize(512);
// mqtt.subscribe(cmdTopic);
mqtt.setCallback([](const char *topic, const uint8_t *bytes, const unsigned int length) {
char content[64];
if (length > sizeof content - 1) {
error("MQTT", "MQTT RECEIVE BUFFER OVERFLOW");
error("MQTT RECEIVE BUFFER OVERFLOW");
return;
}
memcpy(content, bytes, length);
content[length] = 0;
if (strcmp(topic, cmdTopic) == 0) {
info("MQTT", "CMD > %s", content);
info("MQTT CMD > %s", content);
consoleHandle(content);
}
});

View File

@ -43,20 +43,20 @@ public:
first = false;
uint8_t count = sensors.getDeviceCount();
if (count == 0) {
error("DALLAS", "No devices found!");
error("No devices found!");
} else {
debug("DALLAS", "Found %d devices:", count);
debug("Found %d devices:", count);
uint64_t address;
for (int index = 0; index < count; ++index) {
sensors.getAddress((uint8_t *) &address, index);
debug("DALLAS", " - 0x%016llX = %5.1f C", address, sensors.getTempC((uint8_t *) &address));
debug(" - 0x%016llX = %5.1f C", address, sensors.getTempC((uint8_t *) &address));
}
}
}
converting = false;
converted = true;
} else if (millis() - lastMillis > DALLAS_TIMEOUT_MILLISECONDS) {
error("DALLAS", "Timeout!");
error("Timeout!");
converting = false;
converted = false;
}

View File

@ -55,7 +55,7 @@ void wifiConnect() {
WiFi.setAutoReconnect(false);
yield();
info("WIFI", "Connecting: %s", WIFI_SSID);
info("WIFI connecting: %s", WIFI_SSID);
WiFiClass::hostname(HOSTNAME);
yield();
@ -66,18 +66,18 @@ void wifiConnect() {
void otaSetup() {
ArduinoOTA.onStart([] {
info("OTA", "OTA start...");
info("OTA start...");
otaLastLogStep = 0;
});
ArduinoOTA.onProgress([](unsigned int received, unsigned int total) {
uint8_t currentStep = 20 * received / total;
if (otaLastLogStep != currentStep) {
info("OTA", "OTA Progress: %3d%%", currentStep * 5);
info("OTA Progress: %3d%%", currentStep * 5);
otaLastLogStep = currentStep;
}
});
ArduinoOTA.onEnd([] {
info("OTA", "OTA Complete!");
info("OTA Complete!");
});
ArduinoOTA.onError([](ota_error_t e) {
const char *name;
@ -101,7 +101,7 @@ void otaSetup() {
name = "[???]";
break;
}
error("OTA", name);
error(name);
});
}
@ -132,7 +132,7 @@ void wifiLoop() {
if (!timeSet) {
preTimeOffset = epochSeconds;
} else {
info("NTP", "Time set!");
info("Got time via NTP");
}
}
@ -140,7 +140,7 @@ void wifiLoop() {
if (wifiConnected) {
if (!hasIp) {
wifiConnected = false;
info("WIFI", "WiFi disconnected!");
info("WiFi disconnected!");
wifiConnect();
} else {
ArduinoOTA.handle();
@ -148,11 +148,11 @@ void wifiLoop() {
} else {
if (hasIp) {
wifiConnected = true;
info("WIFI", "WiFi connected: ip=%s", WiFi.localIP().toString().c_str());
info("WiFi connected: ip=%s", WiFi.localIP().toString().c_str());
ArduinoOTA.begin();
configTime(TIMEZONE_OFFSET, DST_OFFSET, WiFi.gatewayIP().toString().c_str(), NTP_SERVER);
} else if (millis() - wifiLastConnectTry > WIFI_TIMEOUT_MS) {
info("WIFI", "WiFi timeout!");
info("WiFi timeout!");
wifiConnect();
}
}