moved maxfrag to own function
This commit is contained in:
parent
8342341cb9
commit
e91c8af1a5
@ -387,7 +387,7 @@ void PerfLogging::pushInflux() {
|
|||||||
// Send HTTP POST request
|
// Send HTTP POST request
|
||||||
String auth = "Token " + String(myConfig.getInfluxDb2PushToken());
|
String auth = "Token " + String(myConfig.getInfluxDb2PushToken());
|
||||||
http.addHeader(F("Authorization"), auth.c_str());
|
http.addHeader(F("Authorization"), auth.c_str());
|
||||||
http.setTimeout(myHardwareConfig.getPushTimeout());
|
http.setTimeout(myAdvancedConfig.getPushTimeout());
|
||||||
int httpResponseCode = http.POST(body);
|
int httpResponseCode = http.POST(body);
|
||||||
|
|
||||||
if (httpResponseCode == 204) {
|
if (httpResponseCode == 204) {
|
||||||
|
@ -60,6 +60,12 @@ void checkSleepMode(float angle, float volt) {
|
|||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined( FORCE_GRAVITY_MODE )
|
||||||
|
Log.notice(
|
||||||
|
F("MAIN: Forcing device into gravity mode for debugging" CR));
|
||||||
|
runMode = RunMode::gravityMode;
|
||||||
|
#endif
|
||||||
|
|
||||||
const RawGyroData &g = myConfig.getGyroCalibration();
|
const RawGyroData &g = myConfig.getGyroCalibration();
|
||||||
|
|
||||||
if (!g.ax && !g.ay && !g.az && !g.gx && !g.gy && !g.gz) {
|
if (!g.ax && !g.ay && !g.az && !g.gx && !g.gy && !g.gz) {
|
||||||
|
@ -148,6 +148,36 @@ void PushTarget::sendAll(float angle, float gravitySG, float corrGravitySG,
|
|||||||
intDelay.save();
|
intDelay.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check if the server can reduce the buffer size to save memory (ESP8266 only)
|
||||||
|
//
|
||||||
|
void PushTarget::probeMaxFragement( String& serverPath ) {
|
||||||
|
#if defined(ESP8266) // Looks like this is feature is not supported by influxdb
|
||||||
|
// Format: http:://servername:port/path
|
||||||
|
int port = 443;
|
||||||
|
String host =
|
||||||
|
serverPath.substring(8); // remove the prefix or the probe will fail,
|
||||||
|
// it needs a pure host name.
|
||||||
|
// Remove the path if it exist
|
||||||
|
int idx = host.indexOf("/");
|
||||||
|
if (idx != -1) host = host.substring(0, idx);
|
||||||
|
|
||||||
|
// If a server port is defined, lets extract that part
|
||||||
|
idx = host.indexOf(":");
|
||||||
|
if (idx != -1) {
|
||||||
|
String p = host.substring(idx+1);
|
||||||
|
port = p.toInt();
|
||||||
|
host = host.substring(0, idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.notice(F("PUSH: Probing server to max fragment %s:%d" CR), host.c_str(), port);
|
||||||
|
if (_wifiSecure.probeMaxFragmentLength(host, port, 512)) {
|
||||||
|
Log.notice(F("PUSH: Server supports smaller SSL buffer." CR));
|
||||||
|
_wifiSecure.setBufferSizes(512, 512);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Send to influx db v2
|
// Send to influx db v2
|
||||||
//
|
//
|
||||||
@ -164,40 +194,27 @@ void PushTarget::sendInfluxDb2(TemplatingEngine& engine, bool isSecure) {
|
|||||||
"&bucket=" + String(myConfig.getInfluxDb2PushBucket());
|
"&bucket=" + String(myConfig.getInfluxDb2PushBucket());
|
||||||
String doc = engine.create(TemplatingEngine::TEMPLATE_INFLUX);
|
String doc = engine.create(TemplatingEngine::TEMPLATE_INFLUX);
|
||||||
|
|
||||||
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(myAdvancedConfig.getPushTimeout() * 1000);
|
|
||||||
_lastCode = _httpSecure.POST(doc);
|
|
||||||
} else {
|
|
||||||
_http.begin(_wifi, serverPath);
|
|
||||||
_http.setTimeout(myAdvancedConfig.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());
|
||||||
Log.verbose(F("PUSH: data %s." CR), doc.c_str());
|
Log.verbose(F("PUSH: data %s." CR), doc.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
String auth = "Token " + String(myConfig.getInfluxDb2PushToken());
|
String auth = "Token " + String(myConfig.getInfluxDb2PushToken());
|
||||||
_http.addHeader(F("Authorization"), auth.c_str());
|
|
||||||
_lastCode = _http.POST(doc);
|
if (isSecure) {
|
||||||
|
Log.notice(F("PUSH: InfluxDB, SSL enabled without validation." CR));
|
||||||
|
_wifiSecure.setInsecure();
|
||||||
|
probeMaxFragement( serverPath );
|
||||||
|
_httpSecure.setTimeout(myAdvancedConfig.getPushTimeout() * 1000);
|
||||||
|
_httpSecure.begin(_wifiSecure, serverPath);
|
||||||
|
_httpSecure.addHeader(F("Authorization"), auth.c_str());
|
||||||
|
_lastCode = _httpSecure.POST(doc);
|
||||||
|
} else {
|
||||||
|
_http.setTimeout(myAdvancedConfig.getPushTimeout() * 1000);
|
||||||
|
_http.begin(_wifi, serverPath);
|
||||||
|
_http.addHeader(F("Authorization"), auth.c_str());
|
||||||
|
_lastCode = _http.POST(doc);
|
||||||
|
}
|
||||||
|
|
||||||
if (_lastCode == 204) {
|
if (_lastCode == 204) {
|
||||||
_lastSuccess = true;
|
_lastSuccess = true;
|
||||||
@ -267,22 +284,9 @@ void PushTarget::sendHttpPost(TemplatingEngine& engine, bool isSecure,
|
|||||||
if (isSecure) {
|
if (isSecure) {
|
||||||
Log.notice(F("PUSH: HTTP, SSL enabled without validation." CR));
|
Log.notice(F("PUSH: HTTP, SSL enabled without validation." CR));
|
||||||
_wifiSecure.setInsecure();
|
_wifiSecure.setInsecure();
|
||||||
|
probeMaxFragement( serverPath );
|
||||||
#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: HTTP server supports smaller SSL buffer." CR));
|
|
||||||
_wifiSecure.setBufferSizes(512, 512);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_httpSecure.begin(_wifiSecure, serverPath);
|
|
||||||
_httpSecure.setTimeout(myAdvancedConfig.getPushTimeout() * 1000);
|
_httpSecure.setTimeout(myAdvancedConfig.getPushTimeout() * 1000);
|
||||||
|
_httpSecure.begin(_wifiSecure, serverPath);
|
||||||
|
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
addHttpHeader(_httpSecure, myConfig.getHttpHeader(0));
|
addHttpHeader(_httpSecure, myConfig.getHttpHeader(0));
|
||||||
@ -294,8 +298,8 @@ void PushTarget::sendHttpPost(TemplatingEngine& engine, bool isSecure,
|
|||||||
|
|
||||||
_lastCode = _httpSecure.POST(doc);
|
_lastCode = _httpSecure.POST(doc);
|
||||||
} else {
|
} else {
|
||||||
_http.begin(_wifi, serverPath);
|
|
||||||
_http.setTimeout(myAdvancedConfig.getPushTimeout() * 1000);
|
_http.setTimeout(myAdvancedConfig.getPushTimeout() * 1000);
|
||||||
|
_http.begin(_wifi, serverPath);
|
||||||
|
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
addHttpHeader(_http, myConfig.getHttpHeader(0));
|
addHttpHeader(_http, myConfig.getHttpHeader(0));
|
||||||
@ -349,26 +353,13 @@ void PushTarget::sendHttpGet(TemplatingEngine& engine, bool isSecure) {
|
|||||||
if (isSecure) {
|
if (isSecure) {
|
||||||
Log.notice(F("PUSH: HTTP, SSL enabled without validation." CR));
|
Log.notice(F("PUSH: HTTP, SSL enabled without validation." CR));
|
||||||
_wifiSecure.setInsecure();
|
_wifiSecure.setInsecure();
|
||||||
|
probeMaxFragement( serverPath );
|
||||||
#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: HTTP server supports smaller SSL buffer." CR));
|
|
||||||
_wifiSecure.setBufferSizes(512, 512);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_httpSecure.begin(_wifiSecure, serverPath);
|
|
||||||
_httpSecure.setTimeout(myAdvancedConfig.getPushTimeout() * 1000);
|
_httpSecure.setTimeout(myAdvancedConfig.getPushTimeout() * 1000);
|
||||||
|
_httpSecure.begin(_wifiSecure, serverPath);
|
||||||
_lastCode = _httpSecure.GET();
|
_lastCode = _httpSecure.GET();
|
||||||
} else {
|
} else {
|
||||||
_http.begin(_wifi, serverPath);
|
|
||||||
_http.setTimeout(myAdvancedConfig.getPushTimeout() * 1000);
|
_http.setTimeout(myAdvancedConfig.getPushTimeout() * 1000);
|
||||||
|
_http.begin(_wifi, serverPath);
|
||||||
_lastCode = _http.GET();
|
_lastCode = _http.GET();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,8 +407,10 @@ void PushTarget::sendMqtt(TemplatingEngine& engine, bool isSecure) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
mqtt.setTimeout(myAdvancedConfig.getPushTimeout() * 1000);
|
||||||
mqtt.begin(host.c_str(), port, _wifiSecure);
|
mqtt.begin(host.c_str(), port, _wifiSecure);
|
||||||
} else {
|
} else {
|
||||||
|
mqtt.setTimeout(myAdvancedConfig.getPushTimeout() * 1000);
|
||||||
mqtt.begin(host.c_str(), port, _wifi);
|
mqtt.begin(host.c_str(), port, _wifi);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,9 +422,6 @@ void PushTarget::sendMqtt(TemplatingEngine& engine, bool isSecure) {
|
|||||||
Log.verbose(F("PUSH: data %s." CR), doc.c_str());
|
Log.verbose(F("PUSH: data %s." CR), doc.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Send MQQT message(s)
|
|
||||||
mqtt.setTimeout(myAdvancedConfig.getPushTimeout()); // 10 seconds timeout
|
|
||||||
|
|
||||||
int lines = 1;
|
int lines = 1;
|
||||||
// Find out how many lines are in the document. Each line is one
|
// Find out how many lines are in the document. Each line is one
|
||||||
// topic/message. | is used as new line.
|
// topic/message. | is used as new line.
|
||||||
|
@ -45,6 +45,7 @@ class PushTarget {
|
|||||||
void sendHttpPost(TemplatingEngine& engine, bool isSecure, int index);
|
void sendHttpPost(TemplatingEngine& engine, bool isSecure, int index);
|
||||||
void sendHttpGet(TemplatingEngine& engine, bool isSecure);
|
void sendHttpGet(TemplatingEngine& engine, bool isSecure);
|
||||||
void addHttpHeader(HTTPClient& http, String header);
|
void addHttpHeader(HTTPClient& http, String header);
|
||||||
|
void probeMaxFragement( String& serverPath );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void sendAll(float angle, float gravitySG, float corrGravitySG, float tempC,
|
void sendAll(float angle, float gravitySG, float corrGravitySG, float tempC,
|
||||||
|
Loading…
Reference in New Issue
Block a user