From c84f5fe6073beb5e29e6f083532abfa8f1cf774b Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 5 Apr 2022 23:14:41 +0200 Subject: [PATCH] Add command ``IfxSensor 1`` to send non-teleperiod data to influxdb --- CHANGELOG.md | 2 +- RELEASENOTES.md | 2 +- tasmota/settings.h | 2 +- tasmota/xdrv_59_influxdb.ino | 19 +++++++++++++++++-- tasmota/xdrv_interface.ino | 2 +- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a715c1cf..8c189d9bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file. ## [11.0.0.5] ### Added - Support for improv as used by esp-web-tools -- Non-teleperiod data to influxdb +- Command ``IfxSensor 1`` to send non-teleperiod data to influxdb ### Changed - Remove support for Internet Explorer by allowing ECMAScript6 syntax using less JavaScript code bytes (#15280) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 7ad7dc9f7..487d6768d 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -110,6 +110,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo - Command ``SspmMap 0`` to reset Sonoff SPM default mapping - Command ``TcpConnect `` to add client connection mode [#14874](https://github.com/arendst/Tasmota/issues/14874) - Command ``RfTimeout 100..60000`` to disable duplicate RfReceive. Default 1000 [#15061](https://github.com/arendst/Tasmota/issues/15061) +- Command ``IfxSensor 1`` to send non-teleperiod data to influxdb - Commands ``Sensor12 D0 .. D5, S0 .. S5`` allowing differential or single-ended modes [#15001](https://github.com/arendst/Tasmota/issues/15001) - NeoPool commands ``NPpHMin``, ``NPpHMax``, ``NPpH``, ``NPRedox``, ``NPHydrolysis``, ``NPIonization``, ``NPChlorine`` and ``NPControl`` [#15015](https://github.com/arendst/Tasmota/issues/15015) - NeoPool system voltages display @@ -120,7 +121,6 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo - Support for PCF85363 RTC as used in Shelly 3EM [#13515](https://github.com/arendst/Tasmota/issues/13515) - Full RTC chip integration and synchronisation when using UBX (=GPS), NTP or manual time - NeoPool JSON modules, power module, cell info, chlorine, conductivity and ionization -- Non-teleperiod data to influxdb - ESP32 Berry always enable rules - ESP32 Berry bootloop protection - ESP32 support for BLE Mi scale V1 [#13517](https://github.com/arendst/Tasmota/issues/13517) diff --git a/tasmota/settings.h b/tasmota/settings.h index 1010fde1a..1acf9d376 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -252,7 +252,7 @@ typedef union { uint32_t influxdb_state : 1; // bit 7 (v9.5.0.5) - CMND_IFX - Enable influxdb support uint32_t sspm_display : 1; // bit 8 (v10.0.0.4) - CMND_SSPMDISPLAY - Enable gui display of powered on relays only uint32_t local_ntp_server : 1; // bit 9 (v11.0.0.4) - CMND_RTCNTPSERVER - Enable local NTP server - uint32_t spare10 : 1; // bit 10 + uint32_t influxdb_sensor : 1; // bit 10 (v11.0.0.5) - CMND_IFXSENSOR - Enable sensor support in addition to teleperiod support uint32_t spare11 : 1; // bit 11 uint32_t spare12 : 1; // bit 12 uint32_t spare13 : 1; // bit 13 diff --git a/tasmota/xdrv_59_influxdb.ino b/tasmota/xdrv_59_influxdb.ino index 21380fc80..999820427 100644 --- a/tasmota/xdrv_59_influxdb.ino +++ b/tasmota/xdrv_59_influxdb.ino @@ -38,6 +38,7 @@ * IfxOrg - Set Influxdb v2 and organization * IfxToken - Set Influxdb v2 and token * IfxPeriod - Set Influxdb period. If not set (or 0), use Teleperiod + * IfxSensor - Set Influxdb sensor logging off (0) or on (1) * * Set influxdb update interval with command teleperiod * @@ -365,6 +366,12 @@ void InfluxDbProcessJson(bool use_copy = false) { } } +void InfluxDbProcess(bool use_copy = false) { + if (Settings->sbflag1.influxdb_sensor) { + InfluxDbProcessJson(use_copy); + } +} + void InfluxDbPublishPowerState(uint32_t device) { Response_P(PSTR("{\"power%d\":\"%d\"}"), device, bitRead(TasmotaGlobal.power, device -1)); InfluxDbProcessJson(); @@ -419,6 +426,7 @@ void InfluxDbLoop(void) { #define D_CMND_INFLUXDBDATABASE "Database" #define D_CMND_INFLUXDBBUCKET "Bucket" #define D_CMND_INFLUXDBPERIOD "Period" +#define D_CMND_INFLUXDBSENSOR "Sensor" const char kInfluxDbCommands[] PROGMEM = D_PRFX_INFLUXDB "|" // Prefix "|" D_CMND_INFLUXDBLOG "|" @@ -426,7 +434,7 @@ const char kInfluxDbCommands[] PROGMEM = D_PRFX_INFLUXDB "|" // Prefix D_CMND_INFLUXDBUSER "|" D_CMND_INFLUXDBORG "|" D_CMND_INFLUXDBPASSWORD "|" D_CMND_INFLUXDBTOKEN "|" D_CMND_INFLUXDBDATABASE "|" D_CMND_INFLUXDBBUCKET "|" - D_CMND_INFLUXDBPERIOD; + D_CMND_INFLUXDBPERIOD "|" D_CMND_INFLUXDBSENSOR; void (* const InfluxCommand[])(void) PROGMEM = { &CmndInfluxDbState, &CmndInfluxDbLog, @@ -434,7 +442,7 @@ void (* const InfluxCommand[])(void) PROGMEM = { &CmndInfluxDbUser, &CmndInfluxDbUser, &CmndInfluxDbPassword, &CmndInfluxDbPassword, &CmndInfluxDbDatabase, &CmndInfluxDbDatabase, - &CmndInfluxDbPeriod }; + &CmndInfluxDbPeriod, &CmndInfluxDbSensor }; void InfluxDbReinit(void) { IFDB.init = false; @@ -459,6 +467,13 @@ void CmndInfluxDbState(void) { } } +void CmndInfluxDbSensor(void) { + if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) { + Settings->sbflag1.influxdb_sensor = XdrvMailbox.payload; + } + ResponseCmndStateText(Settings->sbflag1.influxdb_sensor); +} + void CmndInfluxDbLog(void) { if ((XdrvMailbox.payload >= LOG_LEVEL_NONE) && (XdrvMailbox.payload <= LOG_LEVEL_DEBUG_MORE)) { IFDB.log_level = XdrvMailbox.payload; diff --git a/tasmota/xdrv_interface.ino b/tasmota/xdrv_interface.ino index 6017ee95b..cec38d34e 100644 --- a/tasmota/xdrv_interface.ino +++ b/tasmota/xdrv_interface.ino @@ -1095,7 +1095,7 @@ bool XdrvRulesProcess(bool teleperiod, const char* event) { bool XdrvRulesProcess(bool teleperiod) { #ifdef USE_INFLUXDB if (!teleperiod) { // Only process ad-hoc data here - InfluxDbProcessJson(1); // Use a copy + InfluxDbProcess(1); // Use a copy } #endif