mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 12:46:34 +00:00
Unload use of global log_data
This commit is contained in:
parent
14500b8783
commit
fb15736ed7
@ -1896,35 +1896,9 @@ void SetSyslog(uint32_t loglevel)
|
|||||||
TasmotaGlobal.syslog_timer = 0;
|
TasmotaGlobal.syslog_timer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Syslog(void)
|
void SyslogAsync(bool refresh) {
|
||||||
{
|
|
||||||
static IPAddress syslog_host_addr; // Syslog host IP address
|
static IPAddress syslog_host_addr; // Syslog host IP address
|
||||||
static uint32_t syslog_host_hash = 0; // Syslog host name hash
|
static uint32_t syslog_host_hash = 0; // Syslog host name hash
|
||||||
|
|
||||||
// Destroys TasmotaGlobal.log_data
|
|
||||||
|
|
||||||
uint32_t current_hash = GetHash(SettingsText(SET_SYSLOG_HOST), strlen(SettingsText(SET_SYSLOG_HOST)));
|
|
||||||
if (syslog_host_hash != current_hash) {
|
|
||||||
syslog_host_hash = current_hash;
|
|
||||||
WiFi.hostByName(SettingsText(SET_SYSLOG_HOST), syslog_host_addr); // If sleep enabled this might result in exception so try to do it once using hash
|
|
||||||
}
|
|
||||||
if (PortUdp.beginPacket(syslog_host_addr, Settings.syslog_port)) {
|
|
||||||
char syslog_preamble[64]; // Hostname + Id
|
|
||||||
snprintf_P(syslog_preamble, sizeof(syslog_preamble), PSTR("%s ESP-"), NetworkHostname());
|
|
||||||
memmove(TasmotaGlobal.log_data + strlen(syslog_preamble), TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data) - strlen(syslog_preamble));
|
|
||||||
TasmotaGlobal.log_data[sizeof(TasmotaGlobal.log_data) -1] = '\0';
|
|
||||||
memcpy(TasmotaGlobal.log_data, syslog_preamble, strlen(syslog_preamble));
|
|
||||||
PortUdp_write(TasmotaGlobal.log_data, strlen(TasmotaGlobal.log_data));
|
|
||||||
PortUdp.endPacket();
|
|
||||||
delay(1); // Add time for UDP handling (#5512)
|
|
||||||
} else {
|
|
||||||
TasmotaGlobal.syslog_level = 0;
|
|
||||||
TasmotaGlobal.syslog_timer = SYSLOG_TIMER;
|
|
||||||
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_SYSLOG_HOST_NOT_FOUND ". " D_RETRY_IN " %d " D_UNIT_SECOND), SYSLOG_TIMER);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SyslogAsync(bool refresh) {
|
|
||||||
static uint32_t index = 1;
|
static uint32_t index = 1;
|
||||||
|
|
||||||
if (!TasmotaGlobal.syslog_level) { return; }
|
if (!TasmotaGlobal.syslog_level) { return; }
|
||||||
@ -1933,12 +1907,30 @@ void SyslogAsync(bool refresh) {
|
|||||||
char* line;
|
char* line;
|
||||||
size_t len;
|
size_t len;
|
||||||
while (GetLog(TasmotaGlobal.syslog_level, &index, &line, &len)) {
|
while (GetLog(TasmotaGlobal.syslog_level, &index, &line, &len)) {
|
||||||
// 00:00:00.110 Project tasmota Wemos5 Version 9.2.0.1(theo)-2_7_4_9(2020-12-20T17:09:26)
|
// 00:00:02.096 HTP: Web server active on wemos5 with IP address 192.168.2.172
|
||||||
// Project tasmota Wemos5 Version 9.2.0.1(theo)-2_7_4_9(2020-12-20T17:09:26)
|
// HTP: Web server active on wemos5 with IP address 192.168.2.172
|
||||||
uint32_t mxtime = strchr(line, ' ') - line +1; // Remove mxtime
|
uint32_t mxtime = strchr(line, ' ') - line +1; // Remove mxtime
|
||||||
if (mxtime > 0) {
|
if (mxtime > 0) {
|
||||||
strlcpy(TasmotaGlobal.log_data, line +mxtime, len -mxtime);
|
uint32_t current_hash = GetHash(SettingsText(SET_SYSLOG_HOST), strlen(SettingsText(SET_SYSLOG_HOST)));
|
||||||
Syslog();
|
if (syslog_host_hash != current_hash) {
|
||||||
|
syslog_host_hash = current_hash;
|
||||||
|
WiFi.hostByName(SettingsText(SET_SYSLOG_HOST), syslog_host_addr); // If sleep enabled this might result in exception so try to do it once using hash
|
||||||
|
}
|
||||||
|
if (PortUdp.beginPacket(syslog_host_addr, Settings.syslog_port)) {
|
||||||
|
char log_data[len +72]; // Hostname + Id + log data
|
||||||
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s ESP-"), NetworkHostname());
|
||||||
|
uint32_t preamble_len = strlen(log_data);
|
||||||
|
len -= mxtime;
|
||||||
|
strlcpy(log_data +preamble_len, line +mxtime, len);
|
||||||
|
// wemos5 ESP-HTP: Web server active on wemos5 with IP address 192.168.2.172
|
||||||
|
PortUdp_write(log_data, preamble_len + len);
|
||||||
|
PortUdp.endPacket();
|
||||||
|
delay(1); // Add time for UDP handling (#5512)
|
||||||
|
} else {
|
||||||
|
TasmotaGlobal.syslog_level = 0;
|
||||||
|
TasmotaGlobal.syslog_timer = SYSLOG_TIMER;
|
||||||
|
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_SYSLOG_HOST_NOT_FOUND ". " D_RETRY_IN " %d " D_UNIT_SECOND), SYSLOG_TIMER);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -245,7 +245,7 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len)
|
|||||||
DEBUG_CORE_LOG(PSTR("CMD: Payload %d"), payload);
|
DEBUG_CORE_LOG(PSTR("CMD: Payload %d"), payload);
|
||||||
|
|
||||||
// TasmotaGlobal.backlog_timer = millis() + (100 * MIN_BACKLOG_DELAY);
|
// TasmotaGlobal.backlog_timer = millis() + (100 * MIN_BACKLOG_DELAY);
|
||||||
TasmotaGlobal.backlog_timer = millis() + Settings.param[P_BACKLOG_DELAY];
|
TasmotaGlobal.backlog_timer = millis() + Settings.param[P_BACKLOG_DELAY]; // SetOption34
|
||||||
|
|
||||||
char command[CMDSZ] = { 0 };
|
char command[CMDSZ] = { 0 };
|
||||||
XdrvMailbox.command = command;
|
XdrvMailbox.command = command;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user