diff --git a/CHANGELOG.md b/CHANGELOG.md index 10889660d..2a715c1cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +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 ### 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 b77ef3e22..7ad7dc9f7 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -120,6 +120,7 @@ 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/xdrv_59_influxdb.ino b/tasmota/xdrv_59_influxdb.ino index 435a3ed2f..21380fc80 100644 --- a/tasmota/xdrv_59_influxdb.ino +++ b/tasmota/xdrv_59_influxdb.ino @@ -257,15 +257,19 @@ char* InfluxDbNumber(char* alternative, JsonParserToken value) { return nullptr; } -void InfluxDbProcessJson(void) { +void InfluxDbProcessJson(bool use_copy = false) { if (!IFDB.init) { return; } - AddLog(IFDB.log_level, PSTR("IFX: Process %s"), ResponseData()); + char *json_data = ResponseData(); + if (use_copy) { + json_data = (char*)malloc(ResponseSize()+2); + if (!json_data) { return; } + strlcpy(json_data, ResponseData(), ResponseSize()); + } -// String jsonStr = ResponseData(); // Make a copy before use -// JsonParser parser((char *)jsonStr.c_str()); - JsonParser parser((char *)ResponseData()); // Destroys ResponseData but saves heap space + AddLog(IFDB.log_level, PSTR("IFX: Process %s"), json_data); + JsonParser parser(json_data); // Destroys json_data JsonParserObject root = parser.getRootObject(); if (root) { char number[12]; // '1' to '255' @@ -355,6 +359,10 @@ void InfluxDbProcessJson(void) { InfluxDbPostData(data.c_str()); } } + + if (use_copy) { + free(json_data); + } } void InfluxDbPublishPowerState(uint32_t device) { diff --git a/tasmota/xdrv_interface.ino b/tasmota/xdrv_interface.ino index dcf763935..6017ee95b 100644 --- a/tasmota/xdrv_interface.ino +++ b/tasmota/xdrv_interface.ino @@ -1093,8 +1093,14 @@ 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 + } +#endif + bool result = XdrvRulesProcess(teleperiod, ResponseData()); - ResponseClear(); // Free heap space + ResponseClear(); // Free heap space return result; }