add IfxPeriod

This commit is contained in:
Barbudor 2021-11-20 22:35:07 +01:00
parent 476c2b3dc0
commit 235bf403c6
2 changed files with 21 additions and 5 deletions

View File

@ -598,7 +598,8 @@ typedef struct {
int8_t shutter_tilt_config[5][MAX_SHUTTERS]; //508
int8_t shutter_tilt_pos[MAX_SHUTTERS]; //51C
uint8_t free_520[12]; // 520
uint16_t influxdb_period; // 520
uint8_t free_522[10]; // 522
uint16_t mqtt_keepalive; // 52C
uint16_t mqtt_socket_timeout; // 52E

View File

@ -37,6 +37,7 @@
* IfxBucket - Set Influxdb v2 and bucket name
* IfxOrg - Set Influxdb v2 and organization
* IfxToken - Set Influxdb v2 and token
* IfxPeriod - Set Influxdb period. If not set (or 0), use Teleperiod
*
* Set influxdb update interval with command teleperiod
*
@ -364,8 +365,9 @@ void InfluxDbPublishPowerState(uint32_t device) {
void InfluxDbLoop(void) {
if (!TasmotaGlobal.global_state.network_down) {
IFDB.interval--;
if (IFDB.interval <= 0 || IFDB.interval > Settings->tele_period) {
IFDB.interval = Settings->tele_period;
uint16_t period = Settings->influxdb_period ? Settings->influxdb_period : Settings->tele_period;
if (IFDB.interval <= 0 || IFDB.interval > period) {
IFDB.interval = period;
if (!IFDB.init) {
if (InfluxDbParameterInit()) {
IFDB.init = InfluxDbValidateConnection();
@ -408,20 +410,23 @@ void InfluxDbLoop(void) {
#define D_CMND_INFLUXDBTOKEN "Token"
#define D_CMND_INFLUXDBDATABASE "Database"
#define D_CMND_INFLUXDBBUCKET "Bucket"
#define D_CMND_INFLUXDBPERIOD "Period"
const char kInfluxDbCommands[] PROGMEM = D_PRFX_INFLUXDB "|" // Prefix
"|" D_CMND_INFLUXDBLOG "|"
D_CMND_INFLUXDBHOST "|" D_CMND_INFLUXDBPORT "|"
D_CMND_INFLUXDBUSER "|" D_CMND_INFLUXDBORG "|"
D_CMND_INFLUXDBPASSWORD "|" D_CMND_INFLUXDBTOKEN "|"
D_CMND_INFLUXDBDATABASE "|" D_CMND_INFLUXDBBUCKET;
D_CMND_INFLUXDBDATABASE "|" D_CMND_INFLUXDBBUCKET "|"
D_CMND_INFLUXDBPERIOD;
void (* const InfluxCommand[])(void) PROGMEM = {
&CmndInfluxDbState, &CmndInfluxDbLog,
&CmndInfluxDbHost, &CmndInfluxDbPort,
&CmndInfluxDbUser, &CmndInfluxDbUser,
&CmndInfluxDbPassword, &CmndInfluxDbPassword,
&CmndInfluxDbDatabase, &CmndInfluxDbDatabase };
&CmndInfluxDbDatabase, &CmndInfluxDbDatabase,
&CmndInfluxDbPeriod };
void InfluxDbReinit(void) {
IFDB.init = false;
@ -504,6 +509,16 @@ void CmndInfluxDbDatabase(void) {
ResponseCmndChar(SettingsText(SET_INFLUXDB_BUCKET));
}
void CmndInfluxDbPeriod(void) {
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 3601)) {
Settings->influxdb_period = XdrvMailbox.payload;
if(Settings->influxdb_period > 0 && Settings->influxdb_period < 10) {
Settings->influxdb_period = 10;
}
}
ResponseCmndNumber(Settings->influxdb_period);
}
/*********************************************************************************************\
* Interface
\*********************************************************************************************/