Browse Source

Rename influxDB methods

fastled
Xose Pérez 7 years ago
parent
commit
462204b368
12 changed files with 42 additions and 38 deletions
  1. +3
    -0
      code/espurna/alexa.ino
  2. +1
    -1
      code/espurna/analog.ino
  3. +1
    -1
      code/espurna/config/prototypes.h
  4. +1
    -1
      code/espurna/counter.ino
  5. +2
    -2
      code/espurna/dht.ino
  6. +1
    -1
      code/espurna/ds18b20.ino
  7. +1
    -1
      code/espurna/espurna.ino
  8. +19
    -18
      code/espurna/influxdb.ino
  9. +9
    -9
      code/espurna/power.ino
  10. +1
    -1
      code/espurna/relay.ino
  11. +2
    -2
      code/espurna/utils.ino
  12. +1
    -1
      code/espurna/ws.ino

+ 3
- 0
code/espurna/alexa.ino View File

@ -20,6 +20,8 @@ bool _alexa_change = false;
unsigned int _alexa_device_id = 0;
bool _alexa_state = false;
// -----------------------------------------------------------------------------
void alexaConfigure() {
alexa.enable(getSetting("alexaEnabled", ALEXA_ENABLED).toInt() == 1);
}
@ -29,6 +31,7 @@ void alexaSetup() {
// Backwards compatibility
moveSetting("fauxmoEnabled", "alexaEnabled");
// Load & cache settings
alexaConfigure();
unsigned int relays = relayCount();


+ 1
- 1
code/espurna/analog.ino View File

@ -51,7 +51,7 @@ void analogLoop() {
// Send to InfluxDB
#if INFLUXDB_SUPPORT
influxDBSend(MQTT_TOPIC_ANALOG, analog);
idbSend(MQTT_TOPIC_ANALOG, analog);
#endif
// Update websocket clients


+ 1
- 1
code/espurna/config/prototypes.h View File

@ -20,6 +20,6 @@ template<typename T> String getSetting(const String& key, unsigned int index, T
template<typename T> void domoticzSend(const char * key, T value);
template<typename T> void domoticzSend(const char * key, T nvalue, const char * svalue);
template<typename T> bool influxDBSend(const char * topic, T payload);
template<typename T> bool idbSend(const char * topic, T payload);
char * ltrim(char * s);

+ 1
- 1
code/espurna/counter.ino View File

@ -80,7 +80,7 @@ void counterLoop() {
// Send to InfluxDB
#if INFLUXDB_SUPPORT
influxDBSend(COUNTER_TOPIC, _counterValue);
idbSend(COUNTER_TOPIC, _counterValue);
#endif
}


+ 2
- 2
code/espurna/dht.ino View File

@ -208,8 +208,8 @@ void dhtLoop() {
#endif
#if INFLUXDB_SUPPORT
influxDBSend(getSetting("dhtTmpTopic", DHT_TEMPERATURE_TOPIC).c_str(), temperature);
influxDBSend(getSetting("dhtHumTopic", DHT_HUMIDITY_TOPIC).c_str(), humidity);
idbSend(getSetting("dhtTmpTopic", DHT_TEMPERATURE_TOPIC).c_str(), temperature);
idbSend(getSetting("dhtHumTopic", DHT_HUMIDITY_TOPIC).c_str(), humidity);
#endif
// Update websocket clients


+ 1
- 1
code/espurna/ds18b20.ino View File

@ -115,7 +115,7 @@ void dsLoop() {
#endif
#if INFLUXDB_SUPPORT
influxDBSend(getSetting("dsTmpTopic", DS18B20_TEMPERATURE_TOPIC).c_str(), _dsTemperatureStr);
idbSend(getSetting("dsTmpTopic", DS18B20_TEMPERATURE_TOPIC).c_str(), _dsTemperatureStr);
#endif
}


+ 1
- 1
code/espurna/espurna.ino View File

@ -287,7 +287,7 @@ void setup() {
nofussSetup();
#endif
#if INFLUXDB_SUPPORT
influxDBSetup();
idbSetup();
#endif
#if DS18B20_SUPPORT
dsSetup();


+ 19
- 18
code/espurna/influxdb.ino View File

@ -11,18 +11,18 @@ Copyright (C) 2017 by Xose Pérez <xose dot perez at gmail dot com>
#include "ESPAsyncTCP.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;
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");
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(),
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;
}
_influx_client.stop();
_idb_client.stop();
DEBUG_MSG("[INFLUXDB] Sent failed\n");
while (_influx_client.connected()) delay(0);
while (_idb_client.connected()) delay(0);
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

+ 9
- 9
code/espurna/power.ino View File

@ -234,16 +234,16 @@ void _powerReport() {
#endif
#if INFLUXDB_SUPPORT
if (influxdbEnabled()) {
influxDBSend(MQTT_TOPIC_CURRENT, buf_current);
influxDBSend(MQTT_TOPIC_POWER_APPARENT, String((int) _power_apparent).c_str());
influxDBSend(MQTT_TOPIC_ENERGY_DELTA, buf_energy_delta);
influxDBSend(MQTT_TOPIC_ENERGY_TOTAL, buf_energy_total);
if (idbEnabled()) {
idbSend(MQTT_TOPIC_CURRENT, buf_current);
idbSend(MQTT_TOPIC_POWER_APPARENT, String((int) _power_apparent).c_str());
idbSend(MQTT_TOPIC_ENERGY_DELTA, buf_energy_delta);
idbSend(MQTT_TOPIC_ENERGY_TOTAL, buf_energy_total);
#if POWER_HAS_ACTIVE
influxDBSend(MQTT_TOPIC_POWER_ACTIVE, String((int) _power_active).c_str());
influxDBSend(MQTT_TOPIC_POWER_REACTIVE, String((int) _power_reactive).c_str());
influxDBSend(MQTT_TOPIC_VOLTAGE, String((int) _power_voltage).c_str());
influxDBSend(MQTT_TOPIC_POWER_FACTOR, String((int) 100 * _power_factor).c_str());
idbSend(MQTT_TOPIC_POWER_ACTIVE, String((int) _power_active).c_str());
idbSend(MQTT_TOPIC_POWER_REACTIVE, String((int) _power_reactive).c_str());
idbSend(MQTT_TOPIC_VOLTAGE, String((int) _power_voltage).c_str());
idbSend(MQTT_TOPIC_POWER_FACTOR, String((int) 100 * _power_factor).c_str());
#endif
}
#endif


+ 1
- 1
code/espurna/relay.ino View File

@ -493,7 +493,7 @@ void relayInfluxDB(unsigned char id) {
if (id >= _relays.size()) return;
char buffer[10];
snprintf_P(buffer, sizeof(buffer), PSTR("%s,id=%d"), MQTT_TOPIC_RELAY, id);
influxDBSend(buffer, relayStatus(id) ? "1" : "0");
idbSend(buffer, relayStatus(id) ? "1" : "0");
}
#endif


+ 2
- 2
code/espurna/utils.ino View File

@ -96,13 +96,13 @@ void heartbeat() {
#if (HEARTBEAT_REPORT_UPTIME)
mqttSend(MQTT_TOPIC_UPTIME, String(uptime_seconds).c_str());
#if INFLUXDB_SUPPORT
influxDBSend(MQTT_TOPIC_UPTIME, String(uptime_seconds).c_str());
idbSend(MQTT_TOPIC_UPTIME, String(uptime_seconds).c_str());
#endif
#endif
#if (HEARTBEAT_REPORT_FREEHEAP)
mqttSend(MQTT_TOPIC_FREEHEAP, String(free_heap).c_str());
#if INFLUXDB_SUPPORT
influxDBSend(MQTT_TOPIC_FREEHEAP, String(free_heap).c_str());
idbSend(MQTT_TOPIC_FREEHEAP, String(free_heap).c_str());
#endif
#endif
#if (HEARTBEAT_REPORT_RELAY)


+ 1
- 1
code/espurna/ws.ino View File

@ -367,7 +367,7 @@ void _wsParse(AsyncWebSocketClient *client, uint8_t * payload, size_t length) {
alexaConfigure();
#endif
#if INFLUXDB_SUPPORT
influxDBConfigure();
idbConfigure();
#endif
#if DOMOTICZ_SUPPORT
domoticzConfigure();


Loading…
Cancel
Save