diff --git a/tasmota/support.ino b/tasmota/support.ino index 2e17c7915..097bb1de8 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -316,7 +316,7 @@ float CharToFloat(const char *str) char *pt = strbuf; if (*pt == '\0') { return 0.0; } - while ((*pt != '\0') && isblank(*pt)) { pt++; } // Trim leading spaces + while ((*pt != '\0') && isspace(*pt)) { pt++; } // Trim leading spaces signed char sign = 1; if (*pt == '-') { sign = -1; } @@ -529,12 +529,12 @@ bool IsNumeric(const char* value) { return (*digit == '\0'); } -char* Trim(char* p) -{ +char* Trim(char* p) { + // Remove leading and trailing tab, \n, \v, \f, \r and space if (*p != '\0') { - while ((*p != '\0') && isblank(*p)) { p++; } // Trim leading spaces + while ((*p != '\0') && isspace(*p)) { p++; } // Trim leading spaces char* q = p + strlen(p) -1; - while ((q >= p) && isblank(*q)) { q--; } // Trim trailing spaces + while ((q >= p) && isspace(*q)) { q--; } // Trim trailing spaces q++; *q = '\0'; } diff --git a/tasmota/xdrv_59_influxdb.ino b/tasmota/xdrv_59_influxdb.ino index 9bc7f5510..a591321c8 100644 --- a/tasmota/xdrv_59_influxdb.ino +++ b/tasmota/xdrv_59_influxdb.ino @@ -84,7 +84,7 @@ struct { String _serverUrl; // Connection info String _writeUrl; // Cached full write url String _lastErrorResponse; // Server reponse or library error message for last failed request - uint32_t _lastRequestTime = 0; // Last time in ms we made are a request to server + uint32_t _lastRequestTime = 0; // Last time in ms we made a request to server int interval = 0; int _lastStatusCode = 0; // HTTP status code of last request to server int _lastRetryAfter = 0; // Store retry timeout suggested by server after last request @@ -161,7 +161,7 @@ void InfluxDbAfterRequest(int expectedStatusCode, bool modifyLastConnStatus) { IFDB._lastRequestTime = millis(); // AddLog(LOG_LEVEL_DEBUG, PSTR("IFX: HTTP status code %d"), IFDB._lastStatusCode); IFDB._lastRetryAfter = 0; - if (IFDB._lastStatusCode >= 429) { //retryable server errors + if (IFDB._lastStatusCode >= 429) { // Retryable server errors if (IFDBhttpClient->hasHeader(RetryAfter)) { IFDB._lastRetryAfter = IFDBhttpClient->header(RetryAfter).toInt(); AddLog(LOG_LEVEL_DEBUG, PSTR("IFX: Reply after %d"), IFDB._lastRetryAfter); @@ -171,12 +171,12 @@ void InfluxDbAfterRequest(int expectedStatusCode, bool modifyLastConnStatus) { IFDB._lastErrorResponse = ""; if (IFDB._lastStatusCode != expectedStatusCode) { if (IFDB._lastStatusCode > 0) { - IFDB._lastErrorResponse = IFDBhttpClient->getString(); - AddLog(LOG_LEVEL_INFO, PSTR("IFX: %s"), IFDB._lastErrorResponse.c_str()); // {"error":"database not found: \"db\""} + IFDB._lastErrorResponse = IFDBhttpClient->getString(); // {"error":"database not found: \"db\""}\n } else { IFDB._lastErrorResponse = IFDBhttpClient->errorToString(IFDB._lastStatusCode); - AddLog(LOG_LEVEL_INFO, PSTR("IFX: Error %s"), IFDB._lastErrorResponse.c_str()); } + IFDB._lastErrorResponse.trim(); // Remove trailing \n + AddLog(LOG_LEVEL_INFO, PSTR("IFX: Error %s"), IFDB._lastErrorResponse.c_str()); } } @@ -191,8 +191,6 @@ bool InfluxDbValidateConnection(void) { if (1 == Settings->influxdb_version) { url += InfluxDbAuth(); } - // on version 1.8.9 /health works fine -// String url = IFDB._serverUrl + "/health"; AddLog(LOG_LEVEL_INFO, PSTR("IFX: Validating connection to %s"), url.c_str()); if (!IFDBhttpClient->begin(*IFDBwifiClient, url)) { @@ -221,6 +219,7 @@ int InfluxDbPostData(const char *data) { return false; } + Trim((char*)data); // Remove trailing \n AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("IFX: Sending\n%s"), data); IFDBhttpClient->addHeader(F("Content-Type"), F("text/plain")); InfluxDbBeforeRequest(); diff --git a/tasmota/xsns_53_sml.ino b/tasmota/xsns_53_sml.ino index 184261771..5c3644d1f 100755 --- a/tasmota/xsns_53_sml.ino +++ b/tasmota/xsns_53_sml.ino @@ -1198,7 +1198,7 @@ double CharToDouble(const char *str) strlcpy(strbuf, str, sizeof(strbuf)); char *pt = strbuf; - while ((*pt != '\0') && isblank(*pt)) { pt++; } // Trim leading spaces + while ((*pt != '\0') && isspace(*pt)) { pt++; } // Trim leading spaces signed char sign = 1; if (*pt == '-') { sign = -1; }