Added SSL support for influxdb
This commit is contained in:
@ -232,6 +232,7 @@ class Config {
|
|||||||
_saveNeeded = true;
|
_saveNeeded = true;
|
||||||
}
|
}
|
||||||
bool isInfluxDb2Active() { return _influxDb2Url.length() ? true : false; }
|
bool isInfluxDb2Active() { return _influxDb2Url.length() ? true : false; }
|
||||||
|
bool isInfluxSSL() { return _influxDb2Url.startsWith("https://"); }
|
||||||
const char* getInfluxDb2PushOrg() { return _influxDb2Org.c_str(); }
|
const char* getInfluxDb2PushOrg() { return _influxDb2Org.c_str(); }
|
||||||
void setInfluxDb2PushOrg(String s) {
|
void setInfluxDb2PushOrg(String s) {
|
||||||
_influxDb2Org = s;
|
_influxDb2Org = s;
|
||||||
|
@ -64,7 +64,7 @@ void PushTarget::sendAll(float angle, float gravitySG, float corrGravitySG,
|
|||||||
|
|
||||||
if (myConfig.isInfluxDb2Active()) {
|
if (myConfig.isInfluxDb2Active()) {
|
||||||
LOG_PERF_START("push-influxdb2");
|
LOG_PERF_START("push-influxdb2");
|
||||||
sendInfluxDb2(engine);
|
sendInfluxDb2(engine, myConfig.isInfluxSSL());
|
||||||
LOG_PERF_STOP("push-influxdb2");
|
LOG_PERF_STOP("push-influxdb2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ void PushTarget::sendAll(float angle, float gravitySG, float corrGravitySG,
|
|||||||
//
|
//
|
||||||
// Send to influx db v2
|
// Send to influx db v2
|
||||||
//
|
//
|
||||||
void PushTarget::sendInfluxDb2(TemplatingEngine& engine) {
|
void PushTarget::sendInfluxDb2(TemplatingEngine& engine, bool isSecure) {
|
||||||
#if !defined(PUSH_DISABLE_LOGGING)
|
#if !defined(PUSH_DISABLE_LOGGING)
|
||||||
Log.notice(F("PUSH: Sending values to influxdb2." CR));
|
Log.notice(F("PUSH: Sending values to influxdb2." CR));
|
||||||
#endif
|
#endif
|
||||||
@ -91,8 +91,31 @@ void PushTarget::sendInfluxDb2(TemplatingEngine& engine) {
|
|||||||
"&bucket=" + String(myConfig.getInfluxDb2PushBucket());
|
"&bucket=" + String(myConfig.getInfluxDb2PushBucket());
|
||||||
String doc = engine.create(TemplatingEngine::TEMPLATE_INFLUX);
|
String doc = engine.create(TemplatingEngine::TEMPLATE_INFLUX);
|
||||||
|
|
||||||
_http.begin(_wifi, serverPath);
|
if (isSecure) {
|
||||||
_http.setTimeout(myHardwareConfig.getPushTimeout() * 1000);
|
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)
|
#if LOG_LEVEL == 6 && !defined(PUSH_DISABLE_LOGGING)
|
||||||
Log.verbose(F("PUSH: url %s." CR), serverPath.c_str());
|
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));
|
errLog.addEntry("PUSH: Influxdb push failed response=" + String(_lastCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
_http.end();
|
if (isSecure) {
|
||||||
_wifi.stop();
|
_httpSecure.end();
|
||||||
|
_wifiSecure.stop();
|
||||||
|
} else {
|
||||||
|
_http.end();
|
||||||
|
_wifi.stop();
|
||||||
|
}
|
||||||
tcp_cleanup();
|
tcp_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
//
|
// Add HTTP header to request
|
||||||
//
|
//
|
||||||
void PushTarget::addHttpHeader(HTTPClient& http, String header) {
|
void PushTarget::addHttpHeader(HTTPClient& http, String header) {
|
||||||
if (!header.length()) return;
|
if (!header.length()) return;
|
||||||
|
@ -59,7 +59,7 @@ class PushTarget {
|
|||||||
void sendHttp3(TemplatingEngine& engine, bool isSecure) {
|
void sendHttp3(TemplatingEngine& engine, bool isSecure) {
|
||||||
sendHttpGet(engine, isSecure);
|
sendHttpGet(engine, isSecure);
|
||||||
}
|
}
|
||||||
void sendInfluxDb2(TemplatingEngine& engine);
|
void sendInfluxDb2(TemplatingEngine& engine, bool isSecure);
|
||||||
void sendMqtt(TemplatingEngine& engine, bool isSecure);
|
void sendMqtt(TemplatingEngine& engine, bool isSecure);
|
||||||
int getLastCode() { return _lastCode; }
|
int getLastCode() { return _lastCode; }
|
||||||
bool getLastSuccess() { return _lastSuccess; }
|
bool getLastSuccess() { return _lastSuccess; }
|
||||||
|
@ -861,7 +861,7 @@ void WebServerHandler::webHandleTestPush() {
|
|||||||
enabled = true;
|
enabled = true;
|
||||||
} else if (!type.compareTo(PARAM_FORMAT_INFLUXDB) &&
|
} else if (!type.compareTo(PARAM_FORMAT_INFLUXDB) &&
|
||||||
myConfig.isInfluxDb2Active()) {
|
myConfig.isInfluxDb2Active()) {
|
||||||
push.sendInfluxDb2(engine);
|
push.sendInfluxDb2(engine, myConfig.isInfluxSSL());
|
||||||
enabled = true;
|
enabled = true;
|
||||||
} else if (!type.compareTo(PARAM_FORMAT_MQTT) && myConfig.isMqttActive()) {
|
} else if (!type.compareTo(PARAM_FORMAT_MQTT) && myConfig.isMqttActive()) {
|
||||||
push.sendMqtt(engine, myConfig.isMqttSSL());
|
push.sendMqtt(engine, myConfig.isMqttSSL());
|
||||||
|
@ -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.
|
* 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 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 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
|
* BUG: Fixed issue in formula calculation in case there were a gap in the data series
|
||||||
|
|
||||||
v0.9.0
|
v0.9.0
|
||||||
|
@ -31,7 +31,6 @@ Log errors
|
|||||||
Check the format for your custom header. This means it has not a correct format.
|
Check the format for your custom header. This means it has not a correct format.
|
||||||
|
|
||||||
* Influxdb push failed response
|
* Influxdb push failed response
|
||||||
* Brewfather push failed response
|
|
||||||
* HTTP push failed response
|
* HTTP push failed response
|
||||||
|
|
||||||
All these errors are standard http error codes. This are the commone ones;
|
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.
|
* 403 - Forbidden. Could be an issue with token or URL.
|
||||||
* 404 - Not found. Probably a wrong 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 <topic> failed error
|
* MQTT push on <topic> failed error
|
||||||
|
|
||||||
* -3 - Network failed connected
|
* -3 - Network failed connected
|
||||||
|
Reference in New Issue
Block a user