mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-19 16:56:34 +00:00
Move influxdb support from sensor to driver
This commit is contained in:
parent
05d0507104
commit
d0d0d11b15
@ -392,6 +392,7 @@
|
|||||||
|
|
||||||
// -- Influxdb ------------------------------------
|
// -- Influxdb ------------------------------------
|
||||||
//#define USE_INFLUXDB // Enable influxdb support (+5k code)
|
//#define USE_INFLUXDB // Enable influxdb support (+5k code)
|
||||||
|
// #define INFLUXDB_STATE 0 // [Ifx] Influxdb initially Off (0) or On (1)
|
||||||
// #define INFLUXDB_VERSION 1 // Version of Influxdb 1 or 2
|
// #define INFLUXDB_VERSION 1 // Version of Influxdb 1 or 2
|
||||||
// #define INFLUXDB_HOST "influxdb" // [IfxHost] Influxdb hostname or IP address
|
// #define INFLUXDB_HOST "influxdb" // [IfxHost] Influxdb hostname or IP address
|
||||||
// #define INFLUXDB_PORT 8086 // [IfxPort] Influxdb port number
|
// #define INFLUXDB_PORT 8086 // [IfxPort] Influxdb port number
|
||||||
|
@ -248,8 +248,8 @@ typedef union {
|
|||||||
uint32_t range_extender : 1; // bit 3 (v9.5.0.5) - CMND_RGXSTATE - Enable range extender
|
uint32_t range_extender : 1; // bit 3 (v9.5.0.5) - CMND_RGXSTATE - Enable range extender
|
||||||
uint32_t range_extender_napt : 1; // bit 4 (v9.5.0.5) - CMND_RGXNAPT - Enable range extender NAPT
|
uint32_t range_extender_napt : 1; // bit 4 (v9.5.0.5) - CMND_RGXNAPT - Enable range extender NAPT
|
||||||
uint32_t sonoff_l1_music_sync : 1; // bit 5 (v9.5.0.5) - CMND_L1MUSICSYNC - Enable sync to music
|
uint32_t sonoff_l1_music_sync : 1; // bit 5 (v9.5.0.5) - CMND_L1MUSICSYNC - Enable sync to music
|
||||||
uint32_t influxdb_default : 1; // bit 6 (v9.5.0.5) - Set initial defaults if 0
|
uint32_t influxdb_default : 1; // bit 6 (v9.5.0.5) - Set influxdb initial defaults if 0
|
||||||
uint32_t spare07 : 1; // bit 7
|
uint32_t influxdb_state : 1; // bit 7 (v9.5.0.5) - CMND_IFX - Enable influxdb support
|
||||||
uint32_t spare08 : 1; // bit 8
|
uint32_t spare08 : 1; // bit 8
|
||||||
uint32_t spare09 : 1; // bit 9
|
uint32_t spare09 : 1; // bit 9
|
||||||
uint32_t spare10 : 1; // bit 10
|
uint32_t spare10 : 1; // bit 10
|
||||||
|
@ -760,7 +760,7 @@ void ResponseAppendFeatures(void)
|
|||||||
feature8 |= 0x00000400; // xdrv_58_range_extender.ino
|
feature8 |= 0x00000400; // xdrv_58_range_extender.ino
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_INFLUXDB
|
#ifdef USE_INFLUXDB
|
||||||
feature8 |= 0x00000800; // xsns_90_influxdb.ino
|
feature8 |= 0x00000800; // xdrv_59_influxdb.ino
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// feature8 |= 0x00001000;
|
// feature8 |= 0x00001000;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
xsns_90_influxdb.ino - Influxdb support for Tasmota
|
xdrv_59_influxdb.ino - Influxdb support for Tasmota
|
||||||
|
|
||||||
Copyright (C) 2021 Theo Arends
|
Copyright (C) 2021 Theo Arends
|
||||||
|
|
||||||
@ -28,7 +28,7 @@
|
|||||||
* https://docs.influxdata.com/influxdb/v1.8/write_protocols/line_protocol_reference/
|
* https://docs.influxdata.com/influxdb/v1.8/write_protocols/line_protocol_reference/
|
||||||
*
|
*
|
||||||
* Supported commands:
|
* Supported commands:
|
||||||
* Ifx - Show current state
|
* Ifx - Set Influxdb state off (0) or on (1) and show current state
|
||||||
* IfxHost - Set Influxdb host name or IP address
|
* IfxHost - Set Influxdb host name or IP address
|
||||||
* IfxPort - Set Influxdb port
|
* IfxPort - Set Influxdb port
|
||||||
* IfxDatabase - Set Influxdb v1 and database name
|
* IfxDatabase - Set Influxdb v1 and database name
|
||||||
@ -41,10 +41,13 @@
|
|||||||
* Set influxdb update interval with command teleperiod
|
* Set influxdb update interval with command teleperiod
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
#define XSNS_90 90
|
#define XDRV_59 59
|
||||||
|
|
||||||
#define INFLUXDB_INITIAL 7 // Initial number of seconds after wifi connect keeping in mind sensor initialization
|
#define INFLUXDB_INITIAL 7 // Initial number of seconds after wifi connect keeping in mind sensor initialization
|
||||||
|
|
||||||
|
#ifndef INFLUXDB_STATE
|
||||||
|
#define INFLUXDB_STATE 0 // [Ifx] Influxdb initially Off (0) or On (1)
|
||||||
|
#endif
|
||||||
#ifndef INFLUXDB_VERSION
|
#ifndef INFLUXDB_VERSION
|
||||||
#define INFLUXDB_VERSION 1 // Version of Influxdb 1 or 2
|
#define INFLUXDB_VERSION 1 // Version of Influxdb 1 or 2
|
||||||
#endif
|
#endif
|
||||||
@ -405,8 +408,14 @@ void InfluxDbReinit(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CmndInfluxDbState(void) {
|
void CmndInfluxDbState(void) {
|
||||||
Response_P(PSTR("{\"" D_PRFX_INFLUXDB "\":{\"" D_CMND_INFLUXDBHOST "\":\"%s\",\"" D_CMND_INFLUXDBPORT "\":%d,\"Version\":%d"),
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
|
||||||
SettingsText(SET_INFLUXDB_HOST), Settings->influxdb_port, Settings->influxdb_version);
|
if (Settings->sbflag1.influxdb_state != XdrvMailbox.payload) {
|
||||||
|
Settings->sbflag1.influxdb_state = XdrvMailbox.payload;
|
||||||
|
InfluxDbReinit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Response_P(PSTR("{\"" D_PRFX_INFLUXDB "\":{\"State\":\"%s\",\"" D_CMND_INFLUXDBHOST "\":\"%s\",\"" D_CMND_INFLUXDBPORT "\":%d,\"Version\":%d"),
|
||||||
|
GetStateText(Settings->sbflag1.influxdb_state), SettingsText(SET_INFLUXDB_HOST), Settings->influxdb_port, Settings->influxdb_version);
|
||||||
if (1 == Settings->influxdb_version) {
|
if (1 == Settings->influxdb_version) {
|
||||||
ResponseAppend_P(PSTR(",\"" D_CMND_INFLUXDBDATABASE "\":\"%s\",\"" D_CMND_INFLUXDBUSER "\":\"%s\"}}"),
|
ResponseAppend_P(PSTR(",\"" D_CMND_INFLUXDBDATABASE "\":\"%s\",\"" D_CMND_INFLUXDBUSER "\":\"%s\"}}"),
|
||||||
SettingsText(SET_INFLUXDB_BUCKET), SettingsText(SET_INFLUXDB_ORG));
|
SettingsText(SET_INFLUXDB_BUCKET), SettingsText(SET_INFLUXDB_ORG));
|
||||||
@ -471,26 +480,29 @@ void CmndInfluxDbDatabase(void) {
|
|||||||
* Interface
|
* Interface
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
bool Xsns90(uint8_t function) {
|
bool Xdrv59(uint8_t function) {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
if (!Settings->sbflag1.influxdb_default) {
|
if (FUNC_PRE_INIT == function) {
|
||||||
Settings->influxdb_version = INFLUXDB_VERSION;
|
// Initial persistent settings executed only once
|
||||||
Settings->influxdb_port = INFLUXDB_PORT;
|
if (!Settings->sbflag1.influxdb_default) {
|
||||||
SettingsUpdateText(SET_INFLUXDB_HOST, PSTR(INFLUXDB_HOST));
|
Settings->sbflag1.influxdb_state = INFLUXDB_STATE;
|
||||||
SettingsUpdateText(SET_INFLUXDB_ORG, PSTR(INFLUXDB_ORG));
|
Settings->influxdb_version = INFLUXDB_VERSION;
|
||||||
SettingsUpdateText(SET_INFLUXDB_TOKEN, PSTR(INFLUXDB_TOKEN));
|
Settings->influxdb_port = INFLUXDB_PORT;
|
||||||
SettingsUpdateText(SET_INFLUXDB_BUCKET, PSTR(INFLUXDB_BUCKET));
|
SettingsUpdateText(SET_INFLUXDB_HOST, PSTR(INFLUXDB_HOST));
|
||||||
Settings->sbflag1.influxdb_default = 1;
|
SettingsUpdateText(SET_INFLUXDB_ORG, PSTR(INFLUXDB_ORG));
|
||||||
}
|
SettingsUpdateText(SET_INFLUXDB_TOKEN, PSTR(INFLUXDB_TOKEN));
|
||||||
|
SettingsUpdateText(SET_INFLUXDB_BUCKET, PSTR(INFLUXDB_BUCKET));
|
||||||
switch (function) {
|
Settings->sbflag1.influxdb_default = 1;
|
||||||
case FUNC_EVERY_SECOND:
|
}
|
||||||
InfluxDbLoop();
|
} else if (FUNC_COMMAND == function) {
|
||||||
break;
|
result = DecodeCommand(kInfluxDbCommands, InfluxCommand);
|
||||||
case FUNC_COMMAND:
|
} else if (Settings->sbflag1.influxdb_state) {
|
||||||
result = DecodeCommand(kInfluxDbCommands, InfluxCommand);
|
switch (function) {
|
||||||
break;
|
case FUNC_EVERY_SECOND:
|
||||||
|
InfluxDbLoop();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user