Added advanced settings
This commit is contained in:
@ -32,6 +32,74 @@ SOFTWARE.
|
||||
#include <pushtarget.hpp>
|
||||
#include <wifi.hpp>
|
||||
|
||||
#define PUSHINT_FILENAME "/push.dat"
|
||||
|
||||
//
|
||||
// Decrease counters
|
||||
//
|
||||
void PushIntervalTracker::update(const int index, const int defaultValue) {
|
||||
if (_counters[index] <= 0)
|
||||
_counters[index] = defaultValue;
|
||||
else
|
||||
_counters[index]--;
|
||||
}
|
||||
|
||||
//
|
||||
// Load data from file
|
||||
//
|
||||
void PushIntervalTracker::load() {
|
||||
File intFile = LittleFS.open(PUSHINT_FILENAME, "r");
|
||||
int i = 0;
|
||||
|
||||
if (intFile) {
|
||||
String line = intFile.readStringUntil('\n');
|
||||
Log.notice(F("PUSH: Read interval tracker %s." CR), line.c_str());
|
||||
|
||||
char temp[80];
|
||||
char *s, *p = &temp[0];
|
||||
int i = 0;
|
||||
|
||||
snprintf(&temp[0], sizeof(temp), "%s", line.c_str());
|
||||
while ((s = strtok_r(p, ":", &p)) != NULL) {
|
||||
_counters[i++] = atoi(s);
|
||||
}
|
||||
|
||||
intFile.close();
|
||||
}
|
||||
|
||||
#if !defined(PUSH_DISABLE_LOGGING)
|
||||
Log.verbose(F("PUSH: Parsed trackers: %d:%d:%d:%d:%d." CR), _counters[0], _counters[1], _counters[2], _counters[3], _counters[4] );
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
// Update and save counters
|
||||
//
|
||||
void PushIntervalTracker::save() {
|
||||
update(0, myAdvancedConfig.getPushIntervalHttp1());
|
||||
update(1, myAdvancedConfig.getPushIntervalHttp2());
|
||||
update(2, myAdvancedConfig.getPushIntervalHttp3());
|
||||
update(3, myAdvancedConfig.getPushIntervalInflux());
|
||||
update(4, myAdvancedConfig.getPushIntervalMqtt());
|
||||
|
||||
// If this feature is disabled we skip saving the file
|
||||
if (!myAdvancedConfig.isPushIntervalActive()) {
|
||||
#if !defined(PUSH_DISABLE_LOGGING)
|
||||
Log.notice(F("PUSH: Variabled push interval disabled." CR));
|
||||
#endif
|
||||
LittleFS.remove(PUSHINT_FILENAME);
|
||||
} else {
|
||||
Log.notice(F("PUSH: Variabled push interval enabled, updating counters." CR));
|
||||
File intFile = LittleFS.open(PUSHINT_FILENAME, "w");
|
||||
|
||||
if (intFile) {
|
||||
// Format=http1:http2:http3:influx:mqtt
|
||||
intFile.printf("%d:%d:%d:%d:%d\n", _counters[0], _counters[1], _counters[2], _counters[3], _counters[4] );
|
||||
intFile.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Send the data to targets
|
||||
//
|
||||
@ -44,35 +112,40 @@ void PushTarget::sendAll(float angle, float gravitySG, float corrGravitySG,
|
||||
TemplatingEngine engine;
|
||||
engine.initialize(angle, gravitySG, corrGravitySG, tempC, runTime);
|
||||
|
||||
if (myConfig.isHttpActive()) {
|
||||
PushIntervalTracker intDelay;
|
||||
intDelay.load();
|
||||
|
||||
if (myConfig.isHttpActive() && intDelay.useHttp1()) {
|
||||
LOG_PERF_START("push-http");
|
||||
sendHttpPost(engine, myConfig.isHttpSSL(), 0);
|
||||
LOG_PERF_STOP("push-http");
|
||||
}
|
||||
|
||||
if (myConfig.isHttp2Active()) {
|
||||
if (myConfig.isHttp2Active() && intDelay.useHttp2()) {
|
||||
LOG_PERF_START("push-http2");
|
||||
sendHttpPost(engine, myConfig.isHttp2SSL(), 1);
|
||||
LOG_PERF_STOP("push-http2");
|
||||
}
|
||||
|
||||
if (myConfig.isHttp3Active()) {
|
||||
if (myConfig.isHttp3Active() && intDelay.useHttp3()) {
|
||||
LOG_PERF_START("push-http3");
|
||||
sendHttpGet(engine, myConfig.isHttp3SSL());
|
||||
LOG_PERF_STOP("push-http3");
|
||||
}
|
||||
|
||||
if (myConfig.isInfluxDb2Active()) {
|
||||
if (myConfig.isInfluxDb2Active() && intDelay.useInflux()) {
|
||||
LOG_PERF_START("push-influxdb2");
|
||||
sendInfluxDb2(engine, myConfig.isInfluxSSL());
|
||||
LOG_PERF_STOP("push-influxdb2");
|
||||
}
|
||||
|
||||
if (myConfig.isMqttActive()) {
|
||||
if (myConfig.isMqttActive() && intDelay.useMqtt()) {
|
||||
LOG_PERF_START("push-mqtt");
|
||||
sendMqtt(engine, myConfig.isMqttSSL());
|
||||
LOG_PERF_STOP("push-mqtt");
|
||||
}
|
||||
|
||||
intDelay.save();
|
||||
}
|
||||
|
||||
//
|
||||
@ -109,11 +182,11 @@ void PushTarget::sendInfluxDb2(TemplatingEngine& engine, bool isSecure) {
|
||||
#endif
|
||||
|
||||
_httpSecure.begin(_wifiSecure, serverPath);
|
||||
_httpSecure.setTimeout(myHardwareConfig.getPushTimeout() * 1000);
|
||||
_httpSecure.setTimeout(myAdvancedConfig.getPushTimeout() * 1000);
|
||||
_lastCode = _httpSecure.POST(doc);
|
||||
} else {
|
||||
_http.begin(_wifi, serverPath);
|
||||
_http.setTimeout(myHardwareConfig.getPushTimeout() * 1000);
|
||||
_http.setTimeout(myAdvancedConfig.getPushTimeout() * 1000);
|
||||
_lastCode = _http.POST(doc);
|
||||
}
|
||||
|
||||
@ -209,7 +282,7 @@ void PushTarget::sendHttpPost(TemplatingEngine& engine, bool isSecure,
|
||||
#endif
|
||||
|
||||
_httpSecure.begin(_wifiSecure, serverPath);
|
||||
_httpSecure.setTimeout(myHardwareConfig.getPushTimeout() * 1000);
|
||||
_httpSecure.setTimeout(myAdvancedConfig.getPushTimeout() * 1000);
|
||||
|
||||
if (index == 0) {
|
||||
addHttpHeader(_httpSecure, myConfig.getHttpHeader(0));
|
||||
@ -222,7 +295,7 @@ void PushTarget::sendHttpPost(TemplatingEngine& engine, bool isSecure,
|
||||
_lastCode = _httpSecure.POST(doc);
|
||||
} else {
|
||||
_http.begin(_wifi, serverPath);
|
||||
_http.setTimeout(myHardwareConfig.getPushTimeout() * 1000);
|
||||
_http.setTimeout(myAdvancedConfig.getPushTimeout() * 1000);
|
||||
|
||||
if (index == 0) {
|
||||
addHttpHeader(_http, myConfig.getHttpHeader(0));
|
||||
@ -291,11 +364,11 @@ void PushTarget::sendHttpGet(TemplatingEngine& engine, bool isSecure) {
|
||||
#endif
|
||||
|
||||
_httpSecure.begin(_wifiSecure, serverPath);
|
||||
_httpSecure.setTimeout(myHardwareConfig.getPushTimeout() * 1000);
|
||||
_httpSecure.setTimeout(myAdvancedConfig.getPushTimeout() * 1000);
|
||||
_lastCode = _httpSecure.GET();
|
||||
} else {
|
||||
_http.begin(_wifi, serverPath);
|
||||
_http.setTimeout(myHardwareConfig.getPushTimeout() * 1000);
|
||||
_http.setTimeout(myAdvancedConfig.getPushTimeout() * 1000);
|
||||
_lastCode = _http.GET();
|
||||
}
|
||||
|
||||
@ -357,7 +430,7 @@ void PushTarget::sendMqtt(TemplatingEngine& engine, bool isSecure) {
|
||||
#endif
|
||||
|
||||
// Send MQQT message(s)
|
||||
mqtt.setTimeout(myHardwareConfig.getPushTimeout()); // 10 seconds timeout
|
||||
mqtt.setTimeout(myAdvancedConfig.getPushTimeout()); // 10 seconds timeout
|
||||
|
||||
int lines = 1;
|
||||
// Find out how many lines are in the document. Each line is one
|
||||
|
Reference in New Issue
Block a user