void sendLog(const char *msg, uint8_t loglevel) { char buf[101]; char buf2[121]; static char tbuf[20]; bool timeIsValid=false; strlcpy(buf, msg, sizeof(buf)); if (confTime.ntpEnable) { updateTime(); if(lt.tm_year > 70) { // lt.tm_year = years since 1900, before NTP is synced = 70 //strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", <); strftime(tbuf, sizeof(tbuf), "%H:%M:%S", <); sprintf(buf2, "[%s] %s\r\n", tbuf, buf); timeIsValid = true; } } if(!timeIsValid) { //unsigned long tmpMillis; unsigned long tmpSecs; //unsigned int restMillis; //tmpMillis = millis(); //tmpSecs = tmpMillis / 1000; //restMillis = tmpMillis - (tmpSecs * 1000); tmpSecs = millis() / 1000; //sprintf(buf2, "[%u.%u] %s\r\n", tmpSecs, restMillis, buf); sprintf(buf2, "[%07lu] %s\r\n", tmpSecs, buf); } if(loglevel <= confLog.logLevelSerial) Serial.print(buf2); if (confMqtt.mqtt_enable && mqttclient.state() == 0) { if(loglevel <= confLog.logLevelMqtt) mqttclient.publish(confMqtt.mqtt_topic_out, buf, confMqtt.mqtt_outRetain); } yield(); if (confWeb.enableConsole && webSocket.connectedClients() > 0) { if(loglevel <= confLog.logLevelWeb) webSocket.broadcastTXT(buf2); } } void sendLog(const __FlashStringHelper *msg, uint8_t loglevel) { char buf[501]; PGM_P p = reinterpret_cast(msg); size_t n = 0; while (1) { unsigned char c = pgm_read_byte(p++); if (c == 0) { buf[n] = c; break; } else if (n >= sizeof(buf)-1) { break; } else { buf[n] = c; n++; } } sendLog(buf, loglevel); }