diff --git a/src/config.hpp b/src/config.hpp index af1ee77..83c05a1 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -232,6 +232,7 @@ class Config { _saveNeeded = true; } bool isInfluxDb2Active() { return _influxDb2Url.length() ? true : false; } + bool isInfluxSSL() { return _influxDb2Url.startsWith("https://"); } const char* getInfluxDb2PushOrg() { return _influxDb2Org.c_str(); } void setInfluxDb2PushOrg(String s) { _influxDb2Org = s; diff --git a/src/pushtarget.cpp b/src/pushtarget.cpp index c7a265d..8632050 100644 --- a/src/pushtarget.cpp +++ b/src/pushtarget.cpp @@ -64,7 +64,7 @@ void PushTarget::sendAll(float angle, float gravitySG, float corrGravitySG, if (myConfig.isInfluxDb2Active()) { LOG_PERF_START("push-influxdb2"); - sendInfluxDb2(engine); + sendInfluxDb2(engine, myConfig.isInfluxSSL()); LOG_PERF_STOP("push-influxdb2"); } @@ -78,7 +78,7 @@ void PushTarget::sendAll(float angle, float gravitySG, float corrGravitySG, // // Send to influx db v2 // -void PushTarget::sendInfluxDb2(TemplatingEngine& engine) { +void PushTarget::sendInfluxDb2(TemplatingEngine& engine, bool isSecure) { #if !defined(PUSH_DISABLE_LOGGING) Log.notice(F("PUSH: Sending values to influxdb2." CR)); #endif @@ -91,8 +91,31 @@ void PushTarget::sendInfluxDb2(TemplatingEngine& engine) { "&bucket=" + String(myConfig.getInfluxDb2PushBucket()); String doc = engine.create(TemplatingEngine::TEMPLATE_INFLUX); - _http.begin(_wifi, serverPath); - _http.setTimeout(myHardwareConfig.getPushTimeout() * 1000); + if (isSecure) { + Log.notice(F("PUSH: InfluxDB, SSL enabled without validation." CR)); + _wifiSecure.setInsecure(); + +#if defined(ESP8266) + String host = + serverPath.substring(8); // remove the prefix or the probe will fail, + // it needs a pure host name. + int idx = host.indexOf("/"); + if (idx != -1) host = host.substring(0, idx); + + if (_wifiSecure.probeMaxFragmentLength(host, 443, 512)) { + Log.notice(F("PUSH: InfluxDB server supports smaller SSL buffer." CR)); + _wifiSecure.setBufferSizes(512, 512); + } +#endif + + _httpSecure.begin(_wifiSecure, serverPath); + _httpSecure.setTimeout(myHardwareConfig.getPushTimeout() * 1000); + _lastCode = _httpSecure.POST(doc); + } else { + _http.begin(_wifi, serverPath); + _http.setTimeout(myHardwareConfig.getPushTimeout() * 1000); + _lastCode = _http.POST(doc); + } #if LOG_LEVEL == 6 && !defined(PUSH_DISABLE_LOGGING) Log.verbose(F("PUSH: url %s." CR), serverPath.c_str()); @@ -111,13 +134,18 @@ void PushTarget::sendInfluxDb2(TemplatingEngine& engine) { errLog.addEntry("PUSH: Influxdb push failed response=" + String(_lastCode)); } - _http.end(); - _wifi.stop(); + if (isSecure) { + _httpSecure.end(); + _wifiSecure.stop(); + } else { + _http.end(); + _wifi.stop(); + } tcp_cleanup(); } // -// +// Add HTTP header to request // void PushTarget::addHttpHeader(HTTPClient& http, String header) { if (!header.length()) return; diff --git a/src/pushtarget.hpp b/src/pushtarget.hpp index 227e024..294debf 100644 --- a/src/pushtarget.hpp +++ b/src/pushtarget.hpp @@ -59,7 +59,7 @@ class PushTarget { void sendHttp3(TemplatingEngine& engine, bool isSecure) { sendHttpGet(engine, isSecure); } - void sendInfluxDb2(TemplatingEngine& engine); + void sendInfluxDb2(TemplatingEngine& engine, bool isSecure); void sendMqtt(TemplatingEngine& engine, bool isSecure); int getLastCode() { return _lastCode; } bool getLastSuccess() { return _lastSuccess; } diff --git a/src/webserver.cpp b/src/webserver.cpp index 96d31ff..debcf12 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -861,7 +861,7 @@ void WebServerHandler::webHandleTestPush() { enabled = true; } else if (!type.compareTo(PARAM_FORMAT_INFLUXDB) && myConfig.isInfluxDb2Active()) { - push.sendInfluxDb2(engine); + push.sendInfluxDb2(engine, myConfig.isInfluxSSL()); enabled = true; } else if (!type.compareTo(PARAM_FORMAT_MQTT) && myConfig.isMqttActive()) { push.sendMqtt(engine, myConfig.isMqttSSL()); diff --git a/src_docs/source/releases.rst b/src_docs/source/releases.rst index b6ee67b..bcc8346 100644 --- a/src_docs/source/releases.rst +++ b/src_docs/source/releases.rst @@ -9,6 +9,8 @@ v1.0.0 * Removed brewfather option (can use standard HTTP options), the old apporach can still be used via changing format template. * Added 5 more points for formula creation, so a total of 10 angles/gravity values can be stored. * Added function on format page so that it's easy to copy a format template from the docs (simplify service integration). +* Added https support for Influxdb +* Added additional http error codes to troubleshooting documentation * BUG: Fixed issue in formula calculation in case there were a gap in the data series v0.9.0 diff --git a/src_docs/source/troubleshooting.rst b/src_docs/source/troubleshooting.rst index b441e8c..2fcbbde 100644 --- a/src_docs/source/troubleshooting.rst +++ b/src_docs/source/troubleshooting.rst @@ -31,7 +31,6 @@ Log errors Check the format for your custom header. This means it has not a correct format. * Influxdb push failed response -* Brewfather push failed response * HTTP push failed response All these errors are standard http error codes. This are the commone ones; @@ -41,6 +40,20 @@ Log errors * 403 - Forbidden. Could be an issue with token or URL. * 404 - Not found. Probably a wrong URL. + In some cases there can be negative error codes which have the following meaning: + + * -1 - Connection refused + * -2 - Send header failed + * -3 - Send payload failed + * -4 - Not connected + * -5 - Connection lost + * -6 - No stream + * -7 - No HTTP server + * -8 - Too little RAM available + * -9 - Error encoding + * -10 - Error writing to stream + * -11 - Read timeout + * MQTT push on failed error * -3 - Network failed connected