From 481cc63bf41b209401c0c99243d7405583178c57 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 3 Jan 2023 17:50:39 +0100 Subject: [PATCH] Add script support to Energy Modbus --- tasmota/energy_modbus_configs/configurations.md | 4 +++- tasmota/tasmota_xnrg_energy/xnrg_29_modbus.ino | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tasmota/energy_modbus_configs/configurations.md b/tasmota/energy_modbus_configs/configurations.md index 15266c92b..68084c46c 100644 --- a/tasmota/energy_modbus_configs/configurations.md +++ b/tasmota/energy_modbus_configs/configurations.md @@ -6,7 +6,9 @@ Modbus JSON configuration data for use with generic Energy Modbus driver. 1. Rule driven - copy the required JSON content to any rule buffer preceded with ``rule3 on file#modbus do `` and followed with `` endon``. -2. File system driven - if a file system is present (every ESP32) create a file called ``modbus.json`` and copy the required JSON +2. Script driven - copy the required JSON content to a script preceded with ``>y`` and + followed with ``#``. +3. File system driven - if a file system is present (every ESP32) create a file called ``modbus.json`` and copy the required JSON content to it. ## Notes diff --git a/tasmota/tasmota_xnrg_energy/xnrg_29_modbus.ino b/tasmota/tasmota_xnrg_energy/xnrg_29_modbus.ino index 2d98c29e4..a95f65f8a 100644 --- a/tasmota/tasmota_xnrg_energy/xnrg_29_modbus.ino +++ b/tasmota/tasmota_xnrg_energy/xnrg_29_modbus.ino @@ -25,6 +25,7 @@ * - Supports single three phase device or three single phase devices of same model on bus. * - For easy configuration of modbus energy monitor device(s) use: * - a rule file called modbus + * - a script using >y * - a filesystem file called modbus.json * * See files configurations.md and value_pair_description.md in folder energy_modbus_configs @@ -481,10 +482,9 @@ bool EnergyModbusReadRegisters(void) { String modbus = ""; #ifdef USE_UFILESYS - const size_t file_size = ENERGY_MODBUS_MAX_FSIZE; - char *modbus_file = (char*)calloc(file_size, 1); + char *modbus_file = (char*)calloc(ENERGY_MODBUS_MAX_FSIZE, 1); if (modbus_file) { - if (TfsLoadFile(ENERGY_MODBUS_FILE, (uint8_t*)modbus_file, file_size -1)) { + if (TfsLoadFile(ENERGY_MODBUS_FILE, (uint8_t*)modbus_file, ENERGY_MODBUS_MAX_FSIZE -1)) { if (strlen(modbus_file) < ENERGY_MODBUS_MAX_FSIZE) { modbus = modbus_file; AddLog(LOG_LEVEL_DEBUG, PSTR("NRG: Loaded from File")); @@ -504,7 +504,7 @@ bool EnergyModbusReadRegisters(void) { #ifdef USE_SCRIPT if (!modbus.length()) { modbus = ScriptLoadSection(">y"); - AddLog(LOG_LEVEL_DEBUG, PSTR("NRG: Loaded from script")); + AddLog(LOG_LEVEL_DEBUG, PSTR("NRG: Loaded from Script")); } #endif // USE_SCRIPT