|
@ -11,18 +11,18 @@ Copyright (C) 2017 by Xose Pérez <xose dot perez at gmail dot com> |
|
|
#include "ESPAsyncTCP.h"
|
|
|
#include "ESPAsyncTCP.h"
|
|
|
#include "SyncClient.h"
|
|
|
#include "SyncClient.h"
|
|
|
|
|
|
|
|
|
bool _influxdb_enabled = false; |
|
|
|
|
|
SyncClient _influx_client; |
|
|
|
|
|
|
|
|
bool _idb_enabled = false; |
|
|
|
|
|
SyncClient _idb_client; |
|
|
|
|
|
|
|
|
template<typename T> bool influxDBSend(const char * topic, T payload) { |
|
|
|
|
|
|
|
|
template<typename T> bool idbSend(const char * topic, T payload) { |
|
|
|
|
|
|
|
|
if (!_influxdb_enabled) return true; |
|
|
|
|
|
|
|
|
if (!_idb_enabled) return true; |
|
|
if (!wifiConnected() || (WiFi.getMode() != WIFI_STA)) return true; |
|
|
if (!wifiConnected() || (WiFi.getMode() != WIFI_STA)) return true; |
|
|
|
|
|
|
|
|
DEBUG_MSG("[INFLUXDB] Sending\n"); |
|
|
DEBUG_MSG("[INFLUXDB] Sending\n"); |
|
|
|
|
|
|
|
|
_influx_client.setTimeout(2); |
|
|
|
|
|
if (!_influx_client.connect(getSetting("idbHost").c_str(), getSetting("idbPort", INFLUXDB_PORT).toInt())) { |
|
|
|
|
|
|
|
|
_idb_client.setTimeout(2); |
|
|
|
|
|
if (!_idb_client.connect(getSetting("idbHost").c_str(), getSetting("idbPort", INFLUXDB_PORT).toInt())) { |
|
|
DEBUG_MSG("[INFLUXDB] Connection failed\n"); |
|
|
DEBUG_MSG("[INFLUXDB] Connection failed\n"); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
@ -37,29 +37,30 @@ template<typename T> bool influxDBSend(const char * topic, T payload) { |
|
|
getSetting("idbHost").c_str(), getSetting("idbPort", INFLUXDB_PORT).toInt(), |
|
|
getSetting("idbHost").c_str(), getSetting("idbPort", INFLUXDB_PORT).toInt(), |
|
|
strlen(data), data); |
|
|
strlen(data), data); |
|
|
|
|
|
|
|
|
if (_influx_client.printf(request) > 0) { |
|
|
|
|
|
while (_influx_client.connected() && _influx_client.available() == 0) delay(1); |
|
|
|
|
|
while (_influx_client.available()) _influx_client.read(); |
|
|
|
|
|
if (_influx_client.connected()) _influx_client.stop(); |
|
|
|
|
|
|
|
|
if (_idb_client.printf(request) > 0) { |
|
|
|
|
|
while (_idb_client.connected() && _idb_client.available() == 0) delay(1); |
|
|
|
|
|
while (_idb_client.available()) _idb_client.read(); |
|
|
|
|
|
if (_idb_client.connected()) _idb_client.stop(); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
_influx_client.stop(); |
|
|
|
|
|
|
|
|
_idb_client.stop(); |
|
|
DEBUG_MSG("[INFLUXDB] Sent failed\n"); |
|
|
DEBUG_MSG("[INFLUXDB] Sent failed\n"); |
|
|
while (_influx_client.connected()) delay(0); |
|
|
|
|
|
|
|
|
while (_idb_client.connected()) delay(0); |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
bool influxdbEnabled() { |
|
|
|
|
|
return _influxdb_enabled; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool idbEnabled() { |
|
|
|
|
|
return _idb_enabled; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void influxDBConfigure() { |
|
|
|
|
|
_influxdb_enabled = getSetting("idbHost").length() > 0; |
|
|
|
|
|
|
|
|
void idbConfigure() { |
|
|
|
|
|
_idb_enabled = getSetting("idbHost").length() > 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void influxDBSetup() { |
|
|
|
|
|
influxDBConfigure(); |
|
|
|
|
|
|
|
|
void idbSetup() { |
|
|
|
|
|
idbConfigure(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#endif
|
|
|
#endif
|