Remove ctrlchars from mqtt log message

This commit is contained in:
Theo Arends 2020-10-10 16:44:35 +02:00
parent 376e0ba1a7
commit 70d49d210b
2 changed files with 22 additions and 3 deletions

View File

@ -375,6 +375,22 @@ char* RemoveSpace(char* p)
return p;
}
char* RemoveControlCharacter(char* p)
{
char* write = p;
char* read = p;
char ch = '.';
while (ch != '\0') {
ch = *read++;
if (!iscntrl(ch)) {
*write++ = ch;
}
}
if (write != p) { *write-- = '\0'; }
return p;
}
char* ReplaceCommaWithDot(char* p)
{
char* write = (char*)p;

View File

@ -242,12 +242,15 @@ void MqttDataHandler(char* mqtt_topic, uint8_t* mqtt_data, unsigned int data_len
char topic[TOPSZ];
strlcpy(topic, mqtt_topic, sizeof(topic));
mqtt_data[data_len] = 0;
char data[data_len +1];
memcpy(data, mqtt_data, sizeof(data));
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_MQTT D_RECEIVED_TOPIC " \"%s\", " D_DATA_SIZE " %d, " D_DATA " \"%s\""), topic, data_len, data);
char data[data_len +1];
memcpy(data, mqtt_data, sizeof(data));
AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_MQTT D_DATA_SIZE " %d, \"%s %s\""), data_len, topic, RemoveControlCharacter(data));
// if (LOG_LEVEL_DEBUG_MORE <= seriallog_level) { Serial.println(data); }
memcpy(data, mqtt_data, sizeof(data));
// MQTT pre-processing
XdrvMailbox.index = strlen(topic);
XdrvMailbox.data_len = data_len;